Mercurial > fife-parpg
comparison demos/shooter/scripts/common/baseobject.py @ 477:6b33d80b468b
Projectiles are now part of the scene.
Cleaned up the scene update() function.
Moved garbage collection to the beginning of the frame.
Introduced global object types.
Projectiles now only check for collisions in a limited number of scene nodes rather than the entire screen.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 22 Apr 2010 19:52:34 +0000 |
parents | 78a1eb57c074 |
children | ab28994820dd |
comparison
equal
deleted
inserted
replaced
476:78a1eb57c074 | 477:6b33d80b468b |
---|---|
23 | 23 |
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 | |
29 SHTR_DEFAULT = 0 | |
30 SHTR_PLAYER = 1 | |
31 SHTR_LASTBOSS = 2 | |
32 SHTR_PROJECTILE = 3 | |
33 SHTR_ENEMYSHIP = 4 | |
34 | |
35 | |
28 class SpaceObject(object): | 36 class SpaceObject(object): |
29 def __init__(self, scene, name, findInstance=True): | 37 def __init__(self, scene, name, findInstance=True): |
30 self._scene = scene | 38 self._scene = scene |
31 self._model = self._scene.model | 39 self._model = self._scene.model |
32 self._layer = self._scene.objectlayer | 40 self._layer = self._scene.objectlayer |
37 self._maxvelocity = 1.25 | 45 self._maxvelocity = 1.25 |
38 self._boundingBox = Rect(0,0,0,0) | 46 self._boundingBox = Rect(0,0,0,0) |
39 self._running = False | 47 self._running = False |
40 self._changedPosition = False | 48 self._changedPosition = False |
41 self._scenenodeid = -1 | 49 self._scenenodeid = -1 |
50 self._type = SHTR_DEFAULT | |
42 | 51 |
43 if findInstance: | 52 if findInstance: |
44 self._instance = self._layer.getInstance(self._name) | 53 self._instance = self._layer.getInstance(self._name) |
45 self._instance.thisown = 0 | 54 self._instance.thisown = 0 |
46 else: | 55 else: |
111 self._velocity.x += (norm.x * (self._scene.timedelta/1000.0))/self._xscale | 120 self._velocity.x += (norm.x * (self._scene.timedelta/1000.0))/self._xscale |
112 self._velocity.y += (norm.y * (self._scene.timedelta/1000.0))/self._yscale | 121 self._velocity.y += (norm.y * (self._scene.timedelta/1000.0))/self._yscale |
113 | 122 |
114 def removeFromScene(self): | 123 def removeFromScene(self): |
115 self._scene.queueObjectForRemoval(self) | 124 self._scene.queueObjectForRemoval(self) |
116 # if self._instance: | |
117 # self._layer.deleteInstance(self._instance) | |
118 # self._instance = None | |
119 | 125 |
120 def _isRunning(self): | 126 def _isRunning(self): |
121 return self._running | 127 return self._running |
122 | 128 |
123 def _getMaxVelocity(self): | 129 def _getMaxVelocity(self): |
165 def _getNodeId(self): | 171 def _getNodeId(self): |
166 return self._scenenodeid | 172 return self._scenenodeid |
167 | 173 |
168 def _setNodeId(self, id): | 174 def _setNodeId(self, id): |
169 self._scenenodeid = id | 175 self._scenenodeid = id |
176 | |
177 def _getType(self): | |
178 return self._type | |
179 | |
180 def _setType(self, objtype): | |
181 self._type = objtype | |
170 | 182 |
183 type = property(_getType, _setType) | |
171 width = property(_getW, _setW) | 184 width = property(_getW, _setW) |
172 height = property(_getH, _setH) | 185 height = property(_getH, _setH) |
173 boundingbox = property(_getBoundingBox) | 186 boundingbox = property(_getBoundingBox) |
174 location = property(_getLocation,_setLocation) | 187 location = property(_getLocation,_setLocation) |
175 instance = property(_getInstance, _setInstance) | 188 instance = property(_getInstance, _setInstance) |