Very hacky bullets.
[koperkapel.git] / koperkapel / weapons.py
index ee83eb816c6eb5c9295db74c05fb78199d506e56..7dcb41ed154250bcc009f0f5ce8fdf80261e2a56 100644 (file)
@@ -1,5 +1,7 @@
 """ Tools for dealing with weapons. """
 
+from pygame.surface import Surface
+from pygame.draw import circle
 from pgzero.loaders import images, sounds
 from .actors.animsurf import AnimatedSurfActor
 from .util import safepath
@@ -22,6 +24,9 @@ class Weapon:
         if self.sound:
             self.sound.play()
 
+    def assemble_bullet(self):
+        return BulletActor(self)
+
 
 WEAPONS = [
     Weapon("spit", damage=1, bullet_range=2, can_tape=False,
@@ -44,6 +49,18 @@ class WeaponActor(AnimatedSurfActor):
         self.weapon = weapon
 
 
+class BulletActor(AnimatedSurfActor):
+    def __init__(self, weapon, **kw):
+        radius = min(weapon.damage * 5, 32)
+        surf = Surface((radius * 2, radius * 2))
+        surf.convert_alpha()
+        surf.fill((255, 255, 255, 0))
+        circle(surf, (255, 0, 255, 32), (radius, radius), radius)
+        frames = [surf]
+        super().__init__(frames=frames, **kw)
+        self.weapon = weapon
+
+
 class WeaponFactory:
 
     def assemble_frame(self, suffix, weapon, tape):