-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamefunctions.py
More file actions
42 lines (40 loc) · 1.59 KB
/
gamefunctions.py
File metadata and controls
42 lines (40 loc) · 1.59 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
import sys
import pygame
from bullets import Bullet
def check_events(hero, bullets, game_settings, screen, play_button):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
mouse_x, mouse_y = pygame.mouse.get_pos()
if play_button.rect.collidepoint(mouse_x, mouse_y):
game_settings.game_active = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
hero.moving_right = True
elif event.key == pygame.K_LEFT:
hero.moving_left = True
elif event.key == pygame.K_UP:
hero.moving_up = True
elif event.key == pygame.K_DOWN:
hero.moving_down = True
elif event.key == pygame.K_SPACE:
new_bullet = Bullet(screen, hero, game_settings)
bullets.add(new_bullet)
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
hero.moving_right = False
elif event.key == pygame.K_LEFT:
hero.moving_left = False
elif event.key == pygame.K_UP:
hero.moving_up = False
elif event.key == pygame.K_DOWN:
hero.moving_down = False
def update_screen(settings, screen, hero, bullets, play_button):
screen.fill(settings.bg_color)
hero.draw_me()
for bullet in bullets.sprites():
bullet.draw_bullet()
if not settings.game_active:
play_button.draw_button()
pygame.display.flip()