Mercurial > fife-parpg
comparison demos/shooter/scripts/weapons.py @ 448:5e2ec84902a7
Did a little re-factoring.
Introduced the scene graph for collision detection.
Changed the time scale to be accurate.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 01 Apr 2010 17:03:34 +0000 |
parents | 64676ea55472 |
children | 1cf56403347a |
comparison
equal
deleted
inserted
replaced
447:64676ea55472 | 448:5e2ec84902a7 |
---|---|
20 # Free Software Foundation, Inc., | 20 # Free Software Foundation, Inc., |
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.ships.shipbase import SpaceObject | |
25 | 26 |
26 class Projectile(object): | 27 class Projectile(SpaceObject): |
27 def __init__(self, model, projectileName, layer, timeToLive): | 28 def __init__(self, model, projectileName, layer, timeToLive): |
28 self._model = model | 29 super(Projectile, self).__init__(model, projectileName, layer, False) |
29 self._name = projectileName | 30 self._name = projectileName |
30 self._layer = layer | 31 self._layer = layer |
31 self._instance = None | 32 |
32 self._velocity = None | |
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 self._running = False |
35 self._ttl = timeToLive | 35 self._ttl = timeToLive |
36 self._starttime = 0 | 36 self._starttime = 0 |
37 | 37 |
38 self._xscale = self._layer.getCellGrid().getXScale() | |
39 self._yscale = self._layer.getCellGrid().getYScale() | |
40 | |
41 def create(self, location): | 38 def create(self, location): |
42 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") | 39 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") |
43 fife.InstanceVisual.create(self._instance) | 40 fife.InstanceVisual.create(self._instance) |
44 | 41 |
45 def run(self, velocity, location, time): | 42 def run(self, velocity, location, time): |
56 def destroy(self): | 53 def destroy(self): |
57 if self._running and self._instance: | 54 if self._running and self._instance: |
58 self._layer.deleteInstance(self._instance) | 55 self._layer.deleteInstance(self._instance) |
59 self._running = False | 56 self._running = False |
60 | 57 |
61 def _getLocation(self): | |
62 return self._instance.getLocation() | |
63 | |
64 def _setLocation(self, loc): | |
65 self._instance.setLocation(loc) | |
66 | |
67 def _isRunning(self): | 58 def _isRunning(self): |
68 return self._running | 59 return self._running |
69 | 60 |
70 def _getTTL(self): | 61 def _getTTL(self): |
71 return self._ttl | 62 return self._ttl |
81 projloc.setExactLayerCoordinates(exactloc) | 72 projloc.setExactLayerCoordinates(exactloc) |
82 self.location = projloc | 73 self.location = projloc |
83 else: | 74 else: |
84 self.destroy() | 75 self.destroy() |
85 | 76 |
86 location = property(_getLocation,_setLocation) | |
87 running = property(_isRunning) | 77 running = property(_isRunning) |
88 ttl = property(_getTTL) | 78 ttl = property(_getTTL) |
89 | 79 |
90 class Weapon(object): | 80 class Weapon(object): |
91 def __init__(self, model, layer, ship, firerate): | 81 def __init__(self, model, layer, ship, firerate): |