Mercurial > fife-parpg
diff demos/shooter/scripts/weapons.py @ 449:1cf56403347a
Added object bounding boxes.
Collision detection now works.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 01 Apr 2010 18:44:01 +0000 |
parents | 5e2ec84902a7 |
children | f463ab431cc0 |
line wrap: on
line diff
--- a/demos/shooter/scripts/weapons.py Thu Apr 01 17:03:34 2010 +0000 +++ b/demos/shooter/scripts/weapons.py Thu Apr 01 18:44:01 2010 +0000 @@ -31,9 +31,10 @@ self._layer = layer self._obj = self._model.getObject(self._name, "http://www.fifengine.de/xml/tutorial") - self._running = False + self._ttl = timeToLive self._starttime = 0 + self._totaltime = 0 def create(self, location): self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") @@ -55,26 +56,16 @@ self._layer.deleteInstance(self._instance) self._running = False - def _isRunning(self): - return self._running - def _getTTL(self): return self._ttl - def update(self, curtime): - if self._running and (curtime - self._starttime) < self._ttl: - projloc = self.location - exactloc = projloc.getExactLayerCoordinates() - - exactloc.x += self._velocity.x - exactloc.y += self._velocity.y - - projloc.setExactLayerCoordinates(exactloc) - self.location = projloc + def update(self, timedelta): + self._totaltime += timedelta + if self._running and (self._totaltime - self._starttime) < self._ttl: + super(Projectile, self).update(timedelta) else: self.destroy() - running = property(_isRunning) ttl = property(_getTTL) class Weapon(object): @@ -89,6 +80,8 @@ def fire(self, curtime): if (curtime - self._lastfired) > self._firerate: pjctl = Projectile(self._model, "bullet1", self._layer, 2000 ) + pjctl.width = 0.05 + pjctl.height = 0.05 pjctl.run(fife.DoublePoint(self._projectileVelocity.x,self._projectileVelocity.y), self._ship.location, curtime) self._lastfired = curtime return pjctl