Commits

Anonymous committed ee1ce92

started with an empty scene.

Comments (0)

Files changed (1)

+#!/usr/bin/env python3
+# -*- python-command: "/usr/bin/python3"; -*-
+
+"""The welcome scene from pyglet."""
+
+import core
+import logic
+
+# shared data
+from core import core, run, __copyright__
+# event scheduling functions → interactivity
+from pyglet.clock import schedule, schedule_once, schedule_interval, unschedule
+
+visible = []
+active = True
+paused = False
+events_to_start = [] #: [(delay, event), …]
+
+def schedule_event(event, delay):
+    global active
+    global paused
+    if paused:
+        return events_to_start.append((delay, event))
+    if active:
+        return schedule_once(event, delay)
+
+### The base function for updating the scene
+def update(dt=0): 
+    """Update the stats of all scene objects. 
+
+    Don't blit them, though. That's done by the Game itself.
+
+    To show something, add it to the visible list. 
+    """
+    pass
+
+## Necessary functions for the simple scene interaction API
+
+def start(dt):
+    """Start the scene."""
+    # make all visible items show themselves 
+    # anytime the screen is refreshed
+    @core.win.event
+    def on_draw():
+        core.win.clear()
+        for i in visible:
+            i.draw()
+
+    # update the scene every 10ms - independent of showing the scene
+    schedule_interval(update, 0.01)
+
+def resume(dt=0):
+    active = True
+    paused = False
+    for delay, event in events_to_start:
+        schedule_event(event, delay)
+
+if __name__ == "__main__": 
+    run(__file__)