Ignore:
Timestamp:
09/03/13 14:58:45 (8 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
36616364363066663031393763616436626334636264353230353363646637376262616364306264
Message:

Add DoorEvent and tweak ScreenChange to keep more state when the player goes through a door

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r147 r180  
    55import pymunk.pygame_util
    66
    7 from nagslang.events import ScreenChange
     7from nagslang.events import ScreenChange, DoorEvent
    88from nagslang.level import Level
    99from nagslang.protagonist import Protagonist
     
    6969        self._drawables = Drawables()
    7070        self.add_walls()
    71         self.add_protagonist()
     71        if self.protagonist is not None:
     72            # We do things this way to avoid extra pymunk
     73            # juggling to move objects between spaces
     74            old_protagonist = self.protagonist
     75            self.add_protagonist()
     76            self.protagonist.copy_state(old_protagonist)
     77        else:
     78            self.add_protagonist()
    7279        self.add_game_objects()
    7380
     
    101108            if ev.key == pygame.locals.K_c:
    102109                self.protagonist.toggle_form()
     110        elif DoorEvent.matches(ev):
     111            self.protagonist.set_position(ev.dest_pos)
     112            if ev.destination != self.name:
     113                # Go to anther screen
     114                ScreenChange.post(ev.destination, self.protagonist)
     115            # else we're teleporting within the screen, and just the
     116            # position change is enough
    103117        self.keys.handle_event(ev)
    104118
Note: See TracChangeset for help on using the changeset viewer.