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

Protagonist actions, now required for operating doors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r276 r281  
    44import math
    55
     6from nagslang import environment
    67from nagslang import puzzle
    78from nagslang import render
     
    106107    is_moving = False  # `True` if a movement animation should play.
    107108
    108     def __init__(self, physicser, renderer, puzzler=None, overlay=None):
     109    def __init__(self, physicser, renderer, puzzler=None, overlay=None,
     110                 interactible=None):
    109111        self.physicser = physicser
    110112        physicser.set_game_object(self)
     
    118120        if overlay is not None:
    119121            self.overlay.set_game_object(self)
     122        self.interactible = interactible
     123        if interactible is not None:
     124            self.interactible.set_game_object(self)
    120125
    121126    def get_space(self):
     
    245250                 key_state=None):
    246251        body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5)
    247         self.shape = pymunk.Poly(
    248             body, [(-4, -30), (4, -30), (4, 30), (-4, 30)])
     252        self.shape = pymunk.Circle(body, 30)
    249253        self.shape.collision_type = COLLISION_TYPE_DOOR
    250254        self.shape.body.angle = float(angle) / 180 * math.pi
     
    252256        self.destination = destination
    253257        self.dest_pos = tuple(dest_pos)
    254         if key_state is None:
    255             puzzler = puzzle.YesPuzzler()
    256         else:
     258        puzzler = None
     259        action = environment.Action(self._post_door_event)
     260        if key_state is not None:
    257261            puzzler = puzzle.StateProxyPuzzler(key_state)
     262            action.condition = environment.PuzzleStateCondition(puzzler)
    258263        super(Door, self).__init__(
    259264            SingleShapePhysicser(space, self.shape),
    260265            render.ImageRenderer(resources.get_image('objects', 'door.png')),
    261266            puzzler,
    262         )
    263 
    264     def collide_with_protagonist(self, protagonist):
    265         if self.puzzler.get_state():
    266             DoorEvent.post(self.destination, self.dest_pos)
     267            interactible=environment.Interactible(action),
     268        )
     269
     270    def _post_door_event(self, protagonist):
     271        DoorEvent.post(self.destination, self.dest_pos)
    267272
    268273    @classmethod
Note: See TracChangeset for help on using the changeset viewer.