-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameTest.py
40 lines (30 loc) · 948 Bytes
/
gameTest.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
import sys
import pygame
clock = pygame.time.Clock()
pygame.init()
display = pygame.display
def main():
display.set_caption("Don't Let It Fall")
size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("intro_ball.gif")
default_image_size = (45, 45)
ball = pygame.transform.scale(ball, default_image_size)
ballrect = ball.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
clock.tick(60)
if __name__ == '__main__':
main()