diff skaapsteker/engine.py @ 250:8d7edd77bfbf

Start hooking up NPC interactions.
author Simon Cross <hodgestar@gmail.com>
date Thu, 07 Apr 2011 23:57:22 +0200
parents 30ae3c681507
children de60329cfc9f
line wrap: on
line diff
--- a/skaapsteker/engine.py	Thu Apr 07 22:20:58 2011 +0200
+++ b/skaapsteker/engine.py	Thu Apr 07 23:57:22 2011 +0200
@@ -5,11 +5,12 @@
 import pygame.event
 from pygame.locals import QUIT, USEREVENT
 
-from .gamestate import GameState
 
 class Engine(object):
 
     def __init__(self):
+        # avoid circular imports
+        from .gamestate import GameState
         self._framerate = 60
         self._current_scene = None
         self._fpss = [self._framerate] * 100
@@ -105,3 +106,45 @@
     @classmethod
     def post(cls):
         super(PlayerDied, cls).post()
+
+class OpenDialog(UserEvent):
+
+    utype = "OPEN_DIALOG"
+
+    @classmethod
+    def post(cls, npc):
+        # request to open dialog box for given NPC sprite
+        # will do nothing if the NPC's current state has
+        # no text
+        super(OpenDialog, cls).post(npc=npc)
+
+class CloseDialog(UserEvent):
+
+    utype = "CLOSE_DIALOG"
+
+    @classmethod
+    def post(cls, npc):
+        # close dialog box for given NPC sprite
+        # will do nothing if the sprite has no dialog open
+        super(CloseDialog, cls).post(npc=npc)
+
+class NpcEvent(UserEvent): # TODO: Needed?
+
+    utype = "NPC_EVENT"
+
+    @classmethod
+    def post(cls, npc, ev):
+        """npc is an NPC sprite.
+           ev is a DsmEvent for that sprite.
+           """
+        super(NpcEvent, cls).post(npc=npc, ev=ev)
+
+class GlobalNpcEvent(UserEvent): # TODO: Needed?
+
+    utype = "GLOBAL_NPC_EVENT"
+
+    @classmethod
+    def post(cls, ev):
+        """Send a DsmEvent event to all NPCs.
+           """
+        super(GlobalNpcEvent, cls).post(ev=ev)