Mercurial > boomslang
comparison gamelib/state.py @ 71:99c5506de7ea
Start of interact handling.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Mon, 23 Aug 2010 21:04:43 +0200 |
parents | 158a13a48d48 |
children | d2250cf40ee7 |
comparison
equal
deleted
inserted
replaced
70:213e47dea4d0 | 71:99c5506de7ea |
---|---|
65 self.inventory.remove(self.items[name]) | 65 self.inventory.remove(self.items[name]) |
66 | 66 |
67 def draw(self, surface): | 67 def draw(self, surface): |
68 self.current_scene.draw(surface) | 68 self.current_scene.draw(surface) |
69 | 69 |
70 def interact(self, item, pos): | |
71 self.current_scene.iteract(item, pos) | |
72 | |
73 def mouse_move(self, item, pos): | |
74 self.current_scene.mouse_move(item, pos) | |
75 | |
70 def get_message(self): | 76 def get_message(self): |
71 return self.msg | 77 return self.msg |
72 | 78 |
73 def clear_message(self): | 79 def clear_message(self): |
74 self.msg = None | 80 self.msg = None |
80 old_desc = self.description | 86 old_desc = self.description |
81 self.description = self.current_scene.check_description(pos) | 87 self.description = self.current_scene.check_description(pos) |
82 return old_desc != self.description | 88 return old_desc != self.description |
83 | 89 |
84 def get_description(self): | 90 def get_description(self): |
91 # | |
92 # DEPRECATED | |
93 # | |
85 return self.description | 94 return self.description |
86 | 95 |
87 def message(self, msg): | 96 def message(self, msg): |
88 self.msg = msg | 97 self.msg = msg |
89 | 98 |
124 # link back to state object | 133 # link back to state object |
125 self.state = state | 134 self.state = state |
126 # map of thing names -> Thing objects | 135 # map of thing names -> Thing objects |
127 self.things = {} | 136 self.things = {} |
128 self._background = get_image(self.FOLDER, self.BACKGROUND) | 137 self._background = get_image(self.FOLDER, self.BACKGROUND) |
138 self._current_thing = None | |
129 | 139 |
130 def add_item(self, item): | 140 def add_item(self, item): |
131 self.state.add_item(item) | 141 self.state.add_item(item) |
132 | 142 |
133 def add_thing(self, thing): | 143 def add_thing(self, thing): |
146 | 156 |
147 def draw(self, surface): | 157 def draw(self, surface): |
148 self.draw_background(surface) | 158 self.draw_background(surface) |
149 self.draw_things(surface) | 159 self.draw_things(surface) |
150 | 160 |
161 def interact(self, item, pos): | |
162 """Interact with a particular position. | |
163 | |
164 Item may be an item in the list of items or None for the hand. | |
165 """ | |
166 for thing in self.things.itervalues(): | |
167 if thing.rect.collidepoint(pos): | |
168 thing.interact(item) | |
169 break | |
170 | |
171 def mouse_move(self, item, pos): | |
172 """Call to check whether the cursor has entered / exited a thing. | |
173 | |
174 Item may be an item in the list of items or None for the hand. | |
175 """ | |
176 if self._current_thing is not None: | |
177 if self._current_thing.rect.collidepoint(pos): | |
178 return | |
179 else: | |
180 self._current_thing.leave() | |
181 self._current_thing = None | |
182 for thing in self.things.itervalues(): | |
183 if thing.rect.collidepoint(pos): | |
184 thing.enter(item) | |
185 self._current_thing = thing | |
186 break | |
187 | |
151 def check_description(self, pos): | 188 def check_description(self, pos): |
189 # | |
190 # DEPRECATED | |
191 # | |
152 desc = None | 192 desc = None |
153 for thing in self.things.itervalues(): | 193 for thing in self.things.itervalues(): |
154 # Last thing in the list that matches wins | 194 # Last thing in the list that matches wins |
155 if Rect(thing.rect).collidepoint(pos): | 195 if Rect(thing.rect).collidepoint(pos): |
156 desc = thing.get_description() | 196 desc = thing.get_description() |
198 return None | 238 return None |
199 | 239 |
200 def is_interactive(self): | 240 def is_interactive(self): |
201 return True | 241 return True |
202 | 242 |
243 def enter(self, item): | |
244 """Called when the cursor enters the Thing.""" | |
245 print "Enter %r -> %r" % (item, self) | |
246 | |
247 def leave(self): | |
248 """Called when the cursr leaves the Thing.""" | |
249 print "Leaves %r" % self | |
250 | |
203 def interact(self, item): | 251 def interact(self, item): |
204 if not self.is_interactive(): | 252 if not self.is_interactive(): |
205 return | 253 return |
206 if item is None: | 254 if item is None: |
207 self.interact_without() | 255 self.interact_without() |