Changeset 188:3894cfe15823


Ignore:
Timestamp:
Sep 3, 2013, 6:24:25 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Better collision handling, potentially locked doors.

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r186 r188  
    435435        )
    436436
    437     def animate(self):
    438         space = self.get_space()
    439         for shape in space.shape_query(self.get_shape()):
    440             if shape.collision_type == COLLISION_TYPE_PLAYER:
    441                 # Force to new position
    442                 DoorEvent.post(self.destination, self.dest_pos)
     437    def collide_with_protagonist(self):
     438        if self.puzzler.get_state():
     439            DoorEvent.post(self.destination, self.dest_pos)
  • 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.