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

Location:
nagslang/screens
Files:
3 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
  • nagslang/screens/base.py

    r37 r180  
    77class Screen(object):
    88
    9     def __init__(self, name, world):
     9    def __init__(self, name, player, world):
    1010        self.name = name
    1111        self.world = world
     12        self.protagonist = player
    1213        self.space = pymunk.Space()
    1314
  • nagslang/screens/menu.py

    r29 r180  
    1515                QuitEvent.post()
    1616            elif ev.key == pygame.locals.K_1:
    17                 ScreenChange.post('level1')
     17                ScreenChange.post('level1', None)
    1818
    1919    def render(self, surface):
Note: See TracChangeset for help on using the changeset viewer.