changeset 614:2cf518129725

Delay power assignment to players until the game is started.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Mar 2015 21:02:05 +0100
parents 560b45a7d014
children d1f0bb0b7a17
files pytouhou/game/player.pyx pytouhou/games/eosd/game.py pytouhou/games/sample/game.py scripts/pytouhou
diffstat 4 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/player.pyx
+++ b/pytouhou/game/player.pyx
@@ -24,8 +24,8 @@ from pytouhou.game import GameOver
 
 
 cdef class Player(Element):
-    def __init__(self, long number, anm, long character=0, long power=0,
-                 long continues=0, long lives=2, long bombs=3, long score=0):
+    def __init__(self, long number, anm, long character=0, long continues=0,
+                 long power=0, long lives=2, long bombs=3, long score=0):
         Element.__init__(self, (192, 384))
 
         self.number = number
--- a/pytouhou/games/eosd/game.py
+++ b/pytouhou/games/eosd/game.py
@@ -26,7 +26,9 @@ from pytouhou.vm import ECLMainRunner
 
 
 class Common(object):
-    def __init__(self, resource_loader, player_characters, continues, stage,
+    default_power = [0, 64, 128, 128, 128, 128, 0]
+
+    def __init__(self, resource_loader, player_characters, continues, *,
                  width=384, height=448):
         self.width, self.height = width, height
 
@@ -75,8 +77,6 @@ class Common(object):
                            ('face09b.anm', 'face10a.anm', 'face10b.anm'),
                            ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')]
 
-        default_power = [0, 64, 128, 128, 128, 128, 0][stage]
-
         eosd_characters = resource_loader.get_eosd_characters()
         self.first_character = player_characters[0] // 2
         self.player_anms = {}
@@ -92,7 +92,7 @@ class Common(object):
 
             self.players[i] = Player(i, self.player_anms[character][0],
                                      eosd_characters[player_character],
-                                     character, default_power, continues)
+                                     character, continues)
 
 
 
@@ -124,6 +124,8 @@ class Game(GameBase):
 
         for player in common.players:
             player._game = self
+            if player.power < 0:
+                player.power = common.default_power[stage - 1]
 
         # Load stage data
         self.std = resource_loader.get_stage('stage%d.std' % stage)
@@ -152,11 +154,11 @@ class Game(GameBase):
 
 
 class Player(PlayerBase):
-    def __init__(self, number, anm, shts, character, power, continues):
+    def __init__(self, number, anm, shts, character, continues):
         self.sht = shts[0]
         self.focused_sht = shts[1]
 
-        PlayerBase.__init__(self, number, anm, character, power, continues)
+        PlayerBase.__init__(self, number, anm, character, continues, power=-1)
 
         self.orbs = [Orb(anm, 128, self),
                      Orb(anm, 129, self)]
--- a/pytouhou/games/sample/game.py
+++ b/pytouhou/games/sample/game.py
@@ -27,7 +27,9 @@ from . import enemies, shots
 
 
 class Common(object):
-    def __init__(self, resource_loader, player_characters, continues, stage,
+    default_power = [0, 64, 128, 128, 128, 128, 0]
+
+    def __init__(self, resource_loader, player_characters, continues, *,
                  width=384, height=448):
         self.width, self.height = width, height
 
@@ -76,8 +78,6 @@ class Common(object):
                            ('face09b.anm', 'face10a.anm', 'face10b.anm'),
                            ('face08a.anm', 'face12a.anm', 'face12b.anm', 'face12c.anm')]
 
-        default_power = [0, 64, 128, 128, 128, 128, 0][stage]
-
         sample_characters = shots.characters
         self.first_character = player_characters[0] // 2
         self.player_anms = {}
@@ -93,7 +93,7 @@ class Common(object):
 
             self.players[i] = Player(i, self.player_anms[character][0],
                                      sample_characters[player_character],
-                                     character, default_power, continues)
+                                     character, continues)
 
 
 
@@ -125,6 +125,8 @@ class Game(GameBase):
 
         for player in common.players:
             player._game = self
+            if player.power < 0:
+                player.power = common.default_power[stage - 1]
 
         # Load stage data
         self.std = resource_loader.get_stage('stage%d.std' % stage)
@@ -143,11 +145,11 @@ class Game(GameBase):
 
 
 class Player(PlayerBase):
-    def __init__(self, number, anm, shts, character, power, continues):
+    def __init__(self, number, anm, shts, character, continues):
         self.sht = shts[0]
         self.focused_sht = shts[1]
 
-        PlayerBase.__init__(self, number, anm, character, power, continues)
+        PlayerBase.__init__(self, number, anm, character, continues, power=-1)
 
         self.orbs = [Orb(anm, 128, self),
                      Orb(anm, 129, self)]
--- a/scripts/pytouhou
+++ b/scripts/pytouhou
@@ -202,7 +202,7 @@ def main(window, path, data, stage_num, 
 
     game_class = GameBossRush if boss_rush else Game
 
-    common = Common(resource_loader, characters, continues, stage_num - 1)
+    common = Common(resource_loader, characters, continues)
     interface = Interface(resource_loader, common.players[0]) #XXX
     common.interface = interface #XXX
     renderer = GameRenderer(resource_loader, window) if GameRenderer is not None else None