annotate gamelib/equipment.py @ 85:782e45d70ea8

Adds directory for sounds, and script to download them based on sources.txt (and web.ini, which contains password info for freesound.org) despite licensing disputes
author David Fraser <davidf@sjsoft.com>
date Wed, 02 Sep 2009 09:33:55 +0000
parents 5494af02a0e8
children f5d56688943b
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
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
4
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
5 class Equipment(object):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
6 is_weapon = False
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
7
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
8 class Weapon(Equipment):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
9 is_weapon = True
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
10
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
11 def in_range(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
12 """Can the lucky wielder hit the potentially unlucky target with this?"""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
13 return False
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
14
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
15 def hit(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
16 """Is the potentially unlucky target actually unlucky?"""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
17 return False
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
18
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
19 class Rifle(Weapon):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
20 def in_range(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
21 """For now, we ignore terrain and just assume we can hit
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
22 anything that isn't too far away."""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
23 return wielder.pos.dist(target.pos) <= 3
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
24
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
25 def hit(self, gameboard, wielder, target):
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
26 """Closer is more accurate."""
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
27 return random.randint(1, 100) > 60 + 10*wielder.pos.dist(target.pos)
5494af02a0e8 Chickens with rifles!
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
28