# HG changeset patch # User Simon Cross # Date 1282507665 -7200 # Node ID 088a101f5b945fe14c05bd0a413c1b2fd154ef9d # Parent f9abcfb2e475c4b8a0c0c1738710882a092f91f2 Add an example Thing to cryo scene. diff -r f9abcfb2e475 -r 088a101f5b94 gamelib/scenes/cryo.py --- a/gamelib/scenes/cryo.py Sun Aug 22 20:28:24 2010 +0200 +++ b/gamelib/scenes/cryo.py Sun Aug 22 22:07:45 2010 +0200 @@ -1,4 +1,7 @@ -from gamelib.state import Scene, Item +"""Cryo room where the prisoner starts out.""" + +from gamelib.state import Scene, Item, Thing + class Cryo(Scene): @@ -9,16 +12,19 @@ super(Cryo, self).__init__(state) self.add_item(Triangle("triangle")) self.add_item(Square("square")) + self.add_thing(CryoUnitAlpha("cryo.unit.1", (20, 20, 400, 500))) class Triangle(Item): - INVENTORY_IMAGE = "triangle.png" class Square(Item): - INVENTORY_IMAGE = "square.png" +class CryoUnitAlpha(Thing): + pass + + SCENES = [Cryo] diff -r f9abcfb2e475 -r 088a101f5b94 gamelib/state.py --- a/gamelib/state.py Sun Aug 22 20:28:24 2010 +0200 +++ b/gamelib/state.py Sun Aug 22 22:07:45 2010 +0200 @@ -79,6 +79,9 @@ def add_item(self, item): self.state.add_item(item) + def add_thing(self, thing): + self.things[thing.name] = thing + def draw_background(self, surface): surface.blit(self._background, (0, 0), None, BLEND_ADD) @@ -94,11 +97,21 @@ class Thing(object): """Base class for things in a scene that you can interact with.""" - def __init__(self, rect): + def __init__(self, name, rect): + self.name = name + # area within scene that triggers calls to interact self.rect = rect + # these are set by set_scene + self.scene = None + self.state = None # TODO: add masks # TODO: add images + def set_scene(self, scene): + assert self.scene is None + self.scene = scene + self.state = scene.state + def interact(self, item): pass