Mercurial > touhou
comparison pytouhou/game/game.pyx @ 468:feecdb4a8928
Add “except *” to cdef void functions, and type some more.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 12 Sep 2013 15:47:08 +0200 |
parents | b16d34fca5b4 |
children | 06f0eeb519bb |
comparison
equal
deleted
inserted
replaced
467:5bb7d2c0ff46 | 468:feecdb4a8928 |
---|---|
73 self.next_bonus = self.prng.rand_uint16() % 8 | 73 self.next_bonus = self.prng.rand_uint16() % 8 |
74 | 74 |
75 self.last_keystate = 0 | 75 self.last_keystate = 0 |
76 | 76 |
77 | 77 |
78 def msg_sprites(self): | 78 cdef list msg_sprites(self): |
79 return [face for face in self.faces if face is not None] if self.msg_runner is not None and not self.msg_runner.ended else [] | 79 return [face for face in self.faces if face is not None] if self.msg_runner is not None and not self.msg_runner.ended else [] |
80 | 80 |
81 | 81 |
82 def lasers_sprites(self): | 82 cdef list lasers_sprites(self): |
83 return [laser for laser in self.players_lasers if laser is not None] | 83 return [laser for laser in self.players_lasers if laser is not None] |
84 | 84 |
85 | 85 |
86 cpdef modify_difficulty(self, long diff): | 86 cdef void modify_difficulty(self, long diff): |
87 self.difficulty_counter += diff | 87 self.difficulty_counter += diff |
88 while self.difficulty_counter < 0: | 88 while self.difficulty_counter < 0: |
89 self.difficulty -= 1 | 89 self.difficulty -= 1 |
90 self.difficulty_counter += 100 | 90 self.difficulty_counter += 100 |
91 while self.difficulty_counter >= 100: | 91 while self.difficulty_counter >= 100: |
95 self.difficulty = self.difficulty_min | 95 self.difficulty = self.difficulty_min |
96 elif self.difficulty > self.difficulty_max: | 96 elif self.difficulty > self.difficulty_max: |
97 self.difficulty = self.difficulty_max | 97 self.difficulty = self.difficulty_max |
98 | 98 |
99 | 99 |
100 def enable_spellcard_effect(self): | 100 cpdef enable_spellcard_effect(self): |
101 pos = (-32, -16) | 101 pos = (-32, -16) |
102 self.spellcard_effect = Effect(pos, 0, | 102 self.spellcard_effect = Effect(pos, 0, |
103 self.spellcard_effect_anm) | 103 self.spellcard_effect_anm) |
104 self.spellcard_effect.sprite.allow_dest_offset = True | 104 self.spellcard_effect.sprite.allow_dest_offset = True |
105 | 105 |
109 self.effects.append(face) | 109 self.effects.append(face) |
110 | 110 |
111 self.texts[5] = self.new_native_text((384-24, 24), self.spellcard[1], align='right') | 111 self.texts[5] = self.new_native_text((384-24, 24), self.spellcard[1], align='right') |
112 | 112 |
113 | 113 |
114 def disable_spellcard_effect(self): | 114 cpdef disable_spellcard_effect(self): |
115 self.spellcard_effect = None | 115 self.spellcard_effect = None |
116 self.texts[5] = None | 116 self.texts[5] = None |
117 | 117 |
118 | 118 |
119 def set_player_bomb(self): | 119 cdef void set_player_bomb(self): |
120 face = Effect((-32, -16), 1, self.msg_anm[0][0][0]) | 120 face = Effect((-32, -16), 1, self.msg_anm[0][0][0]) |
121 face.sprite.allow_dest_offset = True | 121 face.sprite.allow_dest_offset = True |
122 self.effects.append(face) | 122 self.effects.append(face) |
123 self.texts[4] = self.new_native_text((24, 24), u'Player Spellcard') | 123 self.texts[4] = self.new_native_text((24, 24), u'Player Spellcard') |
124 | 124 |
125 | 125 |
126 def unset_player_bomb(self): | 126 cdef void unset_player_bomb(self): |
127 self.texts[4] = None | 127 self.texts[4] = None |
128 | 128 |
129 | 129 |
130 cpdef drop_bonus(self, double x, double y, long _type, end_pos=None): | 130 cpdef drop_bonus(self, double x, double y, long _type, end_pos=None): |
131 if _type > 6: | 131 if _type > 6: |
141 | 141 |
142 for item in self.items: | 142 for item in self.items: |
143 item.autocollect(player) | 143 item.autocollect(player) |
144 | 144 |
145 | 145 |
146 cpdef cancel_bullets(self): | 146 cdef void cancel_bullets(self): |
147 cdef Bullet bullet | 147 cdef Bullet bullet |
148 #TODO: cdef Laser laser | 148 #TODO: cdef Laser laser |
149 | 149 |
150 for bullet in self.bullets: | 150 for bullet in self.bullets: |
151 bullet.cancel() | 151 bullet.cancel() |
152 for laser in self.lasers: | 152 for laser in self.lasers: |
153 laser.cancel() | 153 laser.cancel() |
154 | 154 |
155 | 155 |
156 def change_bullets_into_star_items(self): | 156 cpdef change_bullets_into_star_items(self): |
157 cdef Player player | 157 cdef Player player |
158 cdef Bullet bullet | 158 cdef Bullet bullet |
159 | 159 |
160 player = self.players[0] #TODO | 160 player = self.players[0] #TODO |
161 item_type = self.item_types[6] | 161 item_type = self.item_types[6] |
162 self.items.extend(Item((bullet.x, bullet.y), 6, item_type, self, player=player) | 162 self.items.extend([Item((bullet.x, bullet.y), 6, item_type, self, player=player) |
163 for bullet in self.bullets) | 163 for bullet in self.bullets]) |
164 for laser in self.lasers: | 164 for laser in self.lasers: |
165 self.items.extend(Item(pos, 6, item_type, self, player=player) | 165 self.items.extend([Item(pos, 6, item_type, self, player=player) |
166 for pos in laser.get_bullets_pos()) | 166 for pos in laser.get_bullets_pos()]) |
167 laser.cancel() | 167 laser.cancel() |
168 self.bullets = [] | 168 self.bullets = [] |
169 | 169 |
170 | 170 |
171 def change_bullets_into_bonus(self): | 171 cpdef change_bullets_into_bonus(self): |
172 cdef Player player | 172 cdef Player player |
173 cdef Bullet bullet | 173 cdef Bullet bullet |
174 | 174 |
175 player = self.players[0] #TODO | 175 player = self.players[0] #TODO |
176 score = 0 | 176 score = 0 |
182 self.bullets = [] | 182 self.bullets = [] |
183 player.state.score += score | 183 player.state.score += score |
184 #TODO: display the final bonus score. | 184 #TODO: display the final bonus score. |
185 | 185 |
186 | 186 |
187 def kill_enemies(self): | 187 cpdef kill_enemies(self): |
188 cdef Enemy enemy | 188 cdef Enemy enemy |
189 | 189 |
190 for enemy in self.enemies: | 190 for enemy in self.enemies: |
191 if enemy.boss: | 191 if enemy.boss: |
192 pass # Bosses are immune to 96 | 192 pass # Bosses are immune to 96 |
196 #TODO: check | 196 #TODO: check |
197 enemy.process.switch_to_sub(enemy.death_callback) | 197 enemy.process.switch_to_sub(enemy.death_callback) |
198 enemy.death_callback = -1 | 198 enemy.death_callback = -1 |
199 | 199 |
200 | 200 |
201 def new_effect(self, pos, long anim, anm=None, long number=1): | 201 cpdef new_effect(self, pos, long anim, anm=None, long number=1): |
202 number = min(number, self.nb_bullets_max - len(self.effects)) | 202 number = min(number, self.nb_bullets_max - len(self.effects)) |
203 for i in xrange(number): | 203 for i in xrange(number): |
204 self.effects.append(Effect(pos, anim, anm or self.etama[1])) | 204 self.effects.append(Effect(pos, anim, anm or self.etama[1])) |
205 | 205 |
206 | 206 |
208 number = min(number, self.nb_bullets_max - len(self.effects)) | 208 number = min(number, self.nb_bullets_max - len(self.effects)) |
209 for i in xrange(number): | 209 for i in xrange(number): |
210 self.effects.append(Particle(pos, anim, self.etama[1], amp, self, reverse=reverse, duration=duration)) | 210 self.effects.append(Particle(pos, anim, self.etama[1], amp, self, reverse=reverse, duration=duration)) |
211 | 211 |
212 | 212 |
213 def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): | 213 cpdef new_enemy(self, pos, life, instr_type, bonus_dropped, die_score): |
214 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm, self) | 214 enemy = Enemy(pos, life, instr_type, bonus_dropped, die_score, self.enm_anm, self) |
215 self.enemies.append(enemy) | 215 self.enemies.append(enemy) |
216 return enemy | 216 return enemy |
217 | 217 |
218 | 218 |
219 def new_msg(self, sub): | 219 cpdef new_msg(self, sub): |
220 self.msg_runner = MSGRunner(self.msg, sub, self) | 220 self.msg_runner = MSGRunner(self.msg, sub, self) |
221 self.msg_runner.run_iteration() | 221 self.msg_runner.run_iteration() |
222 | 222 |
223 | 223 |
224 cpdef new_label(self, pos, str text): | 224 cdef new_label(self, pos, str text): |
225 label = Text(pos, self.interface.ascii_anm, text=text, xspacing=8, shift=48) | 225 label = Text(pos, self.interface.ascii_anm, text=text, xspacing=8, shift=48) |
226 label.set_timeout(60, effect='move') | 226 label.set_timeout(60, effect='move') |
227 self.labels.append(label) | 227 self.labels.append(label) |
228 return label | 228 return label |
229 | 229 |
230 | 230 |
231 def new_native_text(self, pos, text, align='left'): | 231 cpdef new_native_text(self, pos, text, align='left'): |
232 label = NativeText(pos, text, shadow=True, align=align) | 232 label = NativeText(pos, text, shadow=True, align=align) |
233 return label | 233 return label |
234 | 234 |
235 | 235 |
236 def new_hint(self, hint): | 236 cpdef new_hint(self, hint): |
237 pos = hint['Pos'] | 237 pos = hint['Pos'] |
238 #TODO: Scale | 238 #TODO: Scale |
239 | 239 |
240 pos = pos[0] + 192, pos[1] | 240 pos = pos[0] + 192, pos[1] |
241 label = Text(pos, self.interface.ascii_anm, text=hint['Text'], align=hint['Align']) | 241 label = Text(pos, self.interface.ascii_anm, text=hint['Text'], align=hint['Align']) |
244 label.set_color(hint['Color'], text=False) | 244 label.set_color(hint['Color'], text=False) |
245 self.labels.append(label) | 245 self.labels.append(label) |
246 return label | 246 return label |
247 | 247 |
248 | 248 |
249 def new_face(self, side, effect): | 249 cpdef new_face(self, side, effect): |
250 face = Face(self.msg_anm, effect, side) | 250 face = Face(self.msg_anm, effect, side) |
251 self.faces[side] = face | 251 self.faces[side] = face |
252 return face | 252 return face |
253 | 253 |
254 | 254 |
255 def run_iter(self, long keystate): | 255 cpdef run_iter(self, long keystate): |
256 # 1. VMs. | 256 # 1. VMs. |
257 for runner in self.ecl_runners: | 257 for runner in self.ecl_runners: |
258 runner.run_iter() | 258 runner.run_iter() |
259 | 259 |
260 # 2. Modify difficulty | 260 # 2. Modify difficulty |
315 | 315 |
316 for enemy in self.enemies: | 316 for enemy in self.enemies: |
317 enemy.update() | 317 enemy.update() |
318 | 318 |
319 | 319 |
320 cdef void update_msg(self, long keystate) except *: | 320 cdef void update_msg(self, long keystate): |
321 cdef long k | 321 cdef long k |
322 | 322 |
323 for k in (1, 256): | 323 for k in (1, 256): |
324 if keystate & k and not self.last_keystate & k: | 324 if keystate & k and not self.last_keystate & k: |
325 self.msg_runner.skip() | 325 self.msg_runner.skip() |
327 self.msg_runner.skipping = bool(keystate & 256) | 327 self.msg_runner.skipping = bool(keystate & 256) |
328 self.last_keystate = keystate | 328 self.last_keystate = keystate |
329 self.msg_runner.run_iteration() | 329 self.msg_runner.run_iteration() |
330 | 330 |
331 | 331 |
332 cdef void update_players(self, long keystate) except *: | 332 cdef void update_players(self, long keystate): |
333 cdef Bullet bullet | 333 cdef Bullet bullet |
334 cdef Player player | 334 cdef Player player |
335 | 335 |
336 if self.time_stop: | 336 if self.time_stop: |
337 return | 337 return |
369 | 369 |
370 cdef void update_bullets(self): | 370 cdef void update_bullets(self): |
371 cdef Player player | 371 cdef Player player |
372 cdef Bullet bullet | 372 cdef Bullet bullet |
373 cdef Item item | 373 cdef Item item |
374 cdef double bhalf_width, bhalf_height | |
375 | 374 |
376 if self.time_stop: | 375 if self.time_stop: |
377 return | 376 return |
378 | 377 |
379 for bullet in self.cancelled_bullets: | 378 for bullet in self.cancelled_bullets: |
417 | 416 |
418 for bullet in self.bullets: | 417 for bullet in self.bullets: |
419 if bullet.state != LAUNCHED: | 418 if bullet.state != LAUNCHED: |
420 continue | 419 continue |
421 | 420 |
422 bhalf_width, bhalf_height = bullet.hitbox | 421 bhalf_width = bullet.hitbox[0] |
422 bhalf_height = bullet.hitbox[1] | |
423 bx, by = bullet.x, bullet.y | 423 bx, by = bullet.x, bullet.y |
424 bx1, bx2 = bx - bhalf_width, bx + bhalf_width | 424 bx1, bx2 = bx - bhalf_width, bx + bhalf_width |
425 by1, by2 = by - bhalf_height, by + bhalf_height | 425 by1, by2 = by - bhalf_height, by + bhalf_height |
426 | 426 |
427 if not (bx2 < px1 or bx1 > px2 | 427 if not (bx2 < px1 or bx1 > px2 |