comparison demos/shooter/scripts/scene.py @ 454:bd7e8f708adf

Time is now managed by the Scene object. Enemy projectiles are now a bit slower.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 06 Apr 2010 21:25:10 +0000
parents cf53848fb187
children e686b82d93d0
comparison
equal deleted inserted replaced
453:cf53848fb187 454:bd7e8f708adf
48 self._engine = engine 48 self._engine = engine
49 self._model = engine.getModel() 49 self._model = engine.getModel()
50 self._layer = objectLayer 50 self._layer = objectLayer
51 self._nodes = list() 51 self._nodes = list()
52 52
53 self._player = None
54 self._projectiles = list()
55
56 self._maxnodes = 128
57 self._xscale = 0
58
59 self._time = 0
60 self._timedelta = 0
61 self._lasttime = 0
62
63 self._xscale = self._layer.getCellGrid().getXScale()
64 self._yscale = self._layer.getCellGrid().getYScale()
65
66 def initScene(self, mapobj):
53 self._player = Player(self, 'player') 67 self._player = Player(self, 'player')
54 self._player.width = 0.075 68 self._player.width = 0.075
55 self._player.height = 0.075 69 self._player.height = 0.075
56 self._player.start() 70 self._player.start()
57
58 self._projectiles = list()
59 self._lasttime = 0
60
61 self._maxnodes = 128
62 self._xscale = 0
63
64 self._time = 0
65 self._timedelta = 0
66
67 def initScene(self, mapobj):
68 self._xscale = self._layer.getCellGrid().getXScale()
69 71
70 enemies = self._layer.getInstances('enemy') 72 enemies = self._layer.getInstances('enemy')
71 73
72 #initialize our scene array to some arbitrary size 74 #initialize our scene array to some arbitrary size
73 for i in range(0,self._maxnodes): 75 for i in range(0,self._maxnodes):
166 screenlist = self.getObjectsInRange(leftnode, rightnode) 168 screenlist = self.getObjectsInRange(leftnode, rightnode)
167 169
168 170
169 #update objects on the screen 171 #update objects on the screen
170 for obj in screenlist: 172 for obj in screenlist:
171 obj.update(timedelta) 173 obj.update()
172 if obj.changedposition: 174 if obj.changedposition:
173 self.moveObjectInScene(obj) 175 self.moveObjectInScene(obj)
174 176
175 #Testing enemy fire
176 #prjct = obj.fire(time, fife.DoublePoint(-1,0))
177 #if prjct:
178 # self._projectiles.append(prjct)
179
180 if obj != self._player: 177 if obj != self._player:
178 #TODO: enemy should fire weapon in their update function
179 obj.fire(fife.DoublePoint(-1,0))
180
181 if obj.boundingbox.intersects(self._player.boundingbox): 181 if obj.boundingbox.intersects(self._player.boundingbox):
182 #player touched an enemy. Destroy player and 182 #player touched an enemy. Destroy player and
183 #re-initialize scene 183 #re-initialize scene
184 self._player.destroy() 184 self._player.destroy()
185 185
186 186
187 #update the list of projectiles 187 #update the list of projectiles
188 projtodelete = list() 188 projtodelete = list()
189 for p in self._projectiles: 189 for p in self._projectiles:
190 p.update(timedelta) 190 p.update()
191 #check to see if the projectile hit any object on the screen 191 #check to see if the projectile hit any object on the screen
192 for o in screenlist: 192 for o in screenlist:
193 #cant get hit by your own bullet 193 #cant get hit by your own bullet
194 if p.owner != o: 194 if p.owner != o:
195 if p.boundingbox.intersects(o.boundingbox): 195 if p.boundingbox.intersects(o.boundingbox):
196 self._player.applyScore(100) 196 self._player.applyScore(100)
197 p.destroy() 197 p.destroy()
198 o.destroy() 198 o.destroy()
199 #temporary... the destroy functions should spawn an explosion 199 #TODO: the destroy functions should spawn an explosion
200 #and also destroy the instance and remove itself from the scene 200 #and also destroy the instance and remove itself from the scene
201 self.removeObjectFromScene(o) 201 self.removeObjectFromScene(o)
202 202
203 #build a list of projectiles to remove (ttl expired) 203 #build a list of projectiles to remove (ttl expired)
204 if not p.running: 204 if not p.running: