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

Some refactoring and fixing, start of better collision handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r185 r186  
    4242
    4343
     44class YesPuzzler(Puzzler):
     45    """Yes sir, I'm always on.
     46    """
     47    def get_state(self):
     48        return True
     49
     50
     51class NoPuzzler(Puzzler):
     52    """No sir, I'm always off.
     53    """
     54    def get_state(self):
     55        return False
     56
     57
    4458class CollidePuzzler(Puzzler):
    4559    def __init__(self, *collision_types):
     
    108122        super(SingleShapePhysicser, self).__init__(space)
    109123        self._shape = shape
     124        shape.physicser = self
    110125
    111126    def get_shape(self):
     
    342357        self.renderer.animate()
    343358
     359    def collide_with_protagonist(self):
     360        """Called as a `pre_solve` collision callback with the protagonist.
     361
     362        You can return `False` to ignore the collision, anything else
     363        (including `None`) to process the collision as normal.
     364        """
     365        pass
     366
    344367
    345368class FloorSwitch(GameObject):
     
    394417    zorder = ZORDER_FLOOR
    395418
    396     def __init__(self, space, position, destination, dest_pos):
     419    def __init__(self, space, position, destination, dest_pos, key_state=None):
    397420        body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5)
    398421        self.shape = pymunk.Poly(
     
    402425        self.destination = destination
    403426        self.dest_pos = tuple(dest_pos)
     427        if key_state is None:
     428            puzzler = YesPuzzler()
     429        else:
     430            puzzler = StateProxyPuzzler(key_state)
    404431        super(Door, self).__init__(
    405432            SingleShapePhysicser(space, self.shape),
    406433            ImageRenderer(resources.get_image('objects', 'door.png')),
     434            puzzler,
    407435        )
    408436
Note: See TracChangeset for help on using the changeset viewer.