changeset 161:9b4213f6ea7f

improved equipment layers; unequip method on animal
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Thu, 03 Sep 2009 22:16:09 +0000
parents 8a11bbafa07f
children fa57868123d7
files gamelib/animal.py gamelib/equipment.py
diffstat 2 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Thu Sep 03 22:15:35 2009 +0000
+++ b/gamelib/animal.py	Thu Sep 03 22:16:09 2009 +0000
@@ -61,11 +61,16 @@
 
     def equip(self, item):
         self.equipment.append(item)
-        self.draw_equipment(item)
-        if not equipment.is_weapon(item):
-            # redraw weapons on top
-            for weapon in self.weapons():
-                self.draw_equipment(weapon)
+        self.redraw_equipment()
+
+    def unequip(self, item):
+        self.equipment = [e for e in self.equipment if e != item]
+        self.redraw_equipment()
+
+    def redraw_equipment(self):
+        self.equipment.sort(key=lambda x: x.DRAW_LAYER)
+        for item in self.equipment:
+            self.draw_equipment(item)
 
     def draw_equipment(self, item):
         if not hasattr(self, 'EQUIPMENT_IMAGE_ATTRIBUTE'):
--- a/gamelib/equipment.py	Thu Sep 03 22:15:35 2009 +0000
+++ b/gamelib/equipment.py	Thu Sep 03 22:16:09 2009 +0000
@@ -5,6 +5,7 @@
 
 class Equipment(object):
     IS_EQUIPMENT = True
+    DRAW_LAYER = 0
 
     def __init__(self):
         self._buy_price = self.BUY_PRICE
@@ -22,6 +23,7 @@
 
 class Weapon(Equipment):
     IS_WEAPON = True
+    DRAW_LAYER = 10
 
     def in_range(self, gameboard, wielder, target):
         """Can the lucky wielder hit the potentially unlucky target with this?"""
@@ -64,6 +66,7 @@
     CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png'
 
 class Armour(Equipment):
+    DRAW_LAYER = 5
 
     def place(self, animal):
         """Give additional lives"""