Ignore:
Timestamp:
09/03/13 18:24:25 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Better collision handling, potentially locked doors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r180 r188  
    55import pymunk.pygame_util
    66
     7from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS
    78from nagslang.events import ScreenChange, DoorEvent
    89from nagslang.level import Level
     
    6970        self._drawables = Drawables()
    7071        self.add_walls()
     72        self._add_collision_handlers()
    7173        if self.protagonist is not None:
    7274            # We do things this way to avoid extra pymunk
     
    7880            self.add_protagonist()
    7981        self.add_game_objects()
     82
     83    def _collision_pre_solve_handler(self, space, arbiter):
     84        gobj = arbiter.shapes[1].physicser.game_object
     85        result = gobj.collide_with_protagonist()
     86        if result is False:
     87            return False
     88        return True
     89
     90    def _add_collision_handlers(self):
     91        for collision_type in CALLBACK_COLLIDERS:
     92            self.space.add_collision_handler(
     93                COLLISION_TYPE_PLAYER, collision_type,
     94                pre_solve=self._collision_pre_solve_handler)
    8095
    8196    def add_walls(self):
Note: See TracChangeset for help on using the changeset viewer.