""" 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()
""" 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. """
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