1 """ Tools for dealing with weapons. """
3 from pgzero.loaders import images
4 from .actors.animsurf import AnimatedSurfActor
5 from .util import safepath
9 def __init__(self, name, damage, image_name=None, bullet_range=0,
10 can_tape=True, frames=("_1",), sound=None):
12 self.image_name = image_name or name
15 self.bullet_range = bullet_range
16 self.can_tape = can_tape
21 Weapon("spit", damage=1, bullet_range=2, can_tape=False,
22 image_name="blank", frames=("",), sound="fire_spit"),
23 Weapon("butter_knife", damage=2),
24 Weapon("crowbar", damage=4),
25 Weapon("gun", damage=4, bullet_range=4),
28 WEAPON_LOOKUP = {w.name: w for w in WEAPONS}
31 class WeaponActor(AnimatedSurfActor):
32 def __init__(self, weapon, **kw):
33 super().__init__(**kw)
39 def assemble_frame(self, suffix, weapon, tape):
40 surf = images.load(safepath("weapons/%s%s")
41 % (weapon.image_name, suffix))
44 tape_surf = images.load(safepath("weapons/tape"))
45 frame.blit(tape_surf, (0, 0))
48 def assemble(self, weapon_name, tape=False):
49 weapon = WEAPON_LOOKUP[weapon_name]
50 tape = tape and weapon.can_tape
52 self.assemble_frame(suffix, weapon, tape)
53 for suffix in weapon.frames]
54 return WeaponActor(weapon, frames=frames)
57 default_weapons = WeaponFactory()