Mercurial > rinkhals
comparison gamelib/animal.py @ 431:129de5883524
Moved intermediate position generation to a more suitable location.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 16:46:12 +0000 |
parents | 42777630956a |
children | 95b81e917399 |
comparison
equal
deleted
inserted
replaced
430:db7bb20d2336 | 431:129de5883524 |
---|---|
1 """Class for the various animals in the game""" | 1 """Class for the various animals in the game""" |
2 | 2 |
3 import random | 3 import random |
4 | 4 |
5 from pgu.vid import Sprite | 5 from pgu.vid import Sprite |
6 from pgu.algo import getline | |
7 | 6 |
8 import imagecache | 7 import imagecache |
9 import tiles | 8 import tiles |
10 from misc import Position | 9 from misc import Position |
11 import sound | 10 import sound |
353 return total | 352 return total |
354 | 353 |
355 def _gen_path(self, start_pos, final_pos): | 354 def _gen_path(self, start_pos, final_pos): |
356 """Construct a direct path from start_pos to final_pos, | 355 """Construct a direct path from start_pos to final_pos, |
357 excluding start_pos""" | 356 excluding start_pos""" |
358 if abs(start_pos.x - final_pos.x) < 2 and \ | 357 return start_pos.intermediate_positions(final_pos) |
359 abs(start_pos.y - final_pos.y) < 2: | |
360 # pgu gets this case wrong on occasion. | |
361 return [final_pos] | |
362 start = start_pos.to_tile_tuple() | |
363 end = final_pos.to_tile_tuple() | |
364 points = getline(start, end) | |
365 points.remove(start) # exclude start_pos | |
366 if end not in points: | |
367 # Rounding errors in getline cause this | |
368 points.append(end) | |
369 return [Position(x[0], x[1]) for x in points] | |
370 | 358 |
371 def _find_best_path_step(self, final_pos, gameboard): | 359 def _find_best_path_step(self, final_pos, gameboard): |
372 """Find the cheapest path to final_pos, and return the next step | 360 """Find the cheapest path to final_pos, and return the next step |
373 along the path.""" | 361 along the path.""" |
374 # We calculate the cost of the direct path | 362 # We calculate the cost of the direct path |