annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
1 # Holder for misc useful classes
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
2
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
3 class Position(object):
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
4 """2D position / vector"""
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
5
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
6 def __init__(self, x, y):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
7 self.x = x
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
8 self.y = y
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
9
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
10 def to_tuple(self):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
11 return self.x, self.y
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
12
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
13 def dist(self, b):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
14 """Gives the distance to another position"""
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
15
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
16 return abs(self.x - b.x) + abs(self.y - b.y)
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
17
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
18 def __sub__(self, b):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
19 return Position(self.x - b.x, self.y - b.y)
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
20
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
21 def __add__(self, b):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
22 return Position(self.x + b.x, self.y + b.y)
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
23
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
24 def left_of(self, b):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
25 return self.x < b.x
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
26
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
27 def right_of(self, b):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
28 return self.x > b.x
69
18db99fda6bd Move spawing code from engine to gameboard - seems more natural.
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
29
100
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
30 def __eq__(self, b):
e90068d1f374 Re-indent to four spaces.
Simon Cross <hodgestar@gmail.com>
parents: 69
diff changeset
31 return self.x == b.x and self.y == b.y