changeset 11:249814efa91b

Create game engine. Enable quitting.
author Simon Cross <hodgestar@gmail.com>
date Sun, 03 Apr 2011 15:59:16 +0200
parents 7e0f084aab5c
children ded67a5c80c1
files skaapsteker/__main__.py skaapsteker/engine.py
diffstat 2 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/__main__.py	Sun Apr 03 15:55:52 2011 +0200
+++ b/skaapsteker/__main__.py	Sun Apr 03 15:59:16 2011 +0200
@@ -2,6 +2,7 @@
    """
 
 from constants import SCREEN, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG
+from engine import Engine
 
 import pygame
 from pygame.locals import SWSURFACE
@@ -10,7 +11,6 @@
 import optparse
 
 
-
 def parse_args(args):
     parser = optparse.OptionParser()
     parser.add_option("--no-sound", action="store_false", default=True,
@@ -54,13 +54,12 @@
     draw_level('level1.json', display)
     pygame.display.flip()
 
-    raw_input('?')
+    engine = Engine()
+    try:
+        engine.run()
+    except KeyboardInterrupt:
+        pass
 
-    #shell = MainShell(display)
-    #try:
-    #    shell.run()
-    #except KeyboardInterrupt:
-    #    pass
-
+ 
 if __name__ == '__main__':
     main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skaapsteker/engine.py	Sun Apr 03 15:59:16 2011 +0200
@@ -0,0 +1,21 @@
+"""Top-level engine for switching scenes."""
+
+import pygame.display
+import pygame.time
+import pygame.event
+from pygame.locals import QUIT
+
+class Engine(object):
+
+    def __init__(self):
+        self._framerate = 60
+
+    def run(self):
+        """Run the game loop dispatching events as necessary."""
+        clock = pygame.time.Clock()
+        while True:
+            events = pygame.event.get()
+            for ev in events:
+                if ev.type is QUIT:
+                    return
+            clock.tick(self._framerate)