Ignore:
Timestamp:
09/02/13 12:01:55 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Layered drawing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.