Changeset 162:507df17cfbaf


Ignore:
Timestamp:
Sep 2, 2013, 11:00:29 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
rebase_source:
3e7e68f915cea10e14198af9501416f4d9c43569
Message:

Pictures for lights and switches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r160 r162  
    66
    77from nagslang.constants import (
    8     SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW)
     8    SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, COLLISION_TYPE_BOX, ZORDER_LOW,
     9    ZORDER_FLOOR)
    910from nagslang.options import options
    1011from nagslang.resources import resources
     
    183184
    184185
     186class ImageStateRenderer(ImageRenderer):
     187    def __init__(self, state_images):
     188        self._state_images = state_images
     189
     190    def get_image(self):
     191        return self._state_images[self.game_object.puzzler.get_state()]
     192
     193
    185194class FacingImageRenderer(ImageRenderer):
    186195    def __init__(self, left_image, right_image):
     
    297306    """
    298307
     308    zorder = ZORDER_LOW
     309
    299310    def __init__(self, physicser, renderer, puzzler=None):
    300311        self.physicser = physicser
     
    306317        if puzzler is not None:
    307318            puzzler.set_game_object(self)
    308         self.zorder = ZORDER_LOW
    309319
    310320    def get_space(self):
     
    328338
    329339class FloorSwitch(GameObject):
     340    zorder = ZORDER_FLOOR
     341
    330342    def __init__(self, space, position):
    331343        body = make_body(None, None, position)
     
    335347        super(FloorSwitch, self).__init__(
    336348            SingleShapePhysicser(space, self.shape),
    337             ShapeStateRenderer(),
     349            ImageStateRenderer({
     350                True: resources.get_image('objects', 'sensor_on.png'),
     351                False: resources.get_image('objects', 'sensor_off.png'),
     352            }),
    338353            FloorSwitchPuzzler(),
    339354        )
     
    341356
    342357class FloorLight(GameObject):
     358    zorder = ZORDER_FLOOR
     359
    343360    def __init__(self, space, position, state_source):
    344361        body = make_body(None, None, position)
     
    348365        super(FloorLight, self).__init__(
    349366            SingleShapePhysicser(space, self.shape),
    350             ShapeStateRenderer(),
     367            ImageStateRenderer({
     368                True: resources.get_image('objects', 'light_on.png'),
     369                False: resources.get_image('objects', 'light_off.png'),
     370            }),
    351371            StateProxyPuzzler(state_source),
    352372        )
Note: See TracChangeset for help on using the changeset viewer.