changeset 448:3bc37791f0a2

Make Bullet.state an enum.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 17 Aug 2013 17:44:11 +0200
parents 78e1c3864e73
children d56536ef28e8
files pytouhou/game/bullet.pxd pytouhou/game/bullet.pyx pytouhou/game/enemy.pyx pytouhou/game/game.pyx
diffstat 4 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/bullet.pxd
+++ b/pytouhou/game/bullet.pxd
@@ -2,8 +2,14 @@ from pytouhou.game.element cimport Eleme
 from pytouhou.game.game cimport Game
 from pytouhou.utils.interpolator cimport Interpolator
 
+
+cdef enum State:
+    LAUNCHING, LAUNCHED, CANCELLED
+
+
 cdef class Bullet(Element):
-    cdef public unsigned long state, flags, frame, sprite_idx_offset, damage
+    cdef public State state
+    cdef public unsigned long flags, frame, sprite_idx_offset, damage
     cdef public double dx, dy, angle, speed
     cdef public bint player_bullet, was_visible, grazed
     cdef public object target, _bullet_type
--- a/pytouhou/game/bullet.pyx
+++ b/pytouhou/game/bullet.pyx
@@ -18,8 +18,6 @@ from pytouhou.vm.anmrunner import ANMRun
 from pytouhou.game.sprite cimport Sprite
 
 
-LAUNCHING, LAUNCHED, CANCELLED = range(3)
-
 cdef class Bullet(Element):
     def __init__(self, pos, bullet_type, unsigned long sprite_idx_offset,
                        double angle, double speed, attributes, unsigned long flags, target, Game game,
--- a/pytouhou/game/enemy.pyx
+++ b/pytouhou/game/enemy.pyx
@@ -16,7 +16,7 @@ from libc.math cimport cos, sin, atan2, 
 
 from pytouhou.vm.anmrunner import ANMRunner
 from pytouhou.game.sprite import Sprite
-from pytouhou.game.bullet import Bullet, LAUNCHED
+from pytouhou.game.bullet cimport Bullet, LAUNCHED
 from pytouhou.game.laser import Laser
 from pytouhou.game.effect cimport Effect
 
--- a/pytouhou/game/game.pyx
+++ b/pytouhou/game/game.pyx
@@ -15,8 +15,7 @@
 from pytouhou.vm.msgrunner import MSGRunner
 
 from pytouhou.game.element cimport Element
-from pytouhou.game.bullet cimport Bullet
-from pytouhou.game.bullet import LAUNCHED, CANCELLED
+from pytouhou.game.bullet cimport Bullet, LAUNCHED, CANCELLED
 from pytouhou.game.enemy cimport Enemy
 from pytouhou.game.item cimport Item
 from pytouhou.game.effect cimport Particle
@@ -291,8 +290,10 @@ cdef class Game:
     cdef void update_msg(self, long keystate) except *:
         cdef long k
 
-        if any([(keystate & k and not self.last_keystate & k) for k in (1, 256)]):
-            self.msg_runner.skip()
+        for k in (1, 256):
+            if keystate & k and not self.last_keystate & k:
+                self.msg_runner.skip()
+                break
         self.msg_runner.skipping = bool(keystate & 256)
         self.last_keystate = keystate
         self.msg_runner.run_iteration()