-
Notifications
You must be signed in to change notification settings - Fork 19
/
game_functions.py
44 lines (39 loc) · 1.32 KB
/
game_functions.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
# Author: Bojan G. Kalicanin
# Date: 10-Dec-2016
# Functions which control the flow of the game
import pygame
import sys
def check_keydown_events(event, rocket):
"""Check for key presses."""
if event.key == pygame.K_RIGHT:
rocket.moving_right = True
elif event.key == pygame.K_LEFT:
rocket.moving_left = True
elif event.key == pygame.K_DOWN:
rocket.moving_down = True
elif event.key == pygame.K_UP:
rocket.moving_up = True
def check_keyup_events(event, rocket):
"""Check for key releases."""
if event.key == pygame.K_RIGHT:
rocket.moving_right = False
elif event.key == pygame.K_LEFT:
rocket.moving_left = False
elif event.key == pygame.K_DOWN:
rocket.moving_down = False
elif event.key == pygame.K_UP:
rocket.moving_up = False
def check_events(rocket):
"""Check for keypresses and mouse events."""
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
check_keydown_events(event, rocket)
elif event.type == pygame.KEYUP:
check_keyup_events(event, rocket)
def update_screen(ai_settings, screen, rocket):
"""Update game screen."""
screen.fill(ai_settings.bg_color)
rocket.blitme()
pygame.display.flip()