comparison pytouhou/game/bullet.pyx @ 417:efae61ad6efe

Remove the type of the self argument in extension types, as it clutters the code with useless information.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 22 Aug 2013 12:21:12 +0200
parents b11953cf1d3b
children c9433188ffdb
comparison
equal deleted inserted replaced
416:e23871eddb7a 417:efae61ad6efe
90 self.sprite.angle = angle - pi 90 self.sprite.angle = angle - pi
91 else: 91 else:
92 self.sprite.angle = angle 92 self.sprite.angle = angle
93 93
94 94
95 cpdef is_visible(Bullet self, screen_width, screen_height): 95 cpdef is_visible(self, screen_width, screen_height):
96 tx, ty, tw, th = self.sprite.texcoords 96 tx, ty, tw, th = self.sprite.texcoords
97 x, y = self.x, self.y 97 x, y = self.x, self.y
98 98
99 max_x = tw / 2. 99 max_x = tw / 2.
100 max_y = th / 2. 100 max_y = th / 2.
105 or max_y < -y): 105 or max_y < -y):
106 return False 106 return False
107 return True 107 return True
108 108
109 109
110 def set_anim(Bullet self, sprite_idx_offset=None): 110 def set_anim(self, sprite_idx_offset=None):
111 if sprite_idx_offset is not None: 111 if sprite_idx_offset is not None:
112 self.sprite_idx_offset = sprite_idx_offset 112 self.sprite_idx_offset = sprite_idx_offset
113 113
114 bt = self._bullet_type 114 bt = self._bullet_type
115 self.sprite = Sprite() 115 self.sprite = Sprite()
120 self.anmrunner = ANMRunner(bt.anm_wrapper, bt.anim_index, 120 self.anmrunner = ANMRunner(bt.anm_wrapper, bt.anim_index,
121 self.sprite, self.sprite_idx_offset) 121 self.sprite, self.sprite_idx_offset)
122 self.anmrunner.run_frame() 122 self.anmrunner.run_frame()
123 123
124 124
125 def launch(Bullet self): 125 def launch(self):
126 self.state = LAUNCHED 126 self.state = LAUNCHED
127 self.frame = 0 127 self.frame = 0
128 self.set_anim() 128 self.set_anim()
129 self.dx, self.dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed 129 self.dx, self.dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
130 130
131 if self.flags & 1: 131 if self.flags & 1:
132 self.speed_interpolator = Interpolator((self.speed + 5.,), 0, 132 self.speed_interpolator = Interpolator((self.speed + 5.,), 0,
133 (self.speed,), 16) 133 (self.speed,), 16)
134 134
135 135
136 def collide(Bullet self): 136 def collide(self):
137 self.cancel() 137 self.cancel()
138 self._game.new_particle((self.x, self.y), 10, 256) #TODO: find the real size. 138 self._game.new_particle((self.x, self.y), 10, 256) #TODO: find the real size.
139 139
140 140
141 def cancel(Bullet self): 141 def cancel(self):
142 # Cancel animation 142 # Cancel animation
143 bt = self._bullet_type 143 bt = self._bullet_type
144 self.sprite = Sprite() 144 self.sprite = Sprite()
145 if self.player_bullet: 145 if self.player_bullet:
146 self.sprite.angle = self.angle - pi 146 self.sprite.angle = self.angle - pi
152 self.dx, self.dy = self.dx / 2., self.dy / 2. 152 self.dx, self.dy = self.dx / 2., self.dy / 2.
153 153
154 self.state = CANCELLED 154 self.state = CANCELLED
155 155
156 156
157 def update(Bullet self): 157 def update(self):
158 if self.anmrunner is not None and not self.anmrunner.run_frame(): 158 if self.anmrunner is not None and not self.anmrunner.run_frame():
159 if self.state == LAUNCHING: 159 if self.state == LAUNCHING:
160 #TODO: check if it doesn't skip a frame 160 #TODO: check if it doesn't skip a frame
161 self.launch() 161 self.launch()
162 elif self.state == CANCELLED: 162 elif self.state == CANCELLED: