Mercurial > rinkhals
diff gamelib/misc.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 | e89a1afe4e84 |
children | 96dbf2c8506e |
line wrap: on
line diff
--- a/gamelib/misc.py Sat Nov 21 16:43:03 2009 +0000 +++ b/gamelib/misc.py Sat Nov 21 16:46:12 2009 +0000 @@ -4,6 +4,7 @@ from pygame.locals import KEYDOWN, K_ESCAPE from pgu import gui +from pgu.algo import getline import serializer @@ -40,6 +41,20 @@ def __eq__(self, b): return self.x == b.x and self.y == b.y and self.z == b.z + def intermediate_positions(self, b): + """Only operates in two dimensions.""" + if max(abs(self.x - b.x), abs(self.y - b.y)) <= 1: + # pgu gets this case wrong on occasion. + return [b] + start = self.to_tile_tuple() + end = b.to_tile_tuple() + points = getline(start, end) + points.remove(start) # exclude start_pos + if end not in points: + # Rounding errors in getline cause this + points.append(end) + return [Position(p[0], p[1]) for p in points] + class WeightedSelection(object): def __init__(self, weightings=None): self.weightings = []