comparison eosd @ 332:bdcf2077e368

Add a boss rush mode
author Thibaut Girka <thib@sitedethib.com>
date Sat, 30 Jun 2012 20:10:45 +0200
parents 1b4f04b08729
children d369a369204a
comparison
equal deleted inserted replaced
331:1b4f04b08729 332:bdcf2077e368
27 from pytouhou.formats.t6rp import T6RP 27 from pytouhou.formats.t6rp import T6RP
28 from pytouhou.utils.random import Random 28 from pytouhou.utils.random import Random
29 from pytouhou.vm.msgrunner import NextStage 29 from pytouhou.vm.msgrunner import NextStage
30 30
31 31
32 def main(path, data, stage_num, rank, character, replay): 32 class EoSDGameBossRush(EoSDGame):
33 def run_iter(self, keystate):
34 for i in range(16):
35 EoSDGame.run_iter(self, keystate if i == 0 else 0)
36 if (self.msg_wait or self.enemies or self.items
37 or self.lasers or self.bullets or self.cancelled_bullets):
38 break
39
40 def cleanup(self):
41 if not (self.boss or self.msg_wait or self.ecl_runner.boss_wait):
42 self.enemies = [enemy for enemy in self.enemies
43 if enemy.boss_callback != -1 or enemy.frame > 1]
44 self.lasers = [laser for laser in self.lasers if laser.frame > 1]
45 self.bullets = [bullet for bullet in self.bullets if bullet.frame > 1]
46 self.players_lasers = [(laser if laser and laser.frame > 1 else None) for laser in self.players_lasers]
47 self.players_bullets = [bullet for bullet in self.players_bullets if bullet.frame > 1]
48 EoSDGame.cleanup(self)
49
50
51
52 def main(path, data, stage_num, rank, character, replay, boss_rush):
33 resource_loader = Loader(path) 53 resource_loader = Loader(path)
34 resource_loader.scan_archives(data) 54 resource_loader.scan_archives(data)
35 55
36 if stage_num is None: 56 if stage_num is None:
37 story = True 57 story = True
46 character = replay.character 66 character = replay.character
47 67
48 difficulty = 16 68 difficulty = 16
49 default_power = [0, 64, 128, 128, 128, 128, 0][stage_num - 1] 69 default_power = [0, 64, 128, 128, 128, 128, 0][stage_num - 1]
50 states = [PlayerState(character=character, power=default_power)] 70 states = [PlayerState(character=character, power=default_power)]
71
72 game_class = EoSDGameBossRush if boss_rush else EoSDGame
51 73
52 runner = GameRunner(resource_loader) 74 runner = GameRunner(resource_loader)
53 while True: 75 while True:
54 if replay: 76 if replay:
55 level = replay.levels[stage_num - 1] 77 level = replay.levels[stage_num - 1]
72 prng = None 94 prng = None
73 95
74 # Load stage data 96 # Load stage data
75 stage = resource_loader.get_stage('stage%d.std' % stage_num) 97 stage = resource_loader.get_stage('stage%d.std' % stage_num)
76 98
77 game = EoSDGame(resource_loader, states, stage_num, rank, difficulty, prng=prng, bgms=stage.bgms) 99 game = game_class(resource_loader, states, stage_num, rank, difficulty, prng=prng, bgms=stage.bgms)
78 100
79 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,)) 101 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
80 background = Background(stage, background_anm_wrapper) 102 background = Background(stage, background_anm_wrapper)
81 103
82 # Main loop 104 # Main loop
84 try: 106 try:
85 runner.start() 107 runner.start()
86 break 108 break
87 except NextStage: 109 except NextStage:
88 game.music.pause() 110 game.music.pause()
89 if not story or stage_num == 6: 111 if not story or stage_num == (7 if boss_rush else 6):
90 break 112 break
91 stage_num += 1 113 stage_num += 1
92 states = [player.state.copy() for player in game.players] # if player.state.lives >= 0] 114 states = [player.state.copy() for player in game.players] # if player.state.lives >= 0]
93 115
94 116
106 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.') 128 parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
107 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, default=None, help='Stage, 1 to 7 (Extra).') 129 parser.add_argument('-s', '--stage', metavar='STAGE', type=int, default=None, help='Stage, 1 to 7 (Extra).')
108 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).') 130 parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
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).') 131 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
110 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay') 132 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
133 parser.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses')
111 134
112 args = parser.parse_args() 135 args = parser.parse_args()
113 136
114 main(args.path, tuple(args.data), args.stage, args.rank, args.character, args.replay) 137 main(args.path, tuple(args.data), args.stage, args.rank, args.character, args.replay, args.boss_rush)