From: Simon Cross Date: Sun, 28 Feb 2016 18:31:47 +0000 (+0200) Subject: Hook up very basic engine. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=8631d4fcb6dbc05c0f8f8283f1740ef6ca835ed1;p=koperkapel.git Hook up very basic engine. --- diff --git a/koperkapel/pgzapp.py b/koperkapel/pgzapp.py index d703aaf..109e39e 100644 --- a/koperkapel/pgzapp.py +++ b/koperkapel/pgzapp.py @@ -1,17 +1,45 @@ """ Pygame-zero application module. """ +import sys + +from .scenes.base import Engine +from .scenes.menu import MenuScene + TITLE = "Koperkapel" WIDTH = 1024 HEIGHT = 768 -from .scenes import menu - -current_scene = menu.MenuScene() +engine = Engine(sys.modules[__name__], MenuScene()) def update(dt): - current_scene.update(dt) + engine.update(dt) def draw(): - current_scene.draw(screen) + engine.draw() + + +def on_mouse_down(pos, button): + engine.on_mouse_down(pos, button) + + +def on_mouse_up(pos, button): + engine.on_mouse_up(pos, button) + + +# NOTE: on_mouse_move is not hooked up because of +# https://bitbucket.org/lordmauve/pgzero/issues/41/ +# spellchecker-has-wrong-argument-names-for + + +def on_key_down(key, mod, unicode): + engine.on_key_down(key, mod, unicode) + + +def on_key_up(key, mod): + engine.on_key_up(key, mod) + + +def on_music_end(): + engine.on_music_end() diff --git a/koperkapel/scenes/base.py b/koperkapel/scenes/base.py index 6bb7f55..859f816 100644 --- a/koperkapel/scenes/base.py +++ b/koperkapel/scenes/base.py @@ -1,6 +1,35 @@ """ Scene utilities. """ +class Engine: + """ A holder for game state. """ + + def __init__(self, app, scene): + self._app = app + self._scene = scene + + def update(self, dt): + self._scene.update(dt) + + def draw(self): + self._scene.draw(self._app.screen) + + def on_mouse_down(self, pos, button): + self._scene.on_mouse_down(pos, button) + + def on_mouse_up(self, pos, button): + self._scene.on_mouse_up(pos, button) + + def on_key_down(self, key, mod, unicode): + self._scene.on_key_down(key, mod, unicode) + + def on_key_up(self, key, mod): + self._scene.on_key_up(key, mod) + + def on_music_end(self): + self._scene.on_music_end() + + class Scene: """ Base class for scenes. """ @@ -9,3 +38,18 @@ class Scene: def draw(self, screen): pass + + def on_mouse_down(self, pos, button): + pass + + def on_mouse_up(self, pos, button): + pass + + def on_key_down(self, key, mod, unicode): + pass + + def on_key_up(self, key, mod): + pass + + def on_music_end(self): + pass