comparison pytouhou/game/bullet.pyx @ 260:e22e0d73f614

Implement bullet flags 1024 and 2048 (bouncing bullet).
author Thibaut Girka <thib@sitedethib.com>
date Sun, 22 Jan 2012 22:38:58 +0100
parents 620134bc51f4
children 35644a67ba4c
comparison
equal deleted inserted replaced
259:3631abb6e95b 260:e22e0d73f614
231 (0.,), self.frame + frame - 1) 231 (0.,), self.frame + frame - 1)
232 else: 232 else:
233 self.flags &= ~448 233 self.flags &= ~448
234 234
235 self.attributes[1] = count 235 self.attributes[1] = count
236 #TODO: other flags
237 236
238 # Common updates 237 # Common updates
239 238
240 if self.speed_interpolator: 239 if self.speed_interpolator:
241 self.speed_interpolator.update(self.frame) 240 self.speed_interpolator.update(self.frame)
247 self.y += self.dy 246 self.y += self.dy
248 247
249 self.frame += 1 248 self.frame += 1
250 249
251 # Filter out-of-screen bullets and handle special flags 250 # Filter out-of-screen bullets and handle special flags
252 #TODO: flags 1024 and 2048
253 if self.flags & 448: 251 if self.flags & 448:
254 self._was_visible = False 252 self._was_visible = False
255 elif self.is_visible(self._game.width, self._game.height): 253 elif self.is_visible(self._game.width, self._game.height):
256 self._was_visible = True 254 self._was_visible = True
257 elif self._was_visible: 255 elif self._was_visible:
258 # Filter out-of-screen bullets
259 self._removed = True 256 self._removed = True
260 257 if self.flags & (1024 | 2048) and self.attributes[0] > 0:
258 # Bounce!
259 if self.x < 0 or self.x > self._game.width:
260 self.angle = pi - self.angle
261 self._removed = False
262 if self.y < 0 or ((self.flags & 1024) and self.y > self._game.height):
263 self.angle = -self.angle
264 self._removed = False
265 self.dx = cos(self.angle) * self.speed
266 self.dy = sin(self.angle) * self.speed
267 self.attributes[0] -= 1
268