changeset 206:eca53abdfeab

Fix ReimuA, and refactor Player a bit.
author Thibaut Girka <thib@sitedethib.com>
date Sat, 05 Nov 2011 19:43:11 +0100
parents ee6dfd14a785
children 709f42eaa55e
files pytouhou/game/player.py pytouhou/games/eosd.py
diffstat 2 files changed, 79 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/player.py
+++ b/pytouhou/game/player.py
@@ -16,7 +16,6 @@
 from pytouhou.game.sprite import Sprite
 from pytouhou.vm.anmrunner import ANMRunner
 from pytouhou.game.bullettype import BulletType
-from pytouhou.utils.interpolator import Interpolator
 
 from math import pi
 
@@ -74,9 +73,6 @@ class Player(object):
 
         self.death_time = 0
 
-        self.orb_dx_interpolator = None
-        self.orb_dy_interpolator = None
-
 
     @property
     def x(self):
@@ -89,7 +85,7 @@ class Player(object):
 
 
     def objects(self):
-        return self.orbs if self.state.power >= 8 else []
+        return []
 
 
     def set_anim(self, index):
@@ -107,6 +103,14 @@ class Player(object):
                 self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range.
 
 
+    def start_focusing(self):
+        self.state.focused = True
+
+
+    def stop_focusing(self):
+        self.state.focused = False
+
+
     def update(self, keystate):
         if self.death_time == 0 or self._game.frame - self.death_time > 60:
             try:
@@ -134,30 +138,9 @@ class Player(object):
             self.state.y += dy
 
             if not self.state.focused and keystate & 4:
-                self.orb_dx_interpolator = Interpolator((24,), self._game.frame,
-                                                        (8,), self._game.frame + 8,
-                                                        lambda x: x ** 2)
-                self.orb_dy_interpolator = Interpolator((0,), self._game.frame,
-                                                        (-32,), self._game.frame + 8)
-                self.state.focused = True
+                self.start_focusing()
             elif self.state.focused and not keystate & 4:
-                self.orb_dx_interpolator = Interpolator((8,), self._game.frame,
-                                                        (24,), self._game.frame + 8,
-                                                        lambda x: x ** 2)
-                self.orb_dy_interpolator = Interpolator((-32,), self._game.frame,
-                                                        (0,), self._game.frame + 8)
-                self.state.focused = False
-
-            if self.orb_dx_interpolator:
-                self.orb_dx_interpolator.update(self._game.frame)
-                dx, = self.orb_dx_interpolator.values
-                self.orbs[0].offset_x = -dx
-                self.orbs[1].offset_x = dx
-            if self.orb_dy_interpolator:
-                self.orb_dy_interpolator.update(self._game.frame)
-                dy, = self.orb_dy_interpolator.values
-                self.orbs[0].offset_y = dy
-                self.orbs[1].offset_y = dy
+                self.stop_focusing()
 
             if self.state.invulnerable_time > 0:
                 self.state.invulnerable_time -= 1
@@ -226,10 +209,5 @@ class Player(object):
             if time > 90: # start the bullet hell again
                 self.death_time = 0
 
-
-        for orb in self.orbs:
-            orb.update()
-
-
         self._anmrunner.run_frame()
 
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -12,6 +12,7 @@
 ## GNU General Public License for more details.
 ##
 
+from pytouhou.utils.interpolator import Interpolator
 
 from pytouhou.game.game import Game
 from pytouhou.game.bullettype import BulletType
@@ -55,12 +56,73 @@ class EoSDGame(Game):
                       bullet_types, item_types, nb_bullets_max=640, **kwargs)
 
 
-class Reimu(Player):
+
+class EoSDPlayer(Player):
+    def __init__(self, state, game, anm_wrapper, speed=4., hitbox_size=2.5, graze_hitbox_size=42.):
+        Player.__init__(self, state, game, anm_wrapper, speed=4.)
+
+        self.orbs = [Orb(self.anm_wrapper, 128, self.state, self.orb_fire),
+                     Orb(self.anm_wrapper, 129, self.state, self.orb_fire)]
+
+        self.orbs[0].offset_x = -24
+        self.orbs[1].offset_x = 24
+
+        self.orb_dx_interpolator = None
+        self.orb_dy_interpolator = None
+
+
+    def start_focusing(self):
+        self.orb_dx_interpolator = Interpolator((24,), self._game.frame,
+                                                (8,), self._game.frame + 8,
+                                                lambda x: x ** 2)
+        self.orb_dy_interpolator = Interpolator((0,), self._game.frame,
+                                                (-32,), self._game.frame + 8)
+        self.state.focused = True
+
+
+    def stop_focusing(self):
+        self.orb_dx_interpolator = Interpolator((8,), self._game.frame,
+                                                (24,), self._game.frame + 8,
+                                                lambda x: x ** 2)
+        self.orb_dy_interpolator = Interpolator((-32,), self._game.frame,
+                                                (0,), self._game.frame + 8)
+        self.state.focused = False
+
+
+    def objects(self):
+        return self.orbs if self.state.power >= 8 else []
+
+
+    def update(self, keystate):
+        Player.update(self, keystate)
+
+        if self.death_time == 0 or self._game.frame - self.death_time > 60:
+            if self.orb_dx_interpolator:
+                self.orb_dx_interpolator.update(self._game.frame)
+                dx, = self.orb_dx_interpolator.values
+                self.orbs[0].offset_x = -dx
+                self.orbs[1].offset_x = dx
+            if self.orb_dy_interpolator:
+                self.orb_dy_interpolator.update(self._game.frame)
+                dy, = self.orb_dy_interpolator.values
+                self.orbs[0].offset_y = dy
+                self.orbs[1].offset_y = dy
+
+        for orb in self.orbs:
+            orb.update()
+
+
+    def orb_fire(self, orb):
+        pass
+
+
+
+class Reimu(EoSDPlayer):
     def __init__(self, state, game, resource_loader):
         anm_wrapper = resource_loader.get_anm_wrapper(('player00.anm',))
         self.bullet_angle = pi/30 #TODO: check
 
-        Player.__init__(self, state, game, anm_wrapper, speed=4.)
+        EoSDPlayer.__init__(self, state, game, anm_wrapper, speed=4.)
 
 
     def fire(self):
@@ -94,6 +156,7 @@ class Reimu(Player):
             orb.fire(orb)
 
 
+
 class ReimuA(Reimu):
     def __init__(self, state, game, resource_loader):
         Reimu.__init__(self, state, game, resource_loader)
@@ -112,6 +175,7 @@ class ReimuA(Reimu):
             pass #TODO
 
 
+
 class ReimuB(Reimu):
     def __init__(self, state, game, resource_loader):
         Reimu.__init__(self, state, game, resource_loader)
@@ -119,11 +183,6 @@ class ReimuB(Reimu):
         self.bulletB_type = BulletType(self.anm_wrapper, 66, 98, 0, 0, 0, hitbox_size=4, damage=12) #TODO: verify the hitbox.
         self.bulletB_speed = 22.
 
-        self.orbs = [Orb(self.anm_wrapper, 128, self.state, self.orb_fire),
-                     Orb(self.anm_wrapper, 129, self.state, self.orb_fire)]
-        self.orbs[0].offset_x = -24
-        self.orbs[1].offset_x = 24
-
 
     def fire_spine(self, orb, offset_x):
         bullets = self._game.players_bullets
@@ -176,12 +235,12 @@ class ReimuB(Reimu):
 
 
 
-class Marisa(Player):
+class Marisa(EoSDPlayer):
     def __init__(self, state, game, resource_loader):
         anm_wrapper = resource_loader.get_anm_wrapper(('player01.anm',))
         self.bullet_angle = pi/40 #TODO: check
 
-        Player.__init__(self, state, game, anm_wrapper, speed=5.)
+        EoSDPlayer.__init__(self, state, game, anm_wrapper, speed=5.)
 
 
     def fire(self):