Mercurial > mamba
comparison mamba/snake.py @ 223:c3018764942a
Move shift_head onto base segment so that head is less special (in preparation for snake disappearing down the exit).
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Wed, 14 Sep 2011 22:29:57 +0200 |
parents | 3a652f048f57 |
children | af95fbc8ef5c |
comparison
equal
deleted
inserted
replaced
222:321f2eef40e3 | 223:c3018764942a |
---|---|
196 """Shift this segment a number of pixels.""" | 196 """Shift this segment a number of pixels.""" |
197 dx, dy = self.orientation | 197 dx, dy = self.orientation |
198 dx, dy = distance * dx, distance * dy | 198 dx, dy = distance * dx, distance * dy |
199 self.rect = self.rect.move(dx, dy) | 199 self.rect = self.rect.move(dx, dy) |
200 | 200 |
201 | |
202 class Head(Segment): | |
203 CLOSED = "snake-head" | |
204 OPEN = "snake-head-mouth-open-r" | |
205 EYE = mutators.Overlay("snake/snake-head-eye-r") | |
206 TONGUE = mutators.Overlay("snake/snake-head-tongue-r") | |
207 | |
208 is_head = True | |
209 | |
210 def __init__(self, tile_pos): | |
211 self._detail_mutators = (self.EYE,) | |
212 super(Head, self).__init__(self.CLOSED, tile_pos) | |
213 | |
214 def mouth_open(self): | |
215 self.set_base_image(self.OPEN) | |
216 self.make_images() | |
217 self.update_image() | |
218 | |
219 def mouth_close(self): | |
220 self.set_base_image(self.CLOSED) | |
221 self.make_images() | |
222 self.update_image() | |
223 | |
224 def tongue_out(self): | |
225 self._detail_mutators = (self.EYE, self.TONGUE) | |
226 self.make_images() | |
227 self.update_image() | |
228 | |
229 def tongue_in(self): | |
230 self._detail_mutators = (self.EYE,) | |
231 self.make_images() | |
232 self.update_image() | |
233 | |
234 def shifted_tile(self): | |
235 if random.random() < 0.02: | |
236 self.mouth_open() | |
237 self.tongue_out() | |
238 else: | |
239 self.mouth_close() | |
240 self.tongue_in() | |
241 | |
242 def shift_head(self, ds): | 201 def shift_head(self, ds): |
243 """Shift the head a number of pixels in the direction of it | 202 """Shift the head a number of pixels in the direction of it |
244 orientation. | 203 orientation. |
245 """ | 204 """ |
246 dx, dy = self.orientation | 205 dx, dy = self.orientation |
272 ds = self.rect.top - newdy | 231 ds = self.rect.top - newdy |
273 return True, ds | 232 return True, ds |
274 return False, ds | 233 return False, ds |
275 | 234 |
276 | 235 |
236 class Head(Segment): | |
237 CLOSED = "snake-head" | |
238 OPEN = "snake-head-mouth-open-r" | |
239 EYE = mutators.Overlay("snake/snake-head-eye-r") | |
240 TONGUE = mutators.Overlay("snake/snake-head-tongue-r") | |
241 | |
242 is_head = True | |
243 | |
244 def __init__(self, tile_pos): | |
245 self._detail_mutators = (self.EYE,) | |
246 super(Head, self).__init__(self.CLOSED, tile_pos) | |
247 | |
248 def mouth_open(self): | |
249 self.set_base_image(self.OPEN) | |
250 self.make_images() | |
251 self.update_image() | |
252 | |
253 def mouth_close(self): | |
254 self.set_base_image(self.CLOSED) | |
255 self.make_images() | |
256 self.update_image() | |
257 | |
258 def tongue_out(self): | |
259 self._detail_mutators = (self.EYE, self.TONGUE) | |
260 self.make_images() | |
261 self.update_image() | |
262 | |
263 def tongue_in(self): | |
264 self._detail_mutators = (self.EYE,) | |
265 self.make_images() | |
266 self.update_image() | |
267 | |
268 def shifted_tile(self): | |
269 if random.random() < 0.02: | |
270 self.mouth_open() | |
271 self.tongue_out() | |
272 else: | |
273 self.mouth_close() | |
274 self.tongue_in() | |
275 | |
276 | |
277 class Body(Segment): | 277 class Body(Segment): |
278 def __init__(self, tile_pos): | 278 def __init__(self, tile_pos): |
279 super(Body, self).__init__("snake-body", tile_pos) | 279 super(Body, self).__init__("snake-body", tile_pos) |
280 | 280 |
281 | 281 |