Add input manager.
This commit is contained in:
parent
6186b2b40f
commit
8c07acc22f
10
snake/input_manager.py
Normal file
10
snake/input_manager.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
class InputManager:
|
||||||
|
QUIT = 0
|
||||||
|
|
||||||
|
def process_input(self):
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
return InputManager.QUIT
|
||||||
@ -1,19 +1,19 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from window import Window
|
from window import Window
|
||||||
|
from input_manager import InputManager
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
window = Window(title='Snake', size=(800, 600), background_color=(0, 128, 0))
|
window = Window(title='Snake', size=(800, 600), background_color=(0, 128, 0))
|
||||||
|
input_manager = InputManager()
|
||||||
|
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
framerate = 25
|
framerate = 25
|
||||||
|
|
||||||
shall_abort = False
|
last_input = None
|
||||||
|
|
||||||
while not shall_abort:
|
while last_input != InputManager.QUIT:
|
||||||
for event in pygame.event.get():
|
last_input = input_manager.process_input()
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
shall_abort = True
|
|
||||||
|
|
||||||
window.reset()
|
window.reset()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user