Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (53 loc) · 1.86 KB
/
Copy pathmain.py
File metadata and controls
71 lines (53 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pygame
import settings
from ball import Ball
from paddle import Paddle
from brick import Brick
pygame.init()
screen = pygame.display.set_mode((settings.WIDTH,settings.HEIGHT))
pygame.display.set_caption("Brick Breaker")
clock = pygame.time.Clock()
paddle=Paddle()
ball=Ball()
bricks=[]
for row in range(settings.BRICK_ROWS):
for col in range(settings.BRICK_COLS):
b=Brick(
col * settings.BRICK_WIDTH,
row * settings.BRICK_HEIGHT
)
bricks.append(b)
score = 0
game_over = False
font = pygame.font.SysFont(None, 40)
running = True
while running:
clock.tick(60)
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type==pygame.QUIT:
running=False
keys=pygame.key.get_pressed()
if not game_over:
paddle.move(keys)
ball.move()
if ball.rect.colliderect(paddle.rect):
ball.dy *=-1
for brick in bricks:
if brick.alive and ball.rect.colliderect(brick.rect):
brick.alive=False
ball.dy*=-1
score +=10
if ball.rect.bottom>=settings.HEIGHT:
game_over=True
paddle.draw(screen)
ball.draw(screen)
for brick in bricks:
brick.draw(screen)
score_Text=font.render(f"Score:{score}" ,True, (255,255,255))
screen.blit(score_Text, (10,10))
if game_over:
text=font.render("Game Over!!",True,(255,255,255))
screen.blit(text, (settings.WIDTH//2 - 120, settings.HEIGHT//2))
pygame.display.flip()
pygame.quit()