Changeset 107:b90d01e4d9d4


Ignore:
Timestamp:
Sep 2, 2013, 12:01:55 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Layered drawing.

Location:
nagslang
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r81 r107  
    1616
    1717SWITCH_PUSHERS = [COLLISION_TYPE_PLAYER, COLLISION_TYPE_BOX]
     18
     19ZORDER_FLOOR = 0
     20ZORDER_LOW = 1
     21ZORDER_MID = 2
     22ZORDER_HIGH = 3
  • nagslang/game_object.py

    r106 r107  
    55import pymunk.pygame_util
    66
    7 from nagslang.constants import SWITCH_PUSHERS, COLLISION_TYPE_SWITCH
     7from nagslang.constants import (
     8    SWITCH_PUSHERS, COLLISION_TYPE_SWITCH, ZORDER_LOW)
    89from nagslang.options import options
    910
     
    178179        self.renderer = renderer
    179180        self.puzzler = puzzler
     181        self.zorder = ZORDER_LOW
    180182
    181183    def get_render_position(self, surface):
  • nagslang/protagonist.py

    r104 r107  
    22import pymunk.pygame_util
    33
    4 from nagslang.constants import COLLISION_TYPE_PLAYER
     4from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID
    55from nagslang.game_object import (
    66    GameObject, SingleShapePhysicser, FacingImageRenderer)
     
    2626        super(Protagonist, self).__init__(
    2727            self._physicsers[self.form], self._renderers[self.form])
     28        self.zorder = ZORDER_MID
    2829
    2930        self.go_human()
  • nagslang/screens/area.py

    r106 r107  
    55import pymunk.pygame_util
    66
     7from nagslang.constants import ZORDER_HIGH
    78from nagslang.events import ScreenChange
    89from nagslang.game_object import FloorSwitch, FloorLight, PuzzleGlue
     
    4445
    4546
     47class Drawables(object):
     48    def __init__(self):
     49        self._drawables = {}
     50
     51    def add(self, drawable):
     52        self._drawables.setdefault(drawable.zorder, []).append(drawable)
     53
     54    def remove(self, drawable):
     55        self._drawables[drawable.zorder].remove(drawable)
     56
     57    def get_drawables(self):
     58        for zorder in sorted(self._drawables):
     59            for drawable in self._drawables[zorder]:
     60                yield drawable
     61
     62    __iter__ = get_drawables
     63
     64
    4665class AreaScreen(Screen):
    4766
     
    5069        self._level = Level(self.name)
    5170        self._level.load()
    52         self._drawables = []
     71        self._drawables = Drawables()
    5372        self.add_walls()
    5473        self.add_protagonist()
     
    5776        switch = FloorSwitch(self.space, (300, 400))
    5877        light = FloorLight(self.space, (300, 500), 'switch')
     78        light2 = FloorLight(self.space, (250, 500), 'switch')
     79        light2.zorder = ZORDER_HIGH
    5980        glue.add_component('switch', switch.puzzler)
    6081        glue.add_component('light', light.puzzler)
    61         self._drawables.append(switch)
    62         self._drawables.append(light)
     82        glue.add_component('light2', light2.puzzler)
     83        self._drawables.add(switch)
     84        self._drawables.add(light)
     85        self._drawables.add(light2)
    6386
    6487    def add_walls(self):
     
    79102    def add_protagonist(self):
    80103        self.protagonist = Protagonist(self.space, (350, 300))
    81         self._drawables.append(self.protagonist)
     104        self._drawables.add(self.protagonist)
    82105
    83106    def handle_event(self, ev):
Note: See TracChangeset for help on using the changeset viewer.