Mercurial > touhou
comparison pytouhou/game/game.py @ 404:6c0cb3eee33e
Add MoF’s hints support, and fix the Text timeout interface.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 24 Mar 2013 10:29:37 +0100 |
parents | 9589a01e6edf |
children | 608468be7a93 |
comparison
equal
deleted
inserted
replaced
403:9589a01e6edf | 404:6c0cb3eee33e |
---|---|
32 | 32 |
33 class Game(object): | 33 class Game(object): |
34 def __init__(self, resource_loader, players, stage, rank, difficulty, | 34 def __init__(self, resource_loader, players, stage, rank, difficulty, |
35 bullet_types, laser_types, item_types, | 35 bullet_types, laser_types, item_types, |
36 nb_bullets_max=None, width=384, height=448, prng=None, | 36 nb_bullets_max=None, width=384, height=448, prng=None, |
37 interface=None, continues=0): | 37 interface=None, continues=0, hints=None): |
38 self.resource_loader = resource_loader | 38 self.resource_loader = resource_loader |
39 | 39 |
40 self.width, self.height = width, height | 40 self.width, self.height = width, height |
41 | 41 |
42 self.nb_bullets_max = nb_bullets_max | 42 self.nb_bullets_max = nb_bullets_max |
54 self.players_lasers = [None, None] | 54 self.players_lasers = [None, None] |
55 self.items = [] | 55 self.items = [] |
56 self.labels = [] | 56 self.labels = [] |
57 self.faces = [None, None] | 57 self.faces = [None, None] |
58 self.interface = interface | 58 self.interface = interface |
59 self.hints = hints | |
59 | 60 |
60 self.continues = continues | 61 self.continues = continues |
61 self.stage = stage | 62 self.stage = stage |
62 self.rank = rank | 63 self.rank = rank |
63 self.difficulty = difficulty | 64 self.difficulty = difficulty |
164 def change_bullets_into_bonus(self): | 165 def change_bullets_into_bonus(self): |
165 player = self.players[0] #TODO | 166 player = self.players[0] #TODO |
166 score = 0 | 167 score = 0 |
167 bonus = 2000 | 168 bonus = 2000 |
168 for bullet in self.bullets: | 169 for bullet in self.bullets: |
169 label = self.new_label((bullet.x, bullet.y), str(bonus)) | 170 self.new_label((bullet.x, bullet.y), str(bonus)) |
170 score += bonus | 171 score += bonus |
171 bonus += 10 | 172 bonus += 10 |
172 self.bullets = [] | 173 self.bullets = [] |
173 player.state.score += score | 174 player.state.score += score |
174 #TODO: display the final bonus score. | 175 #TODO: display the final bonus score. |
209 self.msg_runner.run_iteration() | 210 self.msg_runner.run_iteration() |
210 | 211 |
211 | 212 |
212 def new_label(self, pos, text): | 213 def new_label(self, pos, text): |
213 label = Text(pos, self.ascii_wrapper, text=text, xspacing=8, shift=48) | 214 label = Text(pos, self.ascii_wrapper, text=text, xspacing=8, shift=48) |
214 label.set_timeout(60) | 215 label.set_timeout(60, effect='move') |
216 self.labels.append(label) | |
217 return label | |
218 | |
219 | |
220 def new_hint(self, hint): | |
221 pos = hint['Pos'] | |
222 #TODO: Scale | |
223 | |
224 pos = pos[0] + 192, pos[1] | |
225 label = Text(pos, self.ascii_wrapper, text=hint['Text'], align=hint['Align']) | |
226 label.set_timeout(hint['Time']) | |
227 label.set_alpha(hint['Alpha']) | |
228 label.set_color(hint['Color'], text=False) | |
215 self.labels.append(label) | 229 self.labels.append(label) |
216 return label | 230 return label |
217 | 231 |
218 | 232 |
219 def new_face(self, side, effect): | 233 def new_face(self, side, effect): |
253 self.update_effects() # Pri 10 | 267 self.update_effects() # Pri 10 |
254 self.update_bullets() # Pri 11 | 268 self.update_bullets() # Pri 11 |
255 for laser in self.lasers: #TODO: what priority is it? | 269 for laser in self.lasers: #TODO: what priority is it? |
256 laser.update() | 270 laser.update() |
257 self.interface.update() # Pri 12 | 271 self.interface.update() # Pri 12 |
272 if self.hints: | |
273 self.update_hints() # Not from this game, so unknown. | |
258 for label in self.labels: #TODO: what priority is it? | 274 for label in self.labels: #TODO: what priority is it? |
259 label.update() | 275 label.update() |
260 self.update_faces() # Pri XXX | 276 self.update_faces() # Pri XXX |
261 | 277 |
262 # 5. Clean up | 278 # 5. Clean up |
303 | 319 |
304 | 320 |
305 def update_effects(self): | 321 def update_effects(self): |
306 for effect in self.effects: | 322 for effect in self.effects: |
307 effect.update() | 323 effect.update() |
324 | |
325 | |
326 def update_hints(self): | |
327 for hint in self.hints: | |
328 if hint['Count'] == self.frame and hint['Base'] == 'start': | |
329 self.new_hint(hint) | |
308 | 330 |
309 | 331 |
310 def update_faces(self): | 332 def update_faces(self): |
311 for face in self.faces: | 333 for face in self.faces: |
312 if face: | 334 if face: |