forked from ismailhasannnnnn/PyMario
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_functions.py
More file actions
59 lines (48 loc) · 1.93 KB
/
game_functions.py
File metadata and controls
59 lines (48 loc) · 1.93 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
import sys
import pygame as pg
from vector import Vector
from mario import Mario
from sound import Sound
LEFT, RIGHT, UP, DOWN, STOP = 'left', 'right', 'up', 'down', 'stop'
dirs = {LEFT: Vector(-1, 0),
RIGHT: Vector(1, 0),
UP: Vector(0, -1),
DOWN: Vector(0, 1),
STOP: Vector(0, 0)}
dir_keys = {pg.K_LEFT: LEFT, pg.K_a: LEFT,
pg.K_RIGHT: RIGHT, pg.K_d: RIGHT}
def check_events(game):
mario = game.mario
for e in pg.event.get():
if e.type == pg.QUIT:
game.finished = True
elif e.type == pg.KEYDOWN:
if e.key in dir_keys:
v = dirs[dir_keys[e.key]]
if v == Vector(1, 0):
game.mario.movingForward = True
game.mario.wasBackward = False
elif v == Vector(-1, 0):
game.mario.movingBackward = True
game.mario.wasBackward = True
mario.inc_add(v)
if e.key == pg.K_SPACE:
if not mario.isJumping:
Sound.play_jump(Sound())
mario.isJumping = True
if e.key == pg.K_k:
# game.entities.create_entity((mario.rect.centerx + game.enemies.bg_x, mario.rect.centery), pg.image.load("images/mario1.png"))
game.enemies.create_fireball((mario.rect.centerx - game.enemies.bg_x, mario.rect.centery - 40))
elif e.type == pg.KEYUP:
if e.key in dir_keys:
v = dirs[dir_keys[e.key]]
if mario.v == Vector(0, 0):
mario.v = Vector(0, 0)
else:
mario.inc_add(-v)
if v == Vector(1, 0):
game.mario.movingForward = False
elif v == Vector(-1,0):
game.mario.movingBackward = False
# if e.key == pg.K_SPACE and mario.isJumping is True:
# mario.isJumping = False