comparison demos/shooter/scripts/weapons.py @ 645:291ba2946c73

* Added the ability to normalize a 2D and 3D point. * You can now rotate a 2D point around the origin or a specific point. * Modified the shooter demo to use the new point functionality. * Removed the fife_math extension.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 12 Oct 2010 18:58:47 +0000
parents 5e6ff32a46fb
children
comparison
equal deleted inserted replaced
644:b84dbc4665b0 645:291ba2946c73
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # #################################################################### 22 # ####################################################################
23 23
24 from fife import fife 24 from fife import fife
25 from scripts.common.baseobject import * 25 from scripts.common.baseobject import *
26 from fife.extensions.fife_math import normalize, rotatePoint
27 26
28 class Projectile(SpaceObject): 27 class Projectile(SpaceObject):
29 """ 28 """
30 Represents a projectile (or bullet or fireball) in the scene. 29 Represents a projectile (or bullet or fireball) in the scene.
31 30
169 self._projectileVelocity = 0.75 168 self._projectileVelocity = 0.75
170 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/cannon.ogg") 169 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/cannon.ogg")
171 170
172 171
173 def fire(self, direction): 172 def fire(self, direction):
174 velocity = normalize(direction) 173 velocity = fife.DoublePoint(direction)
174 velocity.normalize()
175 velocity.x = velocity.x * self._projectileVelocity 175 velocity.x = velocity.x * self._projectileVelocity
176 velocity.y = velocity.y * self._projectileVelocity 176 velocity.y = velocity.y * self._projectileVelocity
177 177
178 if (self._scene.time - self._lastfired) > self._firerate: 178 if (self._scene.time - self._lastfired) > self._firerate:
179 pjctl = Projectile(self._scene, self._ship, "bullet1", 3000 ) 179 pjctl = Projectile(self._scene, self._ship, "bullet1", 3000 )
191 191
192 self._projectileVelocity = 0.50 192 self._projectileVelocity = 0.50
193 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/fireball.ogg") 193 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/fireball.ogg")
194 194
195 def fire(self, direction): 195 def fire(self, direction):
196 velocity = normalize(direction) 196 velocity = fife.DoublePoint(direction)
197 velocity.normalize()
197 velocity.x = velocity.x * self._projectileVelocity 198 velocity.x = velocity.x * self._projectileVelocity
198 velocity.y = velocity.y * self._projectileVelocity 199 velocity.y = velocity.y * self._projectileVelocity
199 200
200 if (self._scene.time - self._lastfired) > self._firerate: 201 if (self._scene.time - self._lastfired) > self._firerate:
201 pjctl = Projectile(self._scene, self._ship, "fireball", 6000 ) 202 pjctl = Projectile(self._scene, self._ship, "fireball", 6000 )
218 219
219 self._lastburstfired = 0 220 self._lastburstfired = 0
220 221
221 222
222 def fire(self, direction): 223 def fire(self, direction):
223 velocity = normalize(direction) 224 velocity = fife.DoublePoint(direction)
225 velocity.normalize()
224 velocity.x = velocity.x * self._projectileVelocity 226 velocity.x = velocity.x * self._projectileVelocity
225 velocity.y = velocity.y * self._projectileVelocity 227 velocity.y = velocity.y * self._projectileVelocity
226 228
227 if (self._scene.time - self._lastfired) > self._firerate: 229 if (self._scene.time - self._lastfired) > self._firerate:
228 if (self._scene.time - self._lastburstfired) > self._burstrate and self._burstcount > 0: 230 if (self._scene.time - self._lastburstfired) > self._burstrate and self._burstcount > 0:
250 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/fireball.ogg") 252 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/fireball.ogg")
251 253
252 def fire(self, direction): 254 def fire(self, direction):
253 255
254 if (self._scene.time - self._lastfired) > self._firerate: 256 if (self._scene.time - self._lastfired) > self._firerate:
255 velocity = normalize(direction) 257 velocity = fife.DoublePoint(direction)
258 velocity.normalize()
256 velocity.x = velocity.x * self._projectileVelocity 259 velocity.x = velocity.x * self._projectileVelocity
257 velocity.y = velocity.y * self._projectileVelocity 260 velocity.y = velocity.y * self._projectileVelocity
258 261
259 origin = fife.DoublePoint(0,0) 262 origin = fife.DoublePoint(0,0)
260 263
261 p1 = rotatePoint(origin, velocity, -30) 264 p1 = fife.DoublePoint(velocity)
262 p2 = rotatePoint(origin, velocity, -20) 265 p2 = fife.DoublePoint(velocity)
263 p3 = rotatePoint(origin, velocity, -10) 266 p3 = fife.DoublePoint(velocity)
264 p4 = rotatePoint(origin, velocity, 0) 267 p4 = fife.DoublePoint(velocity)
265 p5 = rotatePoint(origin, velocity, 10) 268 p5 = fife.DoublePoint(velocity)
266 p6 = rotatePoint(origin, velocity, 20) 269 p6 = fife.DoublePoint(velocity)
267 p7 = rotatePoint(origin, velocity, 30) 270 p7 = fife.DoublePoint(velocity)
271
272 p1.rotate(origin, -30)
273 p2.rotate(origin, -20)
274 p3.rotate(origin, -10)
275 p4.rotate(origin, 0)
276 p5.rotate(origin, 10)
277 p6.rotate(origin, 20)
278 p7.rotate(origin, 30)
268 279
269 pjctl1 = Projectile(self._scene, self._ship, "fireball", 6000 ) 280 pjctl1 = Projectile(self._scene, self._ship, "fireball", 6000 )
270 pjctl1.run(p1, self._ship.location) 281 pjctl1.run(p1, self._ship.location)
271 self._scene.addObjectToScene(pjctl1) 282 self._scene.addObjectToScene(pjctl1)
272 283
307 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/cannon.ogg") 318 self._soundclip = scene.soundmanager.createSoundEmitter("sounds/cannon.ogg")
308 319
309 def fire(self, direction): 320 def fire(self, direction):
310 321
311 if (self._scene.time - self._lastfired) > self._firerate: 322 if (self._scene.time - self._lastfired) > self._firerate:
312 velocity = normalize(direction) 323 velocity = fife.DoublePoint(direction)
324 velocity.normalize()
313 velocity.x = velocity.x * self._projectileVelocity 325 velocity.x = velocity.x * self._projectileVelocity
314 velocity.y = velocity.y * self._projectileVelocity 326 velocity.y = velocity.y * self._projectileVelocity
315 327
316 origin = fife.DoublePoint(0,0) 328 origin = fife.DoublePoint(0,0)
317 329
318 p2 = rotatePoint(origin, velocity, -10) 330 p2 = fife.DoublePoint(velocity)
319 p3 = rotatePoint(origin, velocity, -5) 331 p3 = fife.DoublePoint(velocity)
320 p4 = rotatePoint(origin, velocity, 0) 332 p4 = fife.DoublePoint(velocity)
321 p5 = rotatePoint(origin, velocity, 5) 333 p5 = fife.DoublePoint(velocity)
322 p6 = rotatePoint(origin, velocity, 10) 334 p6 = fife.DoublePoint(velocity)
335
336 p2.rotate(origin, -10)
337 p3.rotate(origin, -5)
338 p4.rotate(origin, 0)
339 p5.rotate(origin, 5)
340 p6.rotate(origin, 10)
323 341
324 pjctl2 = Projectile(self._scene, self._ship, "bullet1", 3000 ) 342 pjctl2 = Projectile(self._scene, self._ship, "bullet1", 3000 )
325 pjctl2.run(p2, self._ship.location) 343 pjctl2.run(p2, self._ship.location)
326 self._scene.addObjectToScene(pjctl2) 344 self._scene.addObjectToScene(pjctl2)
327 345