From f535da159422a6b7a4844aefdc815ba502426457 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Thu, 2 Apr 2020 17:30:25 +0200 Subject: [PATCH] Added basic events --- src/game/EventManager.py | 12 ++++++++++-- src/game/Game.py | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 4548656..3cc4e99 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -1,3 +1,11 @@ +import pygame + + class EventManager: - def __init__(self): - self.player + def __init__(self, gameObject): + self.game = gameObject + + def handleEvents(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + self.game.running = False diff --git a/src/game/Game.py b/src/game/Game.py index 0c18b48..e1c1fea 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -2,6 +2,7 @@ import pygame import json from pathlib import Path +from game.EventManager import EventManager from game.Screen import Screen @@ -35,10 +36,14 @@ class Game: self.screen = Screen(self, self.config["window"]) print("OK") + self.eventManager = EventManager(self) + self.spritesList = pygame.sprite.Group() self.mainLoop() def mainLoop(self): - self.spritesList.draw(self.screen.pygameScreen) - pygame.display.flip() + while self.running: + self.eventManager.handleEvents() + self.spritesList.draw(self.screen.pygameScreen) + pygame.display.flip()