changeset 339:7a05edbab88a

Implement continues when the lives fall bellow 0.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 04 Jul 2012 21:38:00 +0200
parents 65453340ae95
children 39bc59953dfa
files eosd pytouhou/game/game.py pytouhou/game/player.py pytouhou/games/eosd.py
diffstat 4 files changed, 51 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -24,6 +24,7 @@ from pytouhou.resource.loader import Loa
 from pytouhou.game.background import Background
 from pytouhou.ui.gamerunner import GameRunner
 from pytouhou.games.eosd import EoSDGame
+from pytouhou.game.game import GameOver
 from pytouhou.game.player import PlayerState
 from pytouhou.formats.t6rp import T6RP
 from pytouhou.utils.random import Random
@@ -50,7 +51,7 @@ class EoSDGameBossRush(EoSDGame):
 
 
 
-def main(path, data, stage_num, rank, character, replay, boss_rush, fps_limit, single_buffer):
+def main(path, data, stage_num, rank, character, replay, boss_rush, fps_limit, single_buffer, debug):
     resource_loader = Loader(path)
 
     try:
@@ -62,8 +63,13 @@ def main(path, data, stage_num, rank, ch
     if stage_num is None:
         story = True
         stage_num = 1
+        continues = 3
     else:
         story = False
+        continues = 0
+
+    if debug:
+        continues = float('inf')
 
     if replay:
         with open(replay, 'rb') as file:
@@ -102,7 +108,7 @@ def main(path, data, stage_num, rank, ch
         # Load stage data
         stage = resource_loader.get_stage('stage%d.std' % stage_num)
 
-        game = game_class(resource_loader, states, stage_num, rank, difficulty, prng=prng, bgms=stage.bgms)
+        game = game_class(resource_loader, states, stage_num, rank, difficulty, prng=prng, bgms=stage.bgms, continues=continues)
 
         background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
         background = Background(stage, background_anm_wrapper)
@@ -118,6 +124,9 @@ def main(path, data, stage_num, rank, ch
                 break
             stage_num += 1
             states = [player.state.copy() for player in game.players] # if player.state.lives >= 0]
+        except GameOver:
+            print('Game over')
+            break
 
 
 pathsep = os.path.pathsep
@@ -139,8 +148,10 @@ parser.add_argument('--replay', metavar=
 parser.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses')
 parser.add_argument('--single-buffer', action='store_true', help='Disable double buffering')
 parser.add_argument('--fps-limit', metavar='FPS', default=60, type=int, help='Set fps limit')
+parser.add_argument('--debug', action='store_true', help='Set unlimited continues, and perhaps other debug features.')
 
 args = parser.parse_args()
 
 main(args.path, tuple(args.data), args.stage, args.rank, args.character,
-     args.replay, args.boss_rush, args.fps_limit, args.single_buffer)
+     args.replay, args.boss_rush, args.fps_limit, args.single_buffer,
+     args.debug)
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -28,10 +28,15 @@ from pytouhou.game.text import Text
 
 
 
+class GameOver(Exception):
+    pass
+
+
 class Game(object):
     def __init__(self, resource_loader, players, stage, rank, difficulty,
                  bullet_types, laser_types, item_types,
-                 nb_bullets_max=None, width=384, height=448, prng=None, interface=None):
+                 nb_bullets_max=None, width=384, height=448, prng=None,
+                 interface=None, continues=0):
         self.resource_loader = resource_loader
 
         self.width, self.height = width, height
@@ -53,6 +58,7 @@ class Game(object):
         self.labels = []
         self.interface = interface
 
+        self.continues = continues
         self.stage = stage
         self.rank = rank
         self.difficulty = difficulty
--- a/pytouhou/game/player.py
+++ b/pytouhou/game/player.py
@@ -19,6 +19,7 @@ from pytouhou.game.bullettype import Bul
 from pytouhou.game.bullet import Bullet
 from pytouhou.game.lasertype import LaserType
 from pytouhou.game.laser import PlayerLaser
+from pytouhou.game.game import GameOver
 
 from math import pi
 
@@ -214,19 +215,38 @@ class Player(object):
             time = self._game.frame - self.death_time
             if time == 6: # too late, you are dead :(
                 self.state.touchable = False
-                self.state.lives -= 1
                 if self.state.power > 16:
                     self.state.power -= 16
                 else:
                     self.state.power = 0
 
-                self._game.drop_bonus(self.state.x, self.state.y, 2,
-                                      end_pos=(self._game.prng.rand_double() * 288 + 48, # 102h.exe@0x41f3dc
-                                               self._game.prng.rand_double() * 192 - 64))        # @0x41f3
-                for i in range(5):
-                    self._game.drop_bonus(self.state.x, self.state.y, 0,
-                                          end_pos=(self._game.prng.rand_double() * 288 + 48,
-                                                   self._game.prng.rand_double() * 192 - 64))
+                self.state.lives -= 1
+                if self.state.lives < 0:
+                    #TODO: display a menu to ask the players if they want to continue.
+                    self._game.continues -= 1
+                    if self._game.continues < 0:
+                        raise GameOver
+
+                    for i in range(5):
+                        self._game.drop_bonus(self.state.x, self.state.y, 4,
+                                              end_pos=(self._game.prng.rand_double() * 288 + 48,
+                                                       self._game.prng.rand_double() * 192 - 64))
+                    self.state.score = 0
+                    self.state.effective_score = 0
+                    self.state.lives = 2 #TODO: use the right default.
+                    self.state.bombs = 3 #TODO: use the right default.
+                    self.state.power = 0
+
+                    self.state.graze = 0
+                    self.state.points = 0
+                else:
+                    self._game.drop_bonus(self.state.x, self.state.y, 2,
+                                          end_pos=(self._game.prng.rand_double() * 288 + 48, # 102h.exe@0x41f3dc
+                                                   self._game.prng.rand_double() * 192 - 64))        # @0x41f3
+                    for i in range(5):
+                        self._game.drop_bonus(self.state.x, self.state.y, 0,
+                                              end_pos=(self._game.prng.rand_double() * 288 + 48,
+                                                       self._game.prng.rand_double() * 192 - 64))
 
             elif time == 7:
                 self.sprite.mirrored = False
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -33,7 +33,7 @@ SQ2 = 2. ** 0.5 / 2.
 class EoSDGame(Game):
     def __init__(self, resource_loader, player_states, stage, rank, difficulty,
                  bullet_types=None, laser_types=None, item_types=None,
-                 nb_bullets_max=640, width=384, height=448, prng=None, bgms=None):
+                 nb_bullets_max=640, width=384, height=448, prng=None, bgms=None, continues=0):
 
         if not bullet_types:
             etama3 = resource_loader.get_anm_wrapper(('etama3.anm',))
@@ -112,7 +112,7 @@ class EoSDGame(Game):
 
         Game.__init__(self, resource_loader, players, stage, rank, difficulty,
                       bullet_types, laser_types, item_types, nb_bullets_max,
-                      width, height, prng, interface)
+                      width, height, prng, interface, continues)