Changeset 176:054944c6472b


Ignore:
Timestamp:
Sep 3, 2013, 2:12:15 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Initial door object

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r168 r176  
    1515COLLISION_TYPE_BOX = 4
    1616COLLISION_TYPE_ENEMY = 5
     17COLLISION_TYPE_DOOR = 6
    1718
    1819SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_BOX]
  • nagslang/game_object.py

    r162 r176  
    77from nagslang.constants import (
    88    SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW,
    9     ZORDER_FLOOR)
     9    ZORDER_FLOOR, COLLISION_TYPE_DOOR, COLLISION_TYPE_PLAYER)
    1010from nagslang.options import options
    1111from nagslang.resources import resources
     12from nagslang.events import ScreenChange
    1213
    1314
     
    383384            ImageRenderer(resources.get_image('objects', 'crate.png')),
    384385        )
     386
     387
     388class Door(GameObject):
     389    zorder = ZORDER_FLOOR
     390
     391    def __init__(self, space, position, destination, dest_pos):
     392        body = make_body(pymunk.inf, pymunk.inf, position, damping=0.5)
     393        self.shape = pymunk.Poly(
     394            body, [(-32, -32), (32, -32), (32, 32), (-32, 32)])
     395        self.shape.collision_type = COLLISION_TYPE_DOOR
     396        self.shape.sensor = True
     397        self.destination = destination
     398        self.dest_pos = tuple(dest_pos)
     399        super(Door, self).__init__(
     400            SingleShapePhysicser(space, self.shape),
     401            ImageRenderer(resources.get_image('objects', 'door.png')),
     402        )
     403
     404    def animate(self):
     405        space = self.get_space()
     406        for shape in space.shape_query(self.get_shape()):
     407            if shape.collision_type == COLLISION_TYPE_PLAYER:
     408                # Force to new position
     409                shape.body.position = self.dest_pos
     410                ScreenChange.post(self.destination)
Note: See TracChangeset for help on using the changeset viewer.