-
Notifications
You must be signed in to change notification settings - Fork 14
/
events.py
55 lines (52 loc) · 1.58 KB
/
events.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
45
46
47
48
49
50
51
52
53
54
55
import pygame
from sys import exit
# listen to every event and respond
def check_events(sqs, status, AI):
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.KEYDOWN:
key_down(sqs, event.key, status)
if event.type == pygame.KEYUP:
key_up(event.key, status)
if status.is_AI():
AI.control(sqs, status)
# deal with keys that are pressed down
def key_down(sqs, key, status):
if status.is_game_new():
status.game_status = status.ACTIVE
elif status.is_game_over():
status.game_status = status.RENEW
status.new_AI = False
if key == pygame.K_q: # q stands for quit
exit()
if key == pygame.K_DOWN:
status.down = True
elif key == pygame.K_LEFT:
status.left = True
sqs.clock.update_left_down()
elif key == pygame.K_RIGHT:
status.right = True
sqs.clock.update_right_down()
elif key == pygame.K_UP:
status.rotate = True
elif key == pygame.K_SPACE:
status.straight_drop = True
if key == pygame.K_a:
status.AI = True
status.new_AI = True
sqs.st.adjust_for_AI()
# deal with keys that are released
def key_up(key, status):
if key == pygame.K_q:
exit()
if key == pygame.K_DOWN:
status.down = False
elif key == pygame.K_LEFT:
status.left = False
elif key == pygame.K_RIGHT:
status.right = False
elif key == pygame.K_UP:
status.rotate = False
elif key == pygame.K_SPACE:
status.straight_drop = False