Mercurial > pyntnclick
changeset 39:088a101f5b94
Add an example Thing to cryo scene.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Sun, 22 Aug 2010 22:07:45 +0200 |
parents | f9abcfb2e475 |
children | 9fdbfbc02a60 |
files | gamelib/scenes/cryo.py gamelib/state.py |
diffstat | 2 files changed, 23 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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]
--- 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