# HG changeset patch # User Adrianna PiƄska # Date 1252016169 0 # Node ID 9b4213f6ea7f9e09168f45c2f1f2dc676a58019a # Parent 8a11bbafa07fcb89ddda87b9192001b79c084584 improved equipment layers; unequip method on animal diff -r 8a11bbafa07f -r 9b4213f6ea7f gamelib/animal.py --- 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'): diff -r 8a11bbafa07f -r 9b4213f6ea7f gamelib/equipment.py --- 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"""