changeset 88:2cc60137d368

Ugly implementation of three new attack flags.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 03 Sep 2011 17:44:48 -0700
parents fda176f07d6d
children 1513f5626656
files pytouhou/game/bullet.py
diffstat 1 files changed, 43 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/bullet.py
+++ b/pytouhou/game/bullet.py
@@ -61,6 +61,14 @@ class Bullet(object):
             self.speed_interpolator = Interpolator((speed + 5.,))
             self.speed_interpolator.set_interpolation_start(0, (speed + 5.,))
             self.speed_interpolator.set_interpolation_end(16, (speed,))
+        if flags & 448:
+            self.speed_interpolator = Interpolator((speed,))
+            self.speed_interpolator.set_interpolation_start(0, (speed,))
+            self.speed_interpolator.set_interpolation_end(attributes[0] - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set.
+
+
+    def get_player_angle(self):
+        return atan2(self.player.y - self.y, self.player.x - self.x)
 
 
     def is_visible(self, screen_width, screen_height):
@@ -115,19 +123,45 @@ class Bullet(object):
         x, y = self.x, self.y
 
         if self.flags & 16:
-            #TODO: duration, count
+            duration = self.attributes[0]
             length, angle = self.attributes[4:6]
-            angle = self.angle if angle < -900.0 else angle #TODO: is that right?
-            dx = cos(self.angle) * self.speed + cos(angle) * length
-            dy = sin(self.angle) * self.speed + sin(angle) * length
-            self.speed = (dx ** 2 + dy ** 2) ** 0.5
-            self.angle = atan2(dy, dx)
+            if self.frame < duration:
+                angle = self.angle if angle < -900.0 else angle #TODO: is that right?
+                dx = cos(self.angle) * self.speed + cos(angle) * length
+                dy = sin(self.angle) * self.speed + sin(angle) * length
+                self.speed = (dx ** 2 + dy ** 2) ** 0.5
+                self.angle = atan2(dy, dx)
         elif self.flags & 32:
-            #TODO: duration, count
+            #TODO: count
             #TODO: check
+            duration, count = self.attributes[0:2]
             acceleration, angular_speed = self.attributes[4:6]
-            self.speed += acceleration
-            self.angle += angular_speed
+            if self.frame < duration:
+                self.speed += acceleration
+                self.angle += angular_speed
+        elif self.flags & 448:
+            #TODO: check
+            frame, count = self.attributes[0:2]
+            if count > 0:
+                angle, speed = self.attributes[4:6]
+                if frame == self.frame:
+                    self._sprite._removed = True
+                    count = count - 1
+
+                    if self.flags & 64:
+                        self.angle = self.angle + angle
+                    elif self.flags & 128:
+                        self.angle = self.get_player_angle() + angle
+                    elif self.flags & 256:
+                        self.angle = angle
+
+                    if count:
+                        self.speed_interpolator.set_interpolation_start(self.frame, (speed,))
+                        self.speed_interpolator.set_interpolation_end(self.frame + frame - 1, (0,)) # TODO: really -1? Without, the new speed isn’t set.
+                    else:
+                        self.speed = speed
+
+                    self.attributes[1] = count
         #TODO: other flags
 
         if self.speed_interpolator: