annotate gamelib/equipment.py @ 100:e90068d1f374

Re-indent to four spaces.
author Simon Cross <hodgestar@gmail.com>
date Wed, 02 Sep 2009 17:24:58 +0000
parents f5d56688943b
children 48019afde338
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
1 """Stuff for animals to use."""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
2
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
3 import random
99
f5d56688943b Added background music support, and daytime and night time music (really animal sounds, not music)
David Fraser <davidf@sjsoft.com>
parents: 84
diff changeset
4 import sound
84
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
5
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
6 class Equipment(object):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
7 is_weapon = False
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
8
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
9 class Weapon(Equipment):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
10 is_weapon = True
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
11
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
12 def in_range(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
13 """Can the lucky wielder hit the potentially unlucky target with this?"""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
14 return False
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
15
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
16 def hit(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
17 """Is the potentially unlucky target actually unlucky?"""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
18 return False
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
19
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
20 class Rifle(Weapon):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
21 def in_range(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
22 """For now, we ignore terrain and just assume we can hit
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
23 anything that isn't too far away."""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
24 return wielder.pos.dist(target.pos) <= 3
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
25
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
26 def hit(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
27 """Closer is more accurate."""
99
f5d56688943b Added background music support, and daytime and night time music (really animal sounds, not music)
David Fraser <davidf@sjsoft.com>
parents: 84
diff changeset
28 sound.play_sound("fire-rifle.ogg")
84
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
29 return random.randint(1, 100) > 60 + 10*wielder.pos.dist(target.pos)
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
30