Mercurial > rinkhals
comparison gamelib/misc.py @ 69:18db99fda6bd
Move spawing code from engine to gameboard - seems more natural.
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 22:14:12 +0000 |
parents | |
children | e90068d1f374 |
comparison
equal
deleted
inserted
replaced
68:6b8ac424da83 | 69:18db99fda6bd |
---|---|
1 # Holder for misc useful classes | |
2 | |
3 class Position(object): | |
4 """2D position / vector""" | |
5 | |
6 def __init__(self, x, y): | |
7 self.x = x | |
8 self.y = y | |
9 | |
10 def to_tuple(self): | |
11 return self.x, self.y | |
12 | |
13 def dist(self, b): | |
14 """Gives the distance to another position""" | |
15 | |
16 return abs(self.x - b.x) + abs(self.y - b.y) | |
17 | |
18 def __sub__(self, b): | |
19 return Position(self.x - b.x, self.y - b.y) | |
20 | |
21 def __add__(self, b): | |
22 return Position(self.x + b.x, self.y + b.y) | |
23 | |
24 def left_of(self, b): | |
25 return self.x < b.x | |
26 | |
27 def right_of(self, b): | |
28 return self.x > b.x | |
29 | |
30 def __eq__(self, b): | |
31 return self.x == b.x and self.y == b.y |