changeset 232:8843e26f80c3

Hopefully implement “accelerating” bullets
author Thibaut Girka <thib@sitedethib.com>
date Sat, 31 Dec 2011 02:15:51 +0100
parents c417bb6c98bf
children 067f6d9c562b
files pytouhou/game/bullet.py pytouhou/games/eosd.py pytouhou/games/pcb.py
diffstat 3 files changed, 28 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/bullet.py
+++ b/pytouhou/game/bullet.py
@@ -21,7 +21,7 @@ from pytouhou.game.sprite import Sprite
 
 class Bullet(object):
     def __init__(self, pos, bullet_type, sprite_idx_offset,
-                       angle, speed, attributes, flags, player, game,
+                       angle, speed, attributes, flags, target, game,
                        player_bullet=False, damage=0, hitbox=None):
         self._game = game
         self._sprite = None
@@ -39,7 +39,7 @@ class Bullet(object):
         self.frame = 0
         self.grazed = False
 
-        self.player = player
+        self.target = target
 
         self.sprite_idx_offset = sprite_idx_offset
 
@@ -217,7 +217,7 @@ class Bullet(object):
                     if self.flags & 64:
                         self.angle += angle
                     elif self.flags & 128:
-                        self.angle = atan2(self.player.y - y, self.player.x - x) + angle
+                        self.angle = atan2(self.target.y - y, self.target.x - x) + angle
                     elif self.flags & 256:
                         self.angle = angle
 
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -132,21 +132,32 @@ class EoSDPlayer(Player):
         nb_bullets_max = self._game.nb_bullets_max
 
         for shot in sht.shots[power]:
-            if shot.type in (2, 3): # TODO: Those shot types aren't handled yet
+            if shot.type == 3: # TODO: Lasers aren't implemented yet
+                continue
+
+            if self.fire_time % shot.interval != shot.delay:
                 continue
 
-            if self.fire_time % shot.interval == shot.delay:
-                if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
-                    break
+            if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
+                break
+
+            origin = self.orbs[shot.orb - 1] if shot.orb else self
+            x = origin.x + shot.pos[0]
+            y = origin.y + shot.pos[1]
 
-                origin = self.orbs[shot.orb - 1] if shot.orb else self
-                x = origin.x + shot.pos[0]
-                y = origin.y + shot.pos[1]
-
-                #TODO: find a better way to do that.
-                bullet_type = BulletType(self.anm_wrapper, shot.sprite % 256,
-                                         shot.sprite % 256 + 32, #TODO: find the real cancel anim
-                                         0, 0, 0, 0.)
+            #TODO: find a better way to do that.
+            bullet_type = BulletType(self.anm_wrapper, shot.sprite % 256,
+                                     shot.sprite % 256 + 32, #TODO: find the real cancel anim
+                                     0, 0, 0, 0.)
+            if shot.type == 2:
+                #TODO: check acceleration, check duration, check everything!
+                bullets.append(Bullet((x, y), bullet_type, 0,
+                                      shot.angle, shot.speed,
+                                      (-1, 0, 0, 0, 0.15, -pi/2., 0., 0.),
+                                      16, self, self._game, player_bullet=True,
+                                      damage=shot.damage, hitbox=shot.hitbox))
+            #TODO: types 1 and 4
+            else:
                 bullets.append(Bullet((x, y), bullet_type, 0,
                                       shot.angle, shot.speed,
                                       (0, 0, 0, 0, 0., 0., 0., 0.),
--- a/pytouhou/games/pcb.py
+++ b/pytouhou/games/pcb.py
@@ -139,4 +139,5 @@ class PCBPlayer(Player):
                 bullets.append(Bullet((x, y), self.bullet_type, 0,
                                       shot.angle, shot.speed,
                                       (0, 0, 0, 0, 0., 0., 0., 0.),
-                                      0, self, self._game, player_bullet=True, damage=shot.damage, hitbox=shot.hitbox))
+                                      0, self, self._game, player_bullet=True,
+                                      damage=shot.damage, hitbox=shot.hitbox))