-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_manage.py
executable file
·60 lines (44 loc) · 1.48 KB
/
event_manage.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
56
57
58
59
60
#!/usr/bin/env python
#-*- coding: utf8 -*-
from pygame.locals import *
import pygame
import sys
class EventManager (object):
def __init__(self):
self._stopped = False
self._toggle_full_screen = False
def get_events(self):
ret = []
self._stopped = False
self._toggle_full_screen = False
mods = pygame.key.get_mods()
metaPressed = mods & pygame.KMOD_META
for event in pygame.event.get():
if self._is_quit(event, metaPressed):
pygame.quit()
sys.exit(0)
if event.type == pygame.KEYDOWN and event.key in [K_ESCAPE, K_PAUSE] or \
event.type == pygame.JOYBUTTONDOWN and event.button == 5:
self._stopped = True
continue
ret.append(event)
return ret
def game_stopped(self):
return self._stopped
def toggled_full_screen(self):
return self._toggle_full_screen
def wait(self):
event = pygame.event.wait()
if self._is_quit(event):
pygame.quit()
sys.exit(0)
return event
def _is_quit(self, event, metaPressed = None):
if event.type == pygame.QUIT:
return True
if metaPressed is None:
mods = pygame.key.get_mods()
metaPressed = mods & pygame.KMOD_META
if event.type == pygame.KEYDOWN and event.key == pygame.K_q and metaPressed:
return True
return False