-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
90 lines (68 loc) · 1.52 KB
/
main.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# BREAKOUT GAME
#
import pygame, time
#
# definitions
#
FPS = 30 # Frames Per Second
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
BALL_WIDTH = 16
BALL_HEIGHT = 16
ball_x = 0
ball_speed_x = 6
#
# init game
#
pygame.init()
font = pygame.font.SysFont('default', 64)
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.FULLSCREEN)
fps_clock = pygame.time.Clock()
#
# read images
#
spritesheet = pygame.image.load('Breakout_Tile_Free.png').convert_alpha()
ball_img = pygame.Surface((64, 64), pygame.SRCALPHA)
ball_img.blit(spritesheet, (0, 0), (1403, 652, 64, 64))
ball_img = pygame.transform.scale(ball_img, (BALL_WIDTH, BALL_HEIGHT))
#
# game loop
#
print('mygame is running')
running = True
while running:
#
# read events
#
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
#
# move everything
#
# move ball
ball_x = ball_x + ball_speed_x
# bounce ball
if ball_x < 0 :
ball_speed_x = abs(ball_speed_x)
if ball_x + BALL_WIDTH > SCREEN_WIDTH:
ball_speed_x = abs(ball_speed_x) * -1
#
# handle collisions
#
#
# draw everything
#
# clear screen
screen.fill('black')
# draw ball
screen.blit(ball_img, (ball_x, 0))
# show screen
pygame.display.flip()
#
# wait until next frame
#
fps_clock.tick(FPS) # Sleep the remaining time of this frame
print('mygame stopt running')