Professional Documents
Culture Documents
import sys
# Cores
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)
PURPLE = (128, 0, 128)
CYAN = (0, 255, 255)
# Configurações do jogo
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
BALL_RADIUS = 10
PADDLE_WIDTH = 60
PADDLE_HEIGHT = 15
PADDLE_SPEED = 2
BALL_SPEED = 2
BLOCK_WIDTH = 60
BLOCK_HEIGHT = 20
BLOCK_ROWS = 5
BLOCK_COLS = 10
LIVES = 3
# Níveis
levels = [
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
],
[
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
[2, 0, 2, 0, 2, 0, 2, 0, 2, 0],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
[0, 2, 0, 2, 0, 2, 0, 2, 0, 2],
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
],
#... add more levels if desired
]
def update(self):
self.rect.x += self.direction * self.speed
if self.rect.left < 0:
self.rect.left = 0
elif self.rect.right > SCREEN_WIDTH:
self.rect.right = SCREEN_WIDTH
def draw(self):
pygame.draw.rect(screen, BLUE, self.rect)
def update(self):
self.rect.x += self.dx * self.speed
self.rect.y += self.dy * self.speed
if self.rect.left < 0 or self.rect.right > SCREEN_WIDTH:
self.dx *= -1
if self.rect.top < 0:
self.dy *= -1
elif self.rect.bottom > SCREEN_HEIGHT:
self.dy *= -1
def draw(self):
pygame.draw.circle(screen, WHITE, self.rect.center, BALL_RADIUS)
def draw(self):
pygame.draw.rect(screen, self.color, self.rect)
lives = LIVES
score = 0
current_level = 0
screen.fill((0, 0, 0))
paddle.update()
paddle.draw()
if paddle.rect.colliderect(ball.rect):
ball.dy *= -1
if not blocks:
current_level += 1
if current_level >= len(levels):
print("You won!")
running = False
else:
balls = [Ball(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2, 1, -1, BALL_SPEED
+ current_level)]
blocks = []
for i, row in enumerate(levels[current_level]):
color = BLOCK_COLORS[i % len(BLOCK_COLORS)]
for j, cell in enumerate(row):
if cell != 0:
blocks.append(Block(j * (BLOCK_WIDTH + 3), i *
(BLOCK_HEIGHT + 3), color))
pygame.display.flip()
clock.tick(60)
if lives <= 0:
print("Game Over!")
running = False
pygame.quit()
sys.exit()