attack
authorFrank DeMarco <frank.s.demarco@gmail.com>
Thu, 22 May 2014 19:32:44 +0000 (04:32 +0900)
committerFrank DeMarco <frank.s.demarco@gmail.com>
Thu, 22 May 2014 19:32:44 +0000 (04:32 +0900)
lake_of_heavenly_wind/LakeOfHeavenlyWind.py

index 177f0e8..8bd3cd0 100644 (file)
@@ -89,6 +89,7 @@ class Pulp(GameChild, Surface):
         GameChild.__init__(self, parent)
         self.display_surface = self.get_display_surface()
         self.health = .9999
+        self.explosions = [Explosion(self) for _ in xrange(32)]
         Surface.__init__(self, (self.display_surface.get_width(), 96))
         self.rect = self.get_rect()
         indicators = self.indicators = []
@@ -124,6 +125,43 @@ class Pulp(GameChild, Surface):
                 indicator.move(dy=self.image_r.h)
         self.indicators[int(self.health * len(self.indicators))].update()
         self.display_surface.blit(self, self.rect)
+        outgoing = []
+        for phage in self.parent.rails.phages:
+            if phage.get_center()[1] <= self.rect.centery:
+                outgoing.append(phage)
+                self.health -= .05
+                for explosion in self.explosions:
+                    if explosion.is_hidden():
+                        explosion.get_current_frameset().reset()
+                        explosion.location.center = phage.get_center()
+                        explosion.unhide()
+                        break
+        for phage in outgoing:
+            self.parent.rails.phages.remove(phage)
+        for explosion in self.explosions:
+            explosion.update()
+
+
+class Explosion(Sprite):
+
+    def __init__(self, parent):
+        Sprite.__init__(self, parent)
+        count = 32
+        color = Color(0, 0, 0)
+        for ii in xrange(count):
+            frame = Surface((64, 64), SRCALPHA)
+            ratio = float(ii) / count
+            color.hsla = 60 - ratio * 60, 100, 50, 100 - ratio * 100
+            fr = frame.get_rect()
+            circle(frame, color, fr.center, 6 + int(ratio * (fr.w / 2 - 6)), 5)
+            self.add_frame(frame)
+        self.hide()
+
+    def shift_frame(self):
+        Sprite.shift_frame(self)
+        frameset = self.get_current_frameset()
+        if frameset.current_index == frameset.length() - 1:
+            self.hide()
 
 
 class Link(GameChild):