comparison eosd @ 494:6be9c99a3a24

Merge PlayerState into Player, fix player respawn position.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 14 Oct 2013 12:11:01 +0200
parents 887de1309491
children 5426825c11a6
comparison
equal deleted inserted replaced
493:26c082870dcf 494:6be9c99a3a24
58 58
59 from pytouhou.lib.sdl import SDL 59 from pytouhou.lib.sdl import SDL
60 from pytouhou.ui.window import Window 60 from pytouhou.ui.window import Window
61 from pytouhou.resource.loader import Loader 61 from pytouhou.resource.loader import Loader
62 from pytouhou.ui.gamerunner import GameRunner 62 from pytouhou.ui.gamerunner import GameRunner
63 from pytouhou.game.player import PlayerState, GameOver 63 from pytouhou.game.player import GameOver
64 from pytouhou.formats.t6rp import T6RP, Level 64 from pytouhou.formats.t6rp import T6RP, Level
65 from pytouhou.utils.random import Random 65 from pytouhou.utils.random import Random
66 from pytouhou.vm.msgrunner import NextStage 66 from pytouhou.vm.msgrunner import NextStage
67 from pytouhou.formats.hint import Hint 67 from pytouhou.formats.hint import Hint
68 from pytouhou.network import Network 68 from pytouhou.network import Network
80 if skip: 80 if skip:
81 keystate &= ~1 81 keystate &= ~1
82 Game.run_iter(self, keystate | 256 if i == 0 else 0) 82 Game.run_iter(self, keystate | 256 if i == 0 else 0)
83 if not self.enemies and self.frame % 90 == 0: 83 if not self.enemies and self.frame % 90 == 0:
84 for player in self.players: 84 for player in self.players:
85 if player.state.power < 128: 85 if player.power < 128:
86 player.state.power += 1 86 player.power += 1
87 if not skip: 87 if not skip:
88 break 88 break
89 89
90 def cleanup(self): 90 def cleanup(self):
91 boss_wait = any(ecl_runner.boss_wait for ecl_runner in self.ecl_runners) 91 boss_wait = any(ecl_runner.boss_wait for ecl_runner in self.ecl_runners)
139 save_replay = T6RP() 139 save_replay = T6RP()
140 save_replay.rank = rank 140 save_replay.rank = rank
141 save_replay.character = character 141 save_replay.character = character
142 142
143 difficulty = 16 143 difficulty = 16
144 default_power = [0, 64, 128, 128, 128, 128, 0][stage_num - 1]
145 144
146 if port != 0: 145 if port != 0:
147 if remote: 146 if remote:
148 remote_addr, remote_port = remote.split(':') 147 remote_addr, remote_port = remote.split(':')
149 addr = remote_addr, int(remote_port) 148 addr = remote_addr, int(remote_port)
152 addr = None 151 addr = None
153 selected_player = 1 152 selected_player = 1
154 153
155 prng = Random(0) 154 prng = Random(0)
156 con = Network(port, addr, selected_player) 155 con = Network(port, addr, selected_player)
157 states = [PlayerState(0, character=1, power=default_power, continues=continues), 156 characters = [1, 3]
158 PlayerState(1, character=3, power=default_power, continues=continues)]
159 else: 157 else:
160 con = None 158 con = None
161 selected_player = 0 159 selected_player = 0
162 states = [PlayerState(0, character=character, power=default_power, continues=continues)] 160 characters = [character]
163 161
164 if hints: 162 if hints:
165 with open(hints, 'rb') as file: 163 with open(hints, 'rb') as file:
166 hints = Hint.read(file) 164 hints = Hint.read(file)
167 165
168 game_class = GameBossRush if boss_rush else Game 166 game_class = GameBossRush if boss_rush else Game
169 167
170 common = Common(resource_loader, states[selected_player]) 168 common = Common(resource_loader, characters, continues, stage_num - 1)
171 runner = GameRunner(window, resource_loader, skip=skip_replay, con=con) 169 runner = GameRunner(window, resource_loader, skip=skip_replay, con=con)
172 while True: 170 while True:
171 first_player = common.players[0]
172
173 if replay: 173 if replay:
174 level = replay.levels[stage_num - 1] 174 level = replay.levels[stage_num - 1]
175 if not level: 175 if not level:
176 raise Exception 176 raise Exception
177 177
179 179
180 #TODO: apply the replay to the other players. 180 #TODO: apply the replay to the other players.
181 #TODO: see if the stored score is used or if it’s the one from the previous stage. 181 #TODO: see if the stored score is used or if it’s the one from the previous stage.
182 if stage_num != 1 and stage_num - 2 in replay.levels: 182 if stage_num != 1 and stage_num - 2 in replay.levels:
183 previous_level = replay.levels[stage_num - 1] 183 previous_level = replay.levels[stage_num - 1]
184 states[0].score = previous_level.score 184 first_player.score = previous_level.score
185 states[0].effective_score = previous_level.score 185 first_player.effective_score = previous_level.score
186 states[0].points = level.point_items 186 first_player.points = level.point_items
187 states[0].power = level.power 187 first_player.power = level.power
188 states[0].lives = level.lives 188 first_player.lives = level.lives
189 states[0].bombs = level.bombs 189 first_player.bombs = level.bombs
190 difficulty = level.difficulty 190 difficulty = level.difficulty
191 elif port == 0: 191 elif port == 0:
192 prng = Random() 192 prng = Random()
193 193
194 if save_filename: 194 if save_filename:
195 if not replay: 195 if not replay:
196 save_replay.levels[stage_num - 1] = level = Level() 196 save_replay.levels[stage_num - 1] = level = Level()
197 level.score = states[0].score
198 level.random_seed = prng.seed 197 level.random_seed = prng.seed
199 level.point_items = states[0].points 198 level.score = first_player.score
200 level.power = states[0].power 199 level.point_items = first_player.points
201 level.lives = states[0].lives 200 level.power = first_player.power
202 level.bombs = states[0].bombs 201 level.lives = first_player.lives
202 level.bombs = first_player.bombs
203 level.difficulty = difficulty 203 level.difficulty = difficulty
204 save_keystates = [] 204 save_keystates = []
205 205
206 hints_stage = hints.stages[stage_num - 1] if hints else None 206 hints_stage = hints.stages[stage_num - 1] if hints else None
207 207
208 game = game_class(resource_loader, states, stage_num, rank, difficulty, 208 game = game_class(resource_loader, stage_num, rank, difficulty,
209 common, prng=prng, hints=hints_stage, 209 common, prng=prng, hints=hints_stage,
210 friendly_fire=friendly_fire) 210 friendly_fire=friendly_fire)
211 211
212 if not enable_particles: 212 if not enable_particles:
213 def new_particle(pos, anim, amp, number=1, reverse=False, duration=24): 213 def new_particle(pos, anim, amp, number=1, reverse=False, duration=24):
225 break 225 break
226 except NextStage: 226 except NextStage:
227 if not story or stage_num == (7 if boss_rush else 6 if rank > 0 else 5): 227 if not story or stage_num == (7 if boss_rush else 6 if rank > 0 else 5):
228 break 228 break
229 stage_num += 1 229 stage_num += 1
230 states = [player.state for player in game.players]
231 except GameOver: 230 except GameOver:
232 print('Game over') 231 print('Game over')
233 break 232 break
234 finally: 233 finally:
235 if save_filename: 234 if save_filename: