comparison gamelib/misc.py @ 100:e90068d1f374

Re-indent to four spaces.
author Simon Cross <hodgestar@gmail.com>
date Wed, 02 Sep 2009 17:24:58 +0000
parents 18db99fda6bd
children 672cc5598e77
comparison
equal deleted inserted replaced
99:f5d56688943b 100:e90068d1f374
1 # Holder for misc useful classes 1 # Holder for misc useful classes
2 2
3 class Position(object): 3 class Position(object):
4 """2D position / vector""" 4 """2D position / vector"""
5 5
6 def __init__(self, x, y): 6 def __init__(self, x, y):
7 self.x = x 7 self.x = x
8 self.y = y 8 self.y = y
9 9
10 def to_tuple(self): 10 def to_tuple(self):
11 return self.x, self.y 11 return self.x, self.y
12 12
13 def dist(self, b): 13 def dist(self, b):
14 """Gives the distance to another position""" 14 """Gives the distance to another position"""
15 15
16 return abs(self.x - b.x) + abs(self.y - b.y) 16 return abs(self.x - b.x) + abs(self.y - b.y)
17 17
18 def __sub__(self, b): 18 def __sub__(self, b):
19 return Position(self.x - b.x, self.y - b.y) 19 return Position(self.x - b.x, self.y - b.y)
20 20
21 def __add__(self, b): 21 def __add__(self, b):
22 return Position(self.x + b.x, self.y + b.y) 22 return Position(self.x + b.x, self.y + b.y)
23 23
24 def left_of(self, b): 24 def left_of(self, b):
25 return self.x < b.x 25 return self.x < b.x
26 26
27 def right_of(self, b): 27 def right_of(self, b):
28 return self.x > b.x 28 return self.x > b.x
29 29
30 def __eq__(self, b): 30 def __eq__(self, b):
31 return self.x == b.x and self.y == b.y 31 return self.x == b.x and self.y == b.y