diff mamba/engine.py @ 61:fc4b7db1d832

Habitat switching.
author Simon Cross <hodgestar@gmail.com>
date Sun, 11 Sep 2011 16:35:02 +0200
parents 3cc917814579
children 40be38f4427c
line wrap: on
line diff
--- a/mamba/engine.py	Sun Sep 11 16:35:57 2011 +0200
+++ b/mamba/engine.py	Sun Sep 11 16:35:02 2011 +0200
@@ -30,7 +30,10 @@
             for ev in events:
                 if ev.type is QUIT:
                     return
-                self._habitat.dispatch(ev)
+                elif NewHabitatEvent.matches(ev):
+                    self.set_habitat(ev.habitat)
+                else:
+                    self._habitat.dispatch(ev)
             self._habitat.draw(surface)
             flip()
 
@@ -60,13 +63,22 @@
 
 class UserEvent(object):
 
-    utype = "UNKNOWN"
+    TYPE = "UNKNOWN"
 
     @classmethod
     def post(cls, **kws):
-        ev = pygame.event.Event(USEREVENT, utype=cls.utype, **kws)
+        ev = pygame.event.Event(USEREVENT, utype=cls.TYPE, **kws)
         pygame.event.post(ev)
 
     @classmethod
     def matches(cls, ev):
-        return ev.type is USEREVENT and ev.utype == cls.utype
+        return ev.type is USEREVENT and ev.utype == cls.TYPE
+
+
+class NewHabitatEvent(UserEvent):
+
+    TYPE = "NEW_HABITAT"
+
+    @classmethod
+    def post(cls, habitat):
+        super(NewHabitatEvent, cls).post(habitat)