comparison pytouhou/game/game.py @ 327:13201d90bb22

Display the text when collecting an item.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 21 Jun 2012 15:01:25 +0200
parents 61adb5453e46
children 56523a16db1d
comparison
equal deleted inserted replaced
326:efcdf2ce747c 327:13201d90bb22
19 19
20 from pytouhou.game.enemy import Enemy 20 from pytouhou.game.enemy import Enemy
21 from pytouhou.game.item import Item 21 from pytouhou.game.item import Item
22 from pytouhou.game.effect import Effect 22 from pytouhou.game.effect import Effect
23 from pytouhou.game.effect import Particle 23 from pytouhou.game.effect import Particle
24 from pytouhou.game.text import Text
24 25
25 26
26 27
27 class Game(object): 28 class Game(object):
28 def __init__(self, resource_loader, players, stage, rank, difficulty, 29 def __init__(self, resource_loader, players, stage, rank, difficulty,
44 self.lasers = [] 45 self.lasers = []
45 self.cancelled_bullets = [] 46 self.cancelled_bullets = []
46 self.players_bullets = [] 47 self.players_bullets = []
47 self.players_lasers = [None, None] 48 self.players_lasers = [None, None]
48 self.items = [] 49 self.items = []
50 self.labels = []
49 self.interface = interface 51 self.interface = interface
50 52
51 self.stage = stage 53 self.stage = stage
52 self.rank = rank 54 self.rank = rank
53 self.difficulty = difficulty 55 self.difficulty = difficulty
71 self.ecl_runner = ECLMainRunner(ecl, self) 73 self.ecl_runner = ECLMainRunner(ecl, self)
72 74
73 self.spellcard_effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,)) 75 self.spellcard_effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,))
74 self.spellcard_effect = None 76 self.spellcard_effect = None
75 77
78 #TODO: better place?
79 self.ascii_wrapper = resource_loader.get_anm_wrapper(('ascii.anm',))
80
76 # See 102h.exe@0x413220 if you think you're brave enough. 81 # See 102h.exe@0x413220 if you think you're brave enough.
77 self.deaths_count = self.prng.rand_uint16() % 3 82 self.deaths_count = self.prng.rand_uint16() % 3
78 self.next_bonus = self.prng.rand_uint16() % 8 83 self.next_bonus = self.prng.rand_uint16() % 8
79 84
80 self.last_keystate = 0 85 self.last_keystate = 0
152 def change_bullets_into_bonus(self): 157 def change_bullets_into_bonus(self):
153 player = self.players[0] #TODO 158 player = self.players[0] #TODO
154 score = 0 159 score = 0
155 bonus = 2000 160 bonus = 2000
156 for bullet in self.bullets: 161 for bullet in self.bullets:
157 #TODO: display the labels. 162 label = self.new_label((bullet.x, bullet.y), str(bonus))
158 score += bonus 163 score += bonus
159 bonus += 10 164 bonus += 10
160 self.bullets = [] 165 self.bullets = []
161 player.state.score += score 166 player.state.score += score
162 #TODO: display the final bonus score. 167 #TODO: display the final bonus score.
177 182
178 183
179 def new_msg(self, sub): 184 def new_msg(self, sub):
180 self.msg_runner = MSGRunner(self.msg, sub, self) 185 self.msg_runner = MSGRunner(self.msg, sub, self)
181 self.msg_runner.run_iteration() 186 self.msg_runner.run_iteration()
187
188
189 def new_label(self, pos, text):
190 label = Text(pos, self.ascii_wrapper, text=text, xspacing=8, shift=48)
191 label.set_timeout(60)
192 self.labels.append(label)
193 return label
182 194
183 195
184 def run_iter(self, keystate): 196 def run_iter(self, keystate):
185 # 1. VMs. 197 # 1. VMs.
186 self.ecl_runner.run_iter() 198 self.ecl_runner.run_iter()
211 self.update_effects() # Pri 10 223 self.update_effects() # Pri 10
212 self.update_bullets() # Pri 11 224 self.update_bullets() # Pri 11
213 for laser in self.lasers: #TODO: what priority is it? 225 for laser in self.lasers: #TODO: what priority is it?
214 laser.update() 226 laser.update()
215 self.interface.update() # Pri 12 227 self.interface.update() # Pri 12
228 for label in self.labels: #TODO: what priority is it?
229 label.update()
216 230
217 # 5. Clean up 231 # 5. Clean up
218 self.cleanup() 232 self.cleanup()
219 233
220 self.frame += 1 234 self.frame += 1
379 items.append(item) 393 items.append(item)
380 else: 394 else:
381 self.modify_difficulty(-3) 395 self.modify_difficulty(-3)
382 self.items = items 396 self.items = items
383 397
398 self.labels = [label for label in self.labels if not label.removed]
399
384 # Disable boss mode if it is dead/it has timeout 400 # Disable boss mode if it is dead/it has timeout
385 if self.boss and self.boss._enemy.removed: 401 if self.boss and self.boss._enemy.removed:
386 self.boss = None 402 self.boss = None
387 403