Mercurial > fife-parpg
comparison demos/shooter/scripts/common/baseobject.py @ 453:cf53848fb187
Scene now gets updated when an object moves from one node to another.
Player is now part of the scene.
Projectiles can be files by both player and enemies.
Some code cleanup.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 06 Apr 2010 19:12:41 +0000 |
parents | f463ab431cc0 |
children | bd7e8f708adf |
comparison
equal
deleted
inserted
replaced
452:f07d779362da | 453:cf53848fb187 |
---|---|
24 from fife import fife | 24 from fife import fife |
25 from scripts.common.helpers import normalize | 25 from scripts.common.helpers import normalize |
26 from scripts.common.helpers import Rect | 26 from scripts.common.helpers import Rect |
27 | 27 |
28 class SpaceObject(object): | 28 class SpaceObject(object): |
29 def __init__(self, model, name, layer, findInstance=True): | 29 def __init__(self, scene, name, findInstance=True): |
30 self._model = model | 30 self._scene = scene |
31 self._layer = layer | 31 self._model = self._scene.model |
32 self._layer = self._scene.objectlayer | |
32 self._name = name | 33 self._name = name |
33 self._xscale = self._layer.getCellGrid().getXScale() | 34 self._xscale = self._layer.getCellGrid().getXScale() |
34 self._yscale = self._layer.getCellGrid().getYScale() | 35 self._yscale = self._layer.getCellGrid().getYScale() |
35 self._velocity = fife.DoublePoint(0,0) | 36 self._velocity = fife.DoublePoint(0,0) |
36 self._maxvelocity = 1.25 | 37 self._maxvelocity = 1.25 |
37 self._timedelta = 0 | 38 self._timedelta = 0 |
38 self._boundingBox = Rect(0,0,0,0) | 39 self._boundingBox = Rect(0,0,0,0) |
39 self._running = False | 40 self._running = False |
41 self._changedPosition = False | |
42 self._scenenodeid = -1 | |
40 | 43 |
41 if findInstance: | 44 if findInstance: |
42 self._instance = self._layer.getInstance(self._name) | 45 self._instance = self._layer.getInstance(self._name) |
43 else: | 46 else: |
44 self._instnace = None | 47 self._instnace = None |
59 | 62 |
60 self._boundingBox.x = (exactloc.x - self._boundingBox.w/2) * self._xscale | 63 self._boundingBox.x = (exactloc.x - self._boundingBox.w/2) * self._xscale |
61 self._boundingBox.y = (exactloc.y - self._boundingBox.h/2) * self._yscale | 64 self._boundingBox.y = (exactloc.y - self._boundingBox.h/2) * self._yscale |
62 | 65 |
63 shiploc.setExactLayerCoordinates(exactloc) | 66 shiploc.setExactLayerCoordinates(exactloc) |
67 | |
68 if shiploc == self.location: | |
69 self._changePosition = False | |
70 else: | |
71 self._changedPosition = True | |
72 | |
64 self.location = shiploc | 73 self.location = shiploc |
65 | 74 |
66 def stop(self): | 75 def stop(self): |
67 self._running = False | 76 self._running = False |
68 | 77 |
144 def _setW(self, w): | 153 def _setW(self, w): |
145 self._boundingBox.w = w | 154 self._boundingBox.w = w |
146 | 155 |
147 def _setH(self, h): | 156 def _setH(self, h): |
148 self._boundingBox.h = h | 157 self._boundingBox.h = h |
158 | |
159 def _changedPosition(self): | |
160 return self._changedPosition | |
161 | |
162 def _getNodeId(self): | |
163 return self._scenenodeid | |
164 | |
165 def _setNodeId(self, id): | |
166 self._scenenodeid = id | |
149 | 167 |
150 width = property(_getW, _setW) | 168 width = property(_getW, _setW) |
151 height = property(_getH, _setH) | 169 height = property(_getH, _setH) |
152 boundingbox = property(_getBoundingBox) | 170 boundingbox = property(_getBoundingBox) |
153 location = property(_getLocation,_setLocation) | 171 location = property(_getLocation,_setLocation) |
154 instance = property(_getInstance, _setInstance) | 172 instance = property(_getInstance, _setInstance) |
155 velocity = property(_getVelocity, _setVelocity) | 173 velocity = property(_getVelocity, _setVelocity) |
156 maxvelocity = property(_getMaxVelocity, _setMaxVelocity) | 174 maxvelocity = property(_getMaxVelocity, _setMaxVelocity) |
157 running = property(_isRunning) | 175 running = property(_isRunning) |
176 changedposition = property(_changedPosition) | |
177 scenenodeid = property(_getNodeId, _setNodeId) |