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	Sat Mar 28 19:58:50 2015 +0100
+++ b/pytouhou/game/player.pyx	Sat Mar 28 21:02:05 2015 +0100
@@ -24,8 +24,8 @@
 
 
 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	Sat Mar 28 19:58:50 2015 +0100
+++ b/pytouhou/games/eosd/game.py	Sat Mar 28 21:02:05 2015 +0100
@@ -26,7 +26,9 @@
 
 
 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 @@
                            ('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 @@
 
             self.players[i] = Player(i, self.player_anms[character][0],
                                      eosd_characters[player_character],
-                                     character, default_power, continues)
+                                     character, continues)
 
 
 
@@ -124,6 +124,8 @@
 
         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 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	Sat Mar 28 19:58:50 2015 +0100
+++ b/pytouhou/games/sample/game.py	Sat Mar 28 21:02:05 2015 +0100
@@ -27,7 +27,9 @@
 
 
 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 @@
                            ('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 @@
 
             self.players[i] = Player(i, self.player_anms[character][0],
                                      sample_characters[player_character],
-                                     character, default_power, continues)
+                                     character, continues)
 
 
 
@@ -125,6 +125,8 @@
 
         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 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	Sat Mar 28 19:58:50 2015 +0100
+++ b/scripts/pytouhou	Sat Mar 28 21:02:05 2015 +0100
@@ -202,7 +202,7 @@
 
     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