Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
448:5e2ec84902a7 | 449:1cf56403347a |
---|---|
29 super(Projectile, self).__init__(model, projectileName, layer, False) | 29 super(Projectile, self).__init__(model, projectileName, layer, False) |
30 self._name = projectileName | 30 self._name = projectileName |
31 self._layer = layer | 31 self._layer = layer |
32 | 32 |
33 self._obj = self._model.getObject(self._name, "http://www.fifengine.de/xml/tutorial") | 33 self._obj = self._model.getObject(self._name, "http://www.fifengine.de/xml/tutorial") |
34 self._running = False | 34 |
35 self._ttl = timeToLive | 35 self._ttl = timeToLive |
36 self._starttime = 0 | 36 self._starttime = 0 |
37 self._totaltime = 0 | |
37 | 38 |
38 def create(self, location): | 39 def create(self, location): |
39 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") | 40 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") |
40 fife.InstanceVisual.create(self._instance) | 41 fife.InstanceVisual.create(self._instance) |
41 | 42 |
53 def destroy(self): | 54 def destroy(self): |
54 if self._running and self._instance: | 55 if self._running and self._instance: |
55 self._layer.deleteInstance(self._instance) | 56 self._layer.deleteInstance(self._instance) |
56 self._running = False | 57 self._running = False |
57 | 58 |
58 def _isRunning(self): | |
59 return self._running | |
60 | |
61 def _getTTL(self): | 59 def _getTTL(self): |
62 return self._ttl | 60 return self._ttl |
63 | 61 |
64 def update(self, curtime): | 62 def update(self, timedelta): |
65 if self._running and (curtime - self._starttime) < self._ttl: | 63 self._totaltime += timedelta |
66 projloc = self.location | 64 if self._running and (self._totaltime - self._starttime) < self._ttl: |
67 exactloc = projloc.getExactLayerCoordinates() | 65 super(Projectile, self).update(timedelta) |
68 | |
69 exactloc.x += self._velocity.x | |
70 exactloc.y += self._velocity.y | |
71 | |
72 projloc.setExactLayerCoordinates(exactloc) | |
73 self.location = projloc | |
74 else: | 66 else: |
75 self.destroy() | 67 self.destroy() |
76 | 68 |
77 running = property(_isRunning) | |
78 ttl = property(_getTTL) | 69 ttl = property(_getTTL) |
79 | 70 |
80 class Weapon(object): | 71 class Weapon(object): |
81 def __init__(self, model, layer, ship, firerate): | 72 def __init__(self, model, layer, ship, firerate): |
82 self._model = model | 73 self._model = model |
87 self._projectileVelocity = fife.DoublePoint(0.075,0) | 78 self._projectileVelocity = fife.DoublePoint(0.075,0) |
88 | 79 |
89 def fire(self, curtime): | 80 def fire(self, curtime): |
90 if (curtime - self._lastfired) > self._firerate: | 81 if (curtime - self._lastfired) > self._firerate: |
91 pjctl = Projectile(self._model, "bullet1", self._layer, 2000 ) | 82 pjctl = Projectile(self._model, "bullet1", self._layer, 2000 ) |
83 pjctl.width = 0.05 | |
84 pjctl.height = 0.05 | |
92 pjctl.run(fife.DoublePoint(self._projectileVelocity.x,self._projectileVelocity.y), self._ship.location, curtime) | 85 pjctl.run(fife.DoublePoint(self._projectileVelocity.x,self._projectileVelocity.y), self._ship.location, curtime) |
93 self._lastfired = curtime | 86 self._lastfired = curtime |
94 return pjctl | 87 return pjctl |
95 | 88 |
96 return None | 89 return None |