Mercurial > touhou
comparison pytouhou/game/enemy.pyx @ 509:292fea5c584e
Some more type optimisations.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 25 Nov 2013 19:12:56 +0100 |
parents | 507d446dc6cf |
children | db28538cd399 |
comparison
equal
deleted
inserted
replaced
508:1bc014f9d572 | 509:292fea5c584e |
---|---|
131 cpdef set_hitbox(self, double width, double height): | 131 cpdef set_hitbox(self, double width, double height): |
132 self.hitbox_half_size[:] = [width / 2, height / 2] | 132 self.hitbox_half_size[:] = [width / 2, height / 2] |
133 | 133 |
134 | 134 |
135 cpdef set_bullet_attributes(self, type_, anim, sprite_idx_offset, | 135 cpdef set_bullet_attributes(self, type_, anim, sprite_idx_offset, |
136 bullets_per_shot, number_of_shots, speed, speed2, | 136 unsigned long bullets_per_shot, |
137 launch_angle, angle, flags): | 137 unsigned long number_of_shots, double speed, |
138 double speed2, launch_angle, angle, flags): | |
139 cdef double speed_a, speed_b | |
140 cdef long nb_a, nb_b, shots_a, shots_b | |
138 | 141 |
139 # Apply difficulty-specific modifiers | 142 # Apply difficulty-specific modifiers |
140 speed_a, speed_b, nb_a, nb_b, shots_a, shots_b = self.difficulty_coeffs | 143 speed_a, speed_b, nb_a, nb_b, shots_a, shots_b = self.difficulty_coeffs |
141 diff_coeff = self._game.difficulty / 32. | 144 diff_coeff = self._game.difficulty / 32. |
142 | 145 |
143 speed += speed_a * (1. - diff_coeff) + speed_b * diff_coeff | 146 speed += speed_a * (1. - diff_coeff) + speed_b * diff_coeff |
144 speed2 += (speed_a * (1. - diff_coeff) + speed_b * diff_coeff) / 2. | 147 speed2 += (speed_a * (1. - diff_coeff) + speed_b * diff_coeff) / 2. |
145 bullets_per_shot += int(nb_a * (1. - diff_coeff) + nb_b * diff_coeff) | 148 bullets_per_shot += <long>(nb_a * (1. - diff_coeff) + nb_b * diff_coeff) |
146 number_of_shots += int(shots_a * (1. - diff_coeff) + shots_b * diff_coeff) | 149 number_of_shots += <long>(shots_a * (1. - diff_coeff) + shots_b * diff_coeff) |
147 | 150 |
148 self.bullet_attributes = (type_, anim, sprite_idx_offset, bullets_per_shot, | 151 self.bullet_attributes = (type_, anim, sprite_idx_offset, bullets_per_shot, |
149 number_of_shots, speed, speed2, launch_angle, | 152 number_of_shots, speed, speed2, launch_angle, |
150 angle, flags) | 153 angle, flags) |
151 if not self.delay_attack: | 154 if not self.delay_attack: |
153 | 156 |
154 | 157 |
155 cpdef set_bullet_launch_interval(self, long value, unsigned long start=0): | 158 cpdef set_bullet_launch_interval(self, long value, unsigned long start=0): |
156 # Apply difficulty-specific modifiers: | 159 # Apply difficulty-specific modifiers: |
157 #TODO: check every value possible! Look around 102h.exe@0x408720 | 160 #TODO: check every value possible! Look around 102h.exe@0x408720 |
158 value -= value * (<long>self._game.difficulty - 16) // 80 | 161 value -= value * (self._game.difficulty - 16) // 80 |
159 | 162 |
160 self.bullet_launch_interval = value | 163 self.bullet_launch_interval = value |
161 self.bullet_launch_timer = start % value if value > 0 else 0 | 164 self.bullet_launch_timer = start % value if value > 0 else 0 |
162 | 165 |
163 | 166 |
164 cpdef fire(self, offset=None, bullet_attributes=None, launch_pos=None): | 167 cpdef fire(self, offset=None, bullet_attributes=None, tuple launch_pos=None): |
168 cdef unsigned long type_, bullets_per_shot, number_of_shots | |
169 cdef double speed, speed2, launch_angle, angle | |
170 | |
165 (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots, | 171 (type_, type_idx, sprite_idx_offset, bullets_per_shot, number_of_shots, |
166 speed, speed2, launch_angle, angle, flags) = bullet_attributes or self.bullet_attributes | 172 speed, speed2, launch_angle, angle, flags) = bullet_attributes or self.bullet_attributes |
167 | 173 |
168 bullet_type = self._game.bullet_types[type_idx] | 174 bullet_type = self._game.bullet_types[type_idx] |
169 | 175 |
212 bullet_angle += 2. * pi / bullets_per_shot | 218 bullet_angle += 2. * pi / bullets_per_shot |
213 else: | 219 else: |
214 bullet_angle += angle | 220 bullet_angle += angle |
215 | 221 |
216 | 222 |
217 cpdef new_laser(self, variant, laser_type, sprite_idx_offset, angle, speed, | 223 cpdef new_laser(self, unsigned long variant, laser_type, sprite_idx_offset, |
218 start_offset, end_offset, max_length, width, | 224 double angle, speed, start_offset, end_offset, max_length, |
219 start_duration, duration, end_duration, | 225 width, start_duration, duration, end_duration, |
220 grazing_delay, grazing_extra_duration, unknown, | 226 grazing_delay, grazing_extra_duration, unknown, |
221 offset=None): | 227 tuple offset=None): |
222 ox, oy = offset or self.bullet_launch_offset | 228 cdef double ox, oy |
229 | |
230 if offset is None: | |
231 offset = self.bullet_launch_offset | |
232 ox, oy = offset | |
223 launch_pos = self.x + ox, self.y + oy | 233 launch_pos = self.x + ox, self.y + oy |
224 if variant == 86: | 234 if variant == 86: |
225 angle += self.get_player_angle(launch_pos) | 235 angle += self.get_player_angle(launch_pos) |
226 laser = Laser(launch_pos, self._game.laser_types[laser_type], | 236 laser = Laser(launch_pos, self._game.laser_types[laser_type], |
227 sprite_idx_offset, angle, speed, | 237 sprite_idx_offset, angle, speed, |
270 cpdef set_aux_anm(self, long number, long index): | 280 cpdef set_aux_anm(self, long number, long index): |
271 entry = 0 if index in self._anms[0].scripts else 1 | 281 entry = 0 if index in self._anms[0].scripts else 1 |
272 self.aux_anm[number] = Effect((self.x, self.y), index, self._anms[entry]) | 282 self.aux_anm[number] = Effect((self.x, self.y), index, self._anms[entry]) |
273 | 283 |
274 | 284 |
275 cpdef set_pos(self, x, y, z): | 285 cpdef set_pos(self, double x, double y, double z): |
276 self.x, self.y = x, y | 286 self.x, self.y = x, y |
277 self.update_mode = 1 | 287 self.update_mode = 1 |
278 self.interpolator = Interpolator((x, y), self._game.frame) | 288 self.interpolator = Interpolator((x, y), self._game.frame) |
279 | 289 |
280 | 290 |
281 cpdef move_to(self, duration, x, y, z, formula): | 291 cpdef move_to(self, unsigned long duration, double x, double y, double z, |
292 formula): | |
282 frame = self._game.frame | 293 frame = self._game.frame |
283 self.speed_interpolator = None | 294 self.speed_interpolator = None |
284 self.update_mode = 1 | 295 self.update_mode = 1 |
285 self.interpolator = Interpolator((self.x, self.y), frame, | 296 self.interpolator = Interpolator((self.x, self.y), frame, |
286 (x, y), frame + duration - 1, | 297 (x, y), frame + duration - 1, |
287 formula) | 298 formula) |
288 | 299 |
289 self.angle = atan2(y - self.y, x - self.x) | 300 self.angle = atan2(y - self.y, x - self.x) |
290 | 301 |
291 | 302 |
292 cpdef stop_in(self, duration, formula): | 303 cpdef stop_in(self, unsigned long duration, formula): |
293 frame = self._game.frame | 304 frame = self._game.frame |
294 self.interpolator = None | 305 self.interpolator = None |
295 self.update_mode = 1 | 306 self.update_mode = 1 |
296 self.speed_interpolator = Interpolator((self.speed,), frame, | 307 self.speed_interpolator = Interpolator((self.speed,), frame, |
297 (0.,), frame + duration - 1, | 308 (0.,), frame + duration - 1, |