Hack keyboard behaviour to be different. Also incidently allow rotating in place
[koperkapel.git] / koperkapel / weapons.py
1 """ Tools for dealing with weapons. """
2
3 from pgzero.loaders import images
4 from .actors.animsurf import AnimatedSurfActor
5
6
7 class Weapon:
8     def __init__(self, name, damage, image_name=None, bullet_range=0,
9                  can_tape=True, frames=("_1",)):
10         self.name = name
11         self.image_name = image_name or name
12         self.frames = frames
13         self.damage = damage
14         self.bullet_range = bullet_range
15         self.can_tape = can_tape
16
17
18 WEAPONS = [
19     Weapon("spit", damage=1, bullet_range=2, can_tape=False,
20            image_name="blank", frames=("",)),
21     Weapon("butter_knife", damage=2),
22     Weapon("crowbar", damage=4),
23     Weapon("gun", damage=4, bullet_range=4),
24 ]
25
26 WEAPON_LOOKUP = {w.name: w for w in WEAPONS}
27
28
29 class WeaponActor(AnimatedSurfActor):
30     def __init__(self, weapon, **kw):
31         super().__init__(**kw)
32         self.weapon = weapon
33
34
35 class WeaponFactory:
36
37     def assemble_frame(self, suffix, weapon, tape):
38         surf = images.load("weapons/%s%s" % (weapon.image_name, suffix))
39         frame = surf.copy()
40         if tape:
41             tape_surf = images.load("weapons/tape")
42             frame.blit(tape_surf, (0, 0))
43         return frame
44
45     def assemble(self, weapon_name, tape=False):
46         weapon = WEAPON_LOOKUP[weapon_name]
47         tape = tape and weapon.can_tape
48         frames = [
49             self.assemble_frame(suffix, weapon, tape)
50             for suffix in weapon.frames]
51         return WeaponActor(weapon, frames=frames)
52
53
54 default_weapons = WeaponFactory()