changeset 114:4c2fbab20abe

Foxes are stealthy now.
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 02 Sep 2009 19:17:26 +0000
parents 55105d3bdab1
children 2b2007e231da
files gamelib/animal.py gamelib/equipment.py
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Wed Sep 02 19:13:54 2009 +0000
+++ b/gamelib/animal.py	Wed Sep 02 19:17:26 2009 +0000
@@ -14,6 +14,8 @@
 class Animal(Sprite):
     """Base class for animals"""
 
+    STEALTH = 0
+
     def __init__(self, image_left, image_right, tile_pos):
         # Create the animal somewhere far off screen
         Sprite.__init__(self, image_left, (-1000, -1000))
@@ -72,6 +74,8 @@
         """Choose a random fox within range of this weapon."""
         killable_foxes = []
         for fox in gameboard.foxes:
+            if not visible(self, fox):
+                continue
             if weapon.in_range(gameboard, self, fox):
                 killable_foxes.append(fox)
         if not killable_foxes:
@@ -104,6 +108,8 @@
 class Fox(Animal):
     """A fox"""
 
+    STEALTH = 20
+
     costs = {
             # weighting for movement calculation
             'grassland' : 2,
@@ -290,6 +296,8 @@
 class NinjaFox(Fox):
     """Ninja foxes are hard to see"""
 
+    STEALTH = 60
+
 class DemoFox(Fox):
     """Demolition Foxes destroy fences easily"""
 
@@ -305,3 +313,8 @@
         self.chickens_eaten += 1
         if self.chickens_eaten > 2:
             self.hunting = False
+
+def visible(watcher, watchee):
+    roll = random.randint(1, 100)
+    distance = watcher.pos.dist(watchee.pos) - 1
+    return roll > watchee.STEALTH + 10*distance
--- a/gamelib/equipment.py	Wed Sep 02 19:13:54 2009 +0000
+++ b/gamelib/equipment.py	Wed Sep 02 19:17:26 2009 +0000
@@ -47,7 +47,7 @@
 
     RANGE = 3
     BASE_HIT = 50
-    RANGE_MODIFIER = 10
+    RANGE_MODIFIER = 15
     HIT_SOUND = "fire-rifle.ogg"
 
 def is_equipment(obj):