comparison gamelib/state.py @ 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 ebc76bc0c067
children ad6f56bfa8b7
comparison
equal deleted inserted replaced
38:f9abcfb2e475 39:088a101f5b94
77 self._background = get_image(self.FOLDER, self.BACKGROUND) 77 self._background = get_image(self.FOLDER, self.BACKGROUND)
78 78
79 def add_item(self, item): 79 def add_item(self, item):
80 self.state.add_item(item) 80 self.state.add_item(item)
81 81
82 def add_thing(self, thing):
83 self.things[thing.name] = thing
84
82 def draw_background(self, surface): 85 def draw_background(self, surface):
83 surface.blit(self._background, (0, 0), None, BLEND_ADD) 86 surface.blit(self._background, (0, 0), None, BLEND_ADD)
84 87
85 def draw_things(self, surface): 88 def draw_things(self, surface):
86 for thing in self.things.itervalues(): 89 for thing in self.things.itervalues():
92 95
93 96
94 class Thing(object): 97 class Thing(object):
95 """Base class for things in a scene that you can interact with.""" 98 """Base class for things in a scene that you can interact with."""
96 99
97 def __init__(self, rect): 100 def __init__(self, name, rect):
101 self.name = name
102 # area within scene that triggers calls to interact
98 self.rect = rect 103 self.rect = rect
104 # these are set by set_scene
105 self.scene = None
106 self.state = None
99 # TODO: add masks 107 # TODO: add masks
100 # TODO: add images 108 # TODO: add images
109
110 def set_scene(self, scene):
111 assert self.scene is None
112 self.scene = scene
113 self.state = scene.state
101 114
102 def interact(self, item): 115 def interact(self, item):
103 pass 116 pass
104 117
105 def draw(self, surface): 118 def draw(self, surface):