Ignore:
Timestamp:
09/07/13 22:32:32 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Children:
610:29d67c51fd33, 617:2070ce83637b
Phase:
public
Rebase:
66303738323865633236373163383830656434646134316239343036646431303330666563373864
Message:

KeyedHatch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r591 r609  
    77from nagslang import puzzle
    88from nagslang import render
    9 from nagslang.mutators import FLIP_H, ImageOverlay, rotator
     9from nagslang.mutators import FLIP_H, ImageOverlay, rotator, scaler
    1010from nagslang.constants import (
    1111    COLLISION_TYPE_DOOR, COLLISION_TYPE_FURNITURE, COLLISION_TYPE_PROJECTILE,
     
    509509
    510510    def __init__(self, space, end1, end2, key_state=None):
    511         body = make_body(None, None, (0, 0))
    512         self.shape = pymunk.Segment(body, tuple(end1), tuple(end2), 7)
     511        a = pymunk.Vec2d(end1)
     512        b = pymunk.Vec2d(end2)
     513        offset = b - a
     514        offset.length /= 2
     515        mid = (a + offset).int_tuple
     516        body = make_body(None, None, mid)
     517        self.shape = pymunk.Segment(
     518            body, body.world_to_local(tuple(end1)),
     519            body.world_to_local(tuple(end2)), 7)
    513520        self.shape.collision_type = COLLISION_TYPE_DOOR
    514521        if key_state is None:
     
    535542                ("end2", "coordinates"), ("key_state", "puzzler")]
    536543
    537     # The level knows that bulkheads are magical
     544    # The level knows that hatches are magical
     545    @classmethod
     546    def movable(cls):
     547        return True
     548
     549
     550class KeyedHatch(GameObject):
     551    zorder = ZORDER_FLOOR
     552
     553    def __init__(self, space, end1, end2, key_item):
     554        a = pymunk.Vec2d(end1)
     555        b = pymunk.Vec2d(end2)
     556        offset = b - a
     557        offset.length /= 2
     558        mid = (a + offset).int_tuple
     559        body = make_body(None, None, mid)
     560        self.shape = pymunk.Segment(
     561            body, body.world_to_local(tuple(end1)),
     562            body.world_to_local(tuple(end2)), 7)
     563        self.shape.collision_type = COLLISION_TYPE_DOOR
     564        self._key_item = key_item
     565        super(KeyedHatch, self).__init__(
     566            SingleShapePhysicser(space, self.shape),
     567            render.KeyedHatchRenderer(
     568                resources.get_image(
     569                    'objects', '%s.png' % (key_item,),
     570                    transforms=(scaler((32, 32)),))),
     571            puzzle.ParentAttrPuzzler('is_open'),
     572        )
     573        self.add_timer('door_open', 0.1)
     574
     575    @property
     576    def is_open(self):
     577        return self.check_timer('door_open')
     578
     579    def collide_with_protagonist(self, protagonist):
     580        if protagonist.has_item(self._key_item):
     581            self.start_timer('door_open')
     582            return False
     583        return True
     584
     585    @classmethod
     586    def requires(cls):
     587        return [("name", "string"), ("end1", "coordinates"),
     588                ("end2", "coordinates"), ("key_item", "item name")]
     589
     590    # The level knows that hatches are magical
    538591    @classmethod
    539592    def movable(cls):
Note: See TracChangeset for help on using the changeset viewer.