Changeset 250:8d7edd77bfbf


Ignore:
Timestamp:
04/07/11 21:57:22 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Message:

Start hooking up NPC interactions.

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/engine.py

    r249 r250  
    66from pygame.locals import QUIT, USEREVENT
    77
    8 from .gamestate import GameState
    98
    109class Engine(object):
    1110
    1211    def __init__(self):
     12        # avoid circular imports
     13        from .gamestate import GameState
    1314        self._framerate = 60
    1415        self._current_scene = None
     
    106107    def post(cls):
    107108        super(PlayerDied, cls).post()
     109
     110class OpenDialog(UserEvent):
     111
     112    utype = "OPEN_DIALOG"
     113
     114    @classmethod
     115    def post(cls, npc):
     116        # request to open dialog box for given NPC sprite
     117        # will do nothing if the NPC's current state has
     118        # no text
     119        super(OpenDialog, cls).post(npc=npc)
     120
     121class CloseDialog(UserEvent):
     122
     123    utype = "CLOSE_DIALOG"
     124
     125    @classmethod
     126    def post(cls, npc):
     127        # close dialog box for given NPC sprite
     128        # will do nothing if the sprite has no dialog open
     129        super(CloseDialog, cls).post(npc=npc)
     130
     131class NpcEvent(UserEvent): # TODO: Needed?
     132
     133    utype = "NPC_EVENT"
     134
     135    @classmethod
     136    def post(cls, npc, ev):
     137        """npc is an NPC sprite.
     138           ev is a DsmEvent for that sprite.
     139           """
     140        super(NpcEvent, cls).post(npc=npc, ev=ev)
     141
     142class GlobalNpcEvent(UserEvent): # TODO: Needed?
     143
     144    utype = "GLOBAL_NPC_EVENT"
     145
     146    @classmethod
     147    def post(cls, ev):
     148        """Send a DsmEvent event to all NPCs.
     149           """
     150        super(GlobalNpcEvent, cls).post(ev=ev)
  • skaapsteker/levelscene.py

    r248 r250  
    8787            self._paused = True
    8888
     89    def _open_dialog(self, npc):
     90        print npc.dsm.get_state().text
     91        engine.CloseDialog.post(npc)
     92
     93    def _close_dialog(self, npc):
     94        pass
     95
    8996    def leave(self):
    9097        """Freeze the scene, for serialization"""
     
    134141        cr.clamp_ip(lr)
    135142
    136 
    137143    def dispatch(self, ev):
    138         if engine.PlayerDied.matches(ev):
    139             self._player_dead = True
    140         elif ev.type is KEYDOWN:
     144        if ev.type is KEYDOWN:
    141145            if self._player_dead:
    142146                if ev.key in self._restart_keys:
     
    153157            if ev.key in self._fast_key_map:
    154158                self._fast_keys_down.discard(ev.key)
     159        elif engine.PlayerDied.matches(ev):
     160            self._player_dead = True
     161        elif engine.OpenDialog.matches(ev):
     162            self._open_dialog(ev.npc)
     163        elif engine.CloseDialog.matches(ev):
     164            self._close_dialog(ev.npc)
  • skaapsteker/sprites/base.py

    r249 r250  
    88from ..physics import Sprite
    99from ..constants import Layers
     10from ..engine import OpenDialog
    1011from .. import data
    1112from .. import dialogue
     
    200201        self.dsm = dialogue.DSM(name, world, dsm, state)
    201202
    202 
    203203    def collided_player(self, player):
    204         print "%s is ignoring player" % self
     204        OpenDialog.post(self)
    205205
    206206
Note: See TracChangeset for help on using the changeset viewer.