Play weapon sounds when firing.
[koperkapel.git] / koperkapel / weapons.py
index 3ef987919c9820b4bef15792b759376fc6f20914..ee83eb816c6eb5c9295db74c05fb78199d506e56 100644 (file)
@@ -1,6 +1,6 @@
 """ Tools for dealing with weapons. """
 
-from pgzero.loaders import images
+from pgzero.loaders import images, sounds
 from .actors.animsurf import AnimatedSurfActor
 from .util import safepath
 
@@ -14,7 +14,13 @@ class Weapon:
         self.damage = damage
         self.bullet_range = bullet_range
         self.can_tape = can_tape
-        self.sound = sound
+        self.sound = None
+        if sound:
+            self.sound = sounds.load(sound)
+
+    def play_sound(self):
+        if self.sound:
+            self.sound.play()
 
 
 WEAPONS = [