heart-of-gold

Tactical RPG written in python, using pygame.
Log | Files | Refs | LICENSE

commit 93f567e568cb9c19364d38c5ef21e4908743155b
parent 45cce6b6c4bc40b32b5aa890bc30cf8f91bab1d0
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 21 Aug 2020 15:18:28 -0500

Added interface system and integrated

Diffstat:
M.gitignore | 1+
Msrc/game.py | 18++++++++++--------
Asrc/interface.py | 22++++++++++++++++++++++
3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,6 +1,7 @@ __pycache__/ build *.zip +*.swp # For those who use PyCharm .idea/ diff --git a/src/game.py b/src/game.py @@ -1,4 +1,5 @@ import pygame +from . import interface class Game(object): @@ -9,15 +10,16 @@ class Game(object): self.framerate = 60 self.on = True - def shift_frames(self, framerate): - - self.frame_clock.tick(framerate) + # Subsystems + self.interface = interface.Interface(self) - def handle_events(self): + # Utility methods + def toggle_on(self): + self.on = not self.on - for event in pygame.event.get(): - if event.type == pygame.QUIT: - self.on = False + # Mainloop methods + def shift_frames(self, framerate): + self.frame_clock.tick(framerate) def update_game(self): @@ -28,7 +30,7 @@ class Game(object): while self.on: self.shift_frames(self.framerate) - self.handle_events() + self.interface.handle_events() self.update_game() pygame.quit() diff --git a/src/interface.py b/src/interface.py @@ -0,0 +1,22 @@ +import pygame + +class Interface(object): + """ + Interface controls all event reaction. + """ + + def __init__(self, game): + self.game = game + + def handle_events(self): + + for event in pygame.event.get(): + + if event.type == pygame.QUIT: + self.game.toggle_on() + + def handle_key_press(self, key): + pass + + def handle_key_release(self, key): + pass