comparison pytouhou/game/game.py @ 286:4838e9bab0f9

Implement dialogs (MSG files).
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 12 Feb 2012 16:06:03 +0100
parents f037bca24f2d
children 18e4ed141dd8
comparison
equal deleted inserted replaced
285:2100276c289d 286:4838e9bab0f9
15 from itertools import chain 15 from itertools import chain
16 16
17 from pytouhou.utils.random import Random 17 from pytouhou.utils.random import Random
18 18
19 from pytouhou.vm.eclrunner import ECLMainRunner 19 from pytouhou.vm.eclrunner import ECLMainRunner
20 from pytouhou.vm.msgrunner import MSGRunner
20 21
21 from pytouhou.game.enemy import Enemy 22 from pytouhou.game.enemy import Enemy
22 from pytouhou.game.item import Item 23 from pytouhou.game.item import Item
23 from pytouhou.game.effect import Effect 24 from pytouhou.game.effect import Effect
24 from pytouhou.game.effect import Particle 25 from pytouhou.game.effect import Particle
53 self.difficulty_counter = 0 54 self.difficulty_counter = 0
54 self.difficulty_min = 12 if rank == 0 else 10 55 self.difficulty_min = 12 if rank == 0 else 10
55 self.difficulty_max = 20 if rank == 0 else 32 56 self.difficulty_max = 20 if rank == 0 else 32
56 self.boss = None 57 self.boss = None
57 self.spellcard = None 58 self.spellcard = None
59 self.msg_runner = None
60 self.msg_wait = False
58 self.bonus_list = [0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 61 self.bonus_list = [0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0,
59 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 2] 62 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 2]
60 self.prng = prng or Random() 63 self.prng = prng or Random()
61 self.frame = 0 64 self.frame = 0
62 65
70 self.effect = None 73 self.effect = None
71 74
72 # See 102h.exe@0x413220 if you think you're brave enough. 75 # See 102h.exe@0x413220 if you think you're brave enough.
73 self.deaths_count = self.prng.rand_uint16() % 3 76 self.deaths_count = self.prng.rand_uint16() % 3
74 self.next_bonus = self.prng.rand_uint16() % 8 77 self.next_bonus = self.prng.rand_uint16() % 8
78
79 self.last_keystate = 0
80
81
82 def msg_sprites(self):
83 return []
75 84
76 85
77 def modify_difficulty(self, diff): 86 def modify_difficulty(self, diff):
78 self.difficulty_counter += diff 87 self.difficulty_counter += diff
79 while self.difficulty_counter < 0: 88 while self.difficulty_counter < 0:
136 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self) 145 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm_wrapper, self)
137 self.enemies.append(enemy) 146 self.enemies.append(enemy)
138 return enemy 147 return enemy
139 148
140 149
150 def new_msg(self, sub):
151 self.msg_runner = MSGRunner(self.msg, sub, self)
152 self.msg_runner.run_iteration()
153
154
141 def run_iter(self, keystate): 155 def run_iter(self, keystate):
142 # 1. VMs. 156 # 1. VMs.
143 self.ecl_runner.run_iter() 157 self.ecl_runner.run_iter()
144 if self.frame % (32*60) == (32*60): #TODO: check if that is really that frame. 158 if self.frame % (32*60) == (32*60): #TODO: check if that is really that frame.
145 self.modify_difficulty(+100) 159 self.modify_difficulty(+100)
156 # In the original game, updates are done in prioritized functions called "chains" 170 # In the original game, updates are done in prioritized functions called "chains"
157 # We have to mimic this functionnality to be replay-compatible with the official game. 171 # We have to mimic this functionnality to be replay-compatible with the official game.
158 172
159 # Pri 6 is background 173 # Pri 6 is background
160 self.update_effect() #TODO: Pri unknown 174 self.update_effect() #TODO: Pri unknown
175 if self.msg_runner:
176 self.update_msg(keystate) # Pri ?
177 keystate &= ~3 # Remove the ability to attack (keystates 1 and 2).
161 self.update_players(keystate) # Pri 7 178 self.update_players(keystate) # Pri 7
162 self.update_enemies() # Pri 9 179 self.update_enemies() # Pri 9
163 self.update_effects() # Pri 10 180 self.update_effects() # Pri 10
164 self.update_bullets() # Pri 11 181 self.update_bullets() # Pri 11
165 for laser in self.lasers: #TODO: what priority is it? 182 for laser in self.lasers: #TODO: what priority is it?
178 195
179 196
180 def update_enemies(self): 197 def update_enemies(self):
181 for enemy in self.enemies: 198 for enemy in self.enemies:
182 enemy.update() 199 enemy.update()
200
201
202 def update_msg(self, keystate):
203 if keystate & 1 and not self.last_keystate & 1:
204 self.msg_runner.skip()
205 if keystate & 256 and self.msg_runner.allow_skip:
206 self.msg_runner.skip()
207 self.last_keystate = keystate
208 self.msg_runner.run_iteration()
183 209
184 210
185 def update_players(self, keystate): 211 def update_players(self, keystate):
186 for player in self.players: 212 for player in self.players:
187 player.update(keystate) #TODO: differentiate keystates (multiplayer mode) 213 player.update(keystate) #TODO: differentiate keystates (multiplayer mode)
293 else: 319 else:
294 self.modify_difficulty(-3) 320 self.modify_difficulty(-3)
295 self.items = items 321 self.items = items
296 322
297 # Disable boss mode if it is dead/it has timeout 323 # Disable boss mode if it is dead/it has timeout
298 if self.boss and self.boss._removed: 324 if self.boss and self.boss._enemy._removed:
299 self.boss = None 325 self.boss = None
300 326