Mercurial > touhou
comparison pytouhou/game/game.pyx @ 471:06f0eeb519bb
Make Laser and Orb extension types, and use that where possible.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 16 Sep 2013 18:42:04 +0200 |
parents | feecdb4a8928 |
children | 1c891c71cf22 |
comparison
equal
deleted
inserted
replaced
470:98995d8ac744 | 471:06f0eeb519bb |
---|---|
17 from pytouhou.game.element cimport Element | 17 from pytouhou.game.element cimport Element |
18 from pytouhou.game.bullet cimport Bullet, LAUNCHED, CANCELLED | 18 from pytouhou.game.bullet cimport Bullet, LAUNCHED, CANCELLED |
19 from pytouhou.game.enemy cimport Enemy | 19 from pytouhou.game.enemy cimport Enemy |
20 from pytouhou.game.item cimport Item | 20 from pytouhou.game.item cimport Item |
21 from pytouhou.game.effect cimport Particle | 21 from pytouhou.game.effect cimport Particle |
22 from pytouhou.game.laser cimport Laser, PlayerLaser | |
22 from pytouhou.game.text import Text, NativeText | 23 from pytouhou.game.text import Text, NativeText |
23 from pytouhou.game.face import Face | 24 from pytouhou.game.face import Face |
24 | 25 |
25 | 26 |
26 cdef class Game: | 27 cdef class Game: |
143 item.autocollect(player) | 144 item.autocollect(player) |
144 | 145 |
145 | 146 |
146 cdef void cancel_bullets(self): | 147 cdef void cancel_bullets(self): |
147 cdef Bullet bullet | 148 cdef Bullet bullet |
148 #TODO: cdef Laser laser | 149 cdef Laser laser |
149 | 150 |
150 for bullet in self.bullets: | 151 for bullet in self.bullets: |
151 bullet.cancel() | 152 bullet.cancel() |
152 for laser in self.lasers: | 153 for laser in self.lasers: |
153 laser.cancel() | 154 laser.cancel() |
154 | 155 |
156 cdef void cancel_player_lasers(self): | |
157 cdef PlayerLaser laser | |
158 for laser in self.players_lasers: | |
159 if laser is not None: | |
160 laser.cancel() | |
161 | |
155 | 162 |
156 cpdef change_bullets_into_star_items(self): | 163 cpdef change_bullets_into_star_items(self): |
157 cdef Player player | 164 cdef Player player |
158 cdef Bullet bullet | 165 cdef Bullet bullet |
166 cdef Laser laser | |
159 | 167 |
160 player = self.players[0] #TODO | 168 player = self.players[0] #TODO |
161 item_type = self.item_types[6] | 169 item_type = self.item_types[6] |
162 self.items.extend([Item((bullet.x, bullet.y), 6, item_type, self, player=player) | 170 self.items.extend([Item((bullet.x, bullet.y), 6, item_type, self, player=player) |
163 for bullet in self.bullets]) | 171 for bullet in self.bullets]) |
251 self.faces[side] = face | 259 self.faces[side] = face |
252 return face | 260 return face |
253 | 261 |
254 | 262 |
255 cpdef run_iter(self, long keystate): | 263 cpdef run_iter(self, long keystate): |
264 cdef Laser laser | |
256 # 1. VMs. | 265 # 1. VMs. |
257 for runner in self.ecl_runners: | 266 for runner in self.ecl_runners: |
258 runner.run_iter() | 267 runner.run_iter() |
259 | 268 |
260 # 2. Modify difficulty | 269 # 2. Modify difficulty |
369 | 378 |
370 cdef void update_bullets(self): | 379 cdef void update_bullets(self): |
371 cdef Player player | 380 cdef Player player |
372 cdef Bullet bullet | 381 cdef Bullet bullet |
373 cdef Item item | 382 cdef Item item |
383 cdef PlayerLaser player_laser | |
384 cdef Laser laser | |
385 cdef double player_pos[2] | |
374 | 386 |
375 if self.time_stop: | 387 if self.time_stop: |
376 return | 388 return |
377 | 389 |
378 for bullet in self.cancelled_bullets: | 390 for bullet in self.cancelled_bullets: |
379 bullet.update() | 391 bullet.update() |
380 | 392 |
381 for bullet in self.bullets: | 393 for bullet in self.bullets: |
382 bullet.update() | 394 bullet.update() |
383 | 395 |
384 for laser in self.players_lasers: | 396 for player_laser in self.players_lasers: |
385 if laser is not None: | 397 if player_laser is not None: |
386 laser.update() | 398 player_laser.update() |
387 | 399 |
388 for item in self.items: | 400 for item in self.items: |
389 item.update() | 401 item.update() |
390 | 402 |
391 for player in self.players: | 403 for player in self.players: |
393 | 405 |
394 if not player_state.touchable: | 406 if not player_state.touchable: |
395 continue | 407 continue |
396 | 408 |
397 px, py = player_state.x, player_state.y | 409 px, py = player_state.x, player_state.y |
410 player_pos[:] = [px, py] | |
398 phalf_size = <double>player.sht.hitbox | 411 phalf_size = <double>player.sht.hitbox |
399 px1, px2 = px - phalf_size, px + phalf_size | 412 px1, px2 = px - phalf_size, px + phalf_size |
400 py1, py2 = py - phalf_size, py + phalf_size | 413 py1, py2 = py - phalf_size, py + phalf_size |
401 | 414 |
402 ghalf_size = <double>player.sht.graze_hitbox | 415 ghalf_size = <double>player.sht.graze_hitbox |
403 gx1, gx2 = px - ghalf_size, px + ghalf_size | 416 gx1, gx2 = px - ghalf_size, px + ghalf_size |
404 gy1, gy2 = py - ghalf_size, py + ghalf_size | 417 gy1, gy2 = py - ghalf_size, py + ghalf_size |
405 | 418 |
406 for laser in self.lasers: | 419 for laser in self.lasers: |
407 if laser.check_collision((px, py)): | 420 if laser.check_collision(player_pos): |
408 if player_state.invulnerable_time == 0: | 421 if player_state.invulnerable_time == 0: |
409 player.collide() | 422 player.collide() |
410 elif laser.check_grazing((px, py)): | 423 elif laser.check_grazing(player_pos): |
411 player_state.graze += 1 #TODO | 424 player_state.graze += 1 #TODO |
412 player_state.score += 500 #TODO | 425 player_state.score += 500 #TODO |
413 player.play_sound('graze') | 426 player.play_sound('graze') |
414 self.modify_difficulty(+6) #TODO | 427 self.modify_difficulty(+6) #TODO |
415 self.new_particle((px, py), 9, 192) #TODO | 428 self.new_particle((px, py), 9, 192) #TODO |
458 | 471 |
459 cpdef cleanup(self): | 472 cpdef cleanup(self): |
460 cdef Enemy enemy | 473 cdef Enemy enemy |
461 cdef Bullet bullet | 474 cdef Bullet bullet |
462 cdef Item item | 475 cdef Item item |
476 cdef PlayerLaser laser | |
463 cdef long i | 477 cdef long i |
464 | 478 |
465 # Filter out non-visible enemies | 479 # Filter out non-visible enemies |
466 for enemy in self.enemies: | 480 for enemy in self.enemies: |
467 if enemy.is_visible(self.width, self.height): | 481 if enemy.is_visible(self.width, self.height): |