comparison gamelib/equipment.py @ 202:3074784c93f4

Animation support
author Neil Muller <drnlmuller@gmail.com>
date Fri, 04 Sep 2009 20:23:30 +0000
parents 67d10f7e0159
children 00d609883252
comparison
equal deleted inserted replaced
201:fe1e9c18d4d7 202:3074784c93f4
1 """Stuff for animals to use.""" 1 """Stuff for animals to use."""
2 2
3 import random 3 import random
4 import sound 4 import sound
5 import imagecache 5 import imagecache
6 import animations
6 7
7 class Equipment(object): 8 class Equipment(object):
8 IS_EQUIPMENT = True 9 IS_EQUIPMENT = True
9 DRAW_LAYER = 0 10 DRAW_LAYER = 0
10 11
48 49
49 def hit(self, gameboard, wielder, target): 50 def hit(self, gameboard, wielder, target):
50 """Is the potentially unlucky target actually unlucky?""" 51 """Is the potentially unlucky target actually unlucky?"""
51 if hasattr(self, 'HIT_SOUND'): 52 if hasattr(self, 'HIT_SOUND'):
52 sound.play_sound(self.HIT_SOUND) 53 sound.play_sound(self.HIT_SOUND)
54 if hasattr(self, 'ANIMATION'):
55 gameboard.animations.append(self.ANIMATION(wielder))
53 roll = random.randint(1, 100) 56 roll = random.randint(1, 100)
54 base_hit = self._get_parameter('BASE_HIT', wielder) 57 base_hit = self._get_parameter('BASE_HIT', wielder)
55 range_penalty = self._get_parameter('RANGE_PENALTY', wielder) 58 range_penalty = self._get_parameter('RANGE_PENALTY', wielder)
56 return roll > (100-base_hit) + range_penalty*wielder.pos.dist(target.pos) 59 return roll > (100-base_hit) + range_penalty*wielder.pos.dist(target.pos)
57 60
71 BASE_HIT = 55 74 BASE_HIT = 55
72 RANGE_PENALTY = 15 75 RANGE_PENALTY = 15
73 HIT_SOUND = "fire-rifle.ogg" 76 HIT_SOUND = "fire-rifle.ogg"
74 77
75 CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png' 78 CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png'
79
80 ANIMATION = animations.MuzzleFlash
76 81
77 class Knife(Weapon): 82 class Knife(Weapon):
78 TYPE = "KNIFE" 83 TYPE = "KNIFE"
79 NAME = "knife" 84 NAME = "knife"
80 BUY_PRICE = 25 85 BUY_PRICE = 25