comparison demos/shooter/scripts/weapons.py @ 454:bd7e8f708adf

Time is now managed by the Scene object. Enemy projectiles are now a bit slower.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 06 Apr 2010 21:25:10 +0000
parents cf53848fb187
children 4d0aa75a82f1
comparison
equal deleted inserted replaced
453:cf53848fb187 454:bd7e8f708adf
42 42
43 def create(self, location): 43 def create(self, location):
44 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") 44 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet")
45 fife.InstanceVisual.create(self._instance) 45 fife.InstanceVisual.create(self._instance)
46 46
47 def run(self, velocity, location, time): 47 def run(self, velocity, location):
48 if not self._running: 48 if not self._running:
49 self._velocity = velocity 49 self._velocity = velocity
50 self._velocity.x /= self._xscale 50 self._velocity.x /= self._xscale
51 self._velocity.y /= self._yscale 51 self._velocity.y /= self._yscale
52 52
53 self.create(location) 53 self.create(location)
54 self._running = True 54 self._running = True
55 55
56 self._starttime = time 56 self._starttime = self._scene.time
57 57
58 def destroy(self): 58 def destroy(self):
59 if self._running and self._instance: 59 if self._running and self._instance:
60 self._layer.deleteInstance(self._instance) 60 self._layer.deleteInstance(self._instance)
61 self._running = False 61 self._running = False
64 return self._ttl 64 return self._ttl
65 65
66 def _getOwner(self): 66 def _getOwner(self):
67 return self._owner 67 return self._owner
68 68
69 def update(self, timedelta): 69 def update(self):
70 self._totaltime += timedelta 70 self._totaltime += self._scene.timedelta
71 if self._running and (self._totaltime - self._starttime) < self._ttl: 71 if self._running and self._totaltime < self._ttl:
72 super(Projectile, self).update(timedelta) 72 super(Projectile, self).update()
73 else: 73 else:
74 self.destroy() 74 self.destroy()
75 75
76 ttl = property(_getTTL) 76 ttl = property(_getTTL)
77 owner = property(_getOwner) 77 owner = property(_getOwner)
84 self._ship = ship 84 self._ship = ship
85 self._firerate = firerate 85 self._firerate = firerate
86 self._lastfired = 0 86 self._lastfired = 0
87 self._projectileVelocity = 0.75 87 self._projectileVelocity = 0.75
88 88
89 def fire(self, curtime, direction): 89 def fire(self, direction):
90 return None
91
92 def _getProjectileVelocity(self):
93 return self._projectileVelocity
94
95 def _setProjectileVelocity(self, vel):
96 self._projectileVelocity = vel
97
98 projectilevelocity = property(_getProjectileVelocity, _setProjectileVelocity)
99
100 class Cannon(Weapon):
101 def __init__(self, scene, ship, firerate):
102 super(Cannon, self).__init__(scene, ship, firerate)
103
104 #cannon's projectile velocity
105 self._projectileVelocity = 0.75
106
107
108 def fire(self, direction):
90 velocity = normalize(direction) 109 velocity = normalize(direction)
91 velocity.x = velocity.x * self._projectileVelocity 110 velocity.x = velocity.x * self._projectileVelocity
92 velocity.y = velocity.y * self._projectileVelocity 111 velocity.y = velocity.y * self._projectileVelocity
93 112
94 if (curtime - self._lastfired) > self._firerate: 113 if (self._scene.time - self._lastfired) > self._firerate:
95 pjctl = Projectile(self._scene, self._ship, "bullet1", 2000 ) 114 pjctl = Projectile(self._scene, self._ship, "bullet1", 6000 )
96 pjctl.run(velocity, self._ship.location, curtime) 115 pjctl.run(velocity, self._ship.location)
97 self._lastfired = curtime 116 self._lastfired = self._scene.time
98 return pjctl 117 self._scene.addProjectileToScene(pjctl)
99 118
100 return None 119
101