Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (61 loc) · 1.65 KB
/
Copy pathmain.py
File metadata and controls
61 lines (61 loc) · 1.65 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
import pygame
import random , sys
from object import*
pygame.init()
SCREEN_WEIGHT = 800
SCREEN_HEIGHT = 600
score = 0
screen = pygame.display.set_mode((SCREEN_WEIGHT,SCREEN_HEIGHT))
clock = pygame.time.Clock()
running = True
SCREEN_COLOR = 16, 33, 89
dt = 0
platform_x = 350
platform_y = 550
ball_x = platform_x+50
ball_y = platform_y-20
brick_x = -70
brick_y = 10
bricks = []
pygame.display.set_caption("Bricks Game")
pygame.display.update()
pygame.event.set_grab(True)
pygame.mouse.set_visible(False)
platform = Platform(screen, (255, 255, 255), (platform_x,platform_y, 120, 20))
ball = Ball(screen, (255, 0, 0), [ball_x, ball_y], 10)
brick = Brick(screen, (0, 255, 0), (brick_x, brick_y, 80, 30))
timer = Counter(screen)
for i in range(8):
brick_x += 90
brick_y = 10
# 記得改ㄚㄚㄚㄚㄚㄚ ㄚㄚㄚㄚㄚㄚㄚㄚㄚㄚ ㄚㄚㄚ
for j in range(4):
brick_y += 40
brick = Brick(screen, (0, 255, 0), (brick_x, brick_y, 80, 30))
bricks.append(brick)
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill(SCREEN_COLOR)
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
platform.move(-10)
if keys[pygame.K_RIGHT]:
platform.move(10)
if keys[pygame.K_BACKSPACE]:
pygame.quit()
sys.exit()
ball.draw()
for t in bricks:
t.draw()
if t.exist == True:
ball.collision_check(t.rect)
t.collision_gone(ball.rect)
platform.draw()
ball.move()
ball.collision_check(platform.rect)
timer.timer(screen)
pygame.display.update()
pygame.quit()