Hook up very basic engine.
authorSimon Cross <hodgestar@gmail.com>
Sun, 28 Feb 2016 18:31:47 +0000 (20:31 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 28 Feb 2016 18:31:47 +0000 (20:31 +0200)
koperkapel/pgzapp.py
koperkapel/scenes/base.py

index d703aaf16bc37a6d040fd58801f0a711217773ef..109e39e752c92e0e6a9b966d049b5cca1d701635 100644 (file)
@@ -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()
index 6bb7f5584347e7c6f39e20e509c37fe3c5789286..859f816e6359249e8dfbdc61e36f24b4699fcc44 100644 (file)
@@ -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