-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrol.py
More file actions
30 lines (27 loc) · 1.14 KB
/
Copy pathcontrol.py
File metadata and controls
30 lines (27 loc) · 1.14 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
import pygame
from pygame.locals import *
class Control:
def __init__(self):
self.flag_game = True
self.flag_direction = "RIGHT"
self.flag_pause = False
def control(self):
for event in pygame.event.get():
if event.type == QUIT:
self.flag_game = False
elif event.type == KEYDOWN:
if event.key == K_RIGHT and self.flag_direction != "LEFT":
self.flag_direction = "RIGHT"
elif event.key == K_LEFT and self.flag_direction != "RIGHT":
self.flag_direction = "LEFT"
elif event.key == K_UP and self.flag_direction != "DOWN":
self.flag_direction = "UP"
elif event.key == K_DOWN and self.flag_direction != "UP":
self.flag_direction = "DOWN"
elif event.key == K_ESCAPE:
self.flag_game = False
elif event.key == K_SPACE:
if not self.flag_pause:
self.flag_pause = True
elif self.flag_pause:
self.flag_pause = False