Mercurial > touhou
comparison eosd @ 331:1b4f04b08729
Add the story mode.
| author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
|---|---|
| date | Sat, 30 Jun 2012 19:37:21 +0200 |
| parents | 61adb5453e46 |
| children | bdcf2077e368 |
comparison
equal
deleted
inserted
replaced
| 330:16ed1ab1e14b | 331:1b4f04b08729 |
|---|---|
| 23 from pytouhou.game.background import Background | 23 from pytouhou.game.background import Background |
| 24 from pytouhou.ui.gamerunner import GameRunner | 24 from pytouhou.ui.gamerunner import GameRunner |
| 25 from pytouhou.games.eosd import EoSDGame | 25 from pytouhou.games.eosd import EoSDGame |
| 26 from pytouhou.game.player import PlayerState | 26 from pytouhou.game.player import PlayerState |
| 27 from pytouhou.formats.t6rp import T6RP | 27 from pytouhou.formats.t6rp import T6RP |
| 28 from pytouhou.utils.random import Random | |
| 29 from pytouhou.vm.msgrunner import NextStage | |
| 28 | 30 |
| 29 | 31 |
| 30 def main(path, stage_num, rank, character, replay, data): | 32 def main(path, data, stage_num, rank, character, replay): |
| 33 resource_loader = Loader(path) | |
| 34 resource_loader.scan_archives(data) | |
| 35 | |
| 36 if stage_num is None: | |
| 37 story = True | |
| 38 stage_num = 1 | |
| 39 else: | |
| 40 story = False | |
| 41 | |
| 31 if replay: | 42 if replay: |
| 32 with open(replay, 'rb') as file: | 43 with open(replay, 'rb') as file: |
| 33 replay = T6RP.read(file) | 44 replay = T6RP.read(file) |
| 34 rank = replay.rank | 45 rank = replay.rank |
| 35 character = replay.character | 46 character = replay.character |
| 36 if not replay.levels[stage_num-1]: | |
| 37 raise Exception | |
| 38 from pytouhou.utils.random import Random | |
| 39 prng = Random(replay.levels[stage_num-1].random_seed) | |
| 40 else: | |
| 41 prng = None | |
| 42 | 47 |
| 43 resource_loader = Loader(path) | 48 difficulty = 16 |
| 49 default_power = [0, 64, 128, 128, 128, 128, 0][stage_num - 1] | |
| 50 states = [PlayerState(character=character, power=default_power)] | |
| 44 | 51 |
| 45 resource_loader.scan_archives(data) | 52 runner = GameRunner(resource_loader) |
| 53 while True: | |
| 54 if replay: | |
| 55 level = replay.levels[stage_num - 1] | |
| 56 if not level: | |
| 57 raise Exception | |
| 46 | 58 |
| 47 # Load stage data | 59 prng = Random(level.random_seed) |
| 48 stage = resource_loader.get_stage('stage%d.std' % stage_num) | |
| 49 | 60 |
| 50 default_power = [0, 64, 128, 128, 128, 128, 0][stage_num - 1] | 61 #TODO: apply the replay to the other players. |
| 51 game = EoSDGame(resource_loader, [PlayerState(character=character, power=default_power)], stage_num, rank, 16, | 62 #TODO: see if the stored score is used or if it’s the one from the previous stage. |
| 52 prng=prng, bgms=stage.bgms) | 63 if stage_num != 1 and stage_num - 2 in replay.levels: |
| 64 previous_level = replay.levels[stage_num - 1] | |
| 65 states[0].score = previous_level.score | |
| 66 states[0].effective_score = previous_level.score | |
| 67 states[0].power = level.power | |
| 68 states[0].lives = level.lives | |
| 69 states[0].bombs = level.bombs | |
| 70 difficulty = level.difficulty | |
| 71 else: | |
| 72 prng = None | |
| 53 | 73 |
| 54 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,)) | 74 # Load stage data |
| 55 background = Background(stage, background_anm_wrapper) | 75 stage = resource_loader.get_stage('stage%d.std' % stage_num) |
| 56 | 76 |
| 57 # Main loop | 77 game = EoSDGame(resource_loader, states, stage_num, rank, difficulty, prng=prng, bgms=stage.bgms) |
| 58 runner = GameRunner(resource_loader, game, background, replay=replay) | 78 |
| 59 runner.start() | 79 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,)) |
| 80 background = Background(stage, background_anm_wrapper) | |
| 81 | |
| 82 # Main loop | |
| 83 runner.load_game(game, background, replay) | |
| 84 try: | |
| 85 runner.start() | |
| 86 break | |
| 87 except NextStage: | |
| 88 game.music.pause() | |
| 89 if not story or stage_num == 6: | |
| 90 break | |
| 91 stage_num += 1 | |
| 92 states = [player.state.copy() for player in game.players] # if player.state.lives >= 0] | |
| 60 | 93 |
| 61 | 94 |
| 62 pathsep = os.path.pathsep | 95 pathsep = os.path.pathsep |
| 63 default_data = (pathsep.join(('CM.DAT', 'th06*_CM.DAT', '*CM.DAT', '*cm.dat')), | 96 default_data = (pathsep.join(('CM.DAT', 'th06*_CM.DAT', '*CM.DAT', '*cm.dat')), |
| 64 pathsep.join(('ST.DAT', 'th6*ST.DAT', '*ST.DAT', '*st.dat')), | 97 pathsep.join(('ST.DAT', 'th6*ST.DAT', '*ST.DAT', '*st.dat')), |
| 69 | 102 |
| 70 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.') | 103 parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.') |
| 71 | 104 |
| 72 parser.add_argument('data', metavar='DAT', default=default_data, nargs='*', help='Game’s data files') | 105 parser.add_argument('data', metavar='DAT', default=default_data, nargs='*', help='Game’s data files') |
| 73 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.') | 106 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.') |
| 74 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).') | 107 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, default=None, help='Stage, 1 to 7 (Extra).') |
| 75 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).') | 108 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).') |
| 76 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).') | 109 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).') |
| 77 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay') | 110 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay') |
| 78 | 111 |
| 79 args = parser.parse_args() | 112 args = parser.parse_args() |
| 80 | 113 |
| 81 main(args.path, args.stage, args.rank, args.character, args.replay, tuple(args.data)) | 114 main(args.path, tuple(args.data), args.stage, args.rank, args.character, args.replay) |
