comparison demos/shooter/scripts/scene.py @ 479:ab28994820dd

Added some powerups including a spread weapon and an extra life. Fixed the problem where the player could fly off the screen.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 23 Apr 2010 17:17:02 +0000
parents 41f7754f2a4b
children 85fa5fa486a8
comparison
equal deleted inserted replaced
478:41f7754f2a4b 479:ab28994820dd
23 23
24 from fife import fife 24 from fife import fife
25 from scripts.ships.shipbase import * 25 from scripts.ships.shipbase import *
26 from scripts.ships.player import Player 26 from scripts.ships.player import Player
27 from scripts.ships.enemies import * 27 from scripts.ships.enemies import *
28 from scripts.powerups import *
28 from scripts.common.helpers import Rect 29 from scripts.common.helpers import Rect
29 30
30 class SceneNode(object): 31 class SceneNode(object):
31 def __init__(self, spaceobjects = None): 32 def __init__(self, spaceobjects = None):
32 if not spaceobjects: 33 if not spaceobjects:
98 self._player = Player(self, 'player') 99 self._player = Player(self, 'player')
99 self._player.init() 100 self._player.init()
100 self._player.start() 101 self._player.start()
101 102
102 enemies = list() 103 enemies = list()
104 powerups = list()
103 105
104 temp = self._layer.getInstances('dodge1') 106 temp = self._layer.getInstances('dodge1')
105 enemies.extend(temp) 107 enemies.extend(temp)
106 108
107 temp = self._layer.getInstances('dodge2') 109 temp = self._layer.getInstances('dodge2')
116 temp = self._layer.getInstances("streaker") 118 temp = self._layer.getInstances("streaker")
117 enemies.extend(temp) 119 enemies.extend(temp)
118 120
119 temp = self._layer.getInstances("boss") 121 temp = self._layer.getInstances("boss")
120 enemies.extend(temp) 122 enemies.extend(temp)
123
124 temp = self._layer.getInstances("cannonspread5")
125 powerups.extend(temp)
126
127 temp = self._layer.getInstances("extralife")
128 powerups.extend(temp)
121 129
122 for instance in enemies: 130 for instance in enemies:
123 objectName = instance.getId() 131 objectName = instance.getId()
124 print objectName
125 132
126 if objectName == "dodge1": 133 if objectName == "dodge1":
127 enemy = Saucer1(self, 'enemy', instance, False) 134 enemy = Saucer1(self, 'enemy', instance, False)
128 elif objectName == "dodge2": 135 elif objectName == "dodge2":
129 enemy = Saucer2(self, 'enemy', instance, False) 136 enemy = Saucer2(self, 'enemy', instance, False)
143 loc = instance.getLocation().getExactLayerCoordinates() 150 loc = instance.getLocation().getExactLayerCoordinates()
144 nodeindex = int(loc.x * self._xscale) 151 nodeindex = int(loc.x * self._xscale)
145 enemy.scenenodeid = nodeindex 152 enemy.scenenodeid = nodeindex
146 self._nodes[nodeindex].spaceobjects.append(enemy) 153 self._nodes[nodeindex].spaceobjects.append(enemy)
147 154
155 for instance in powerups:
156 objectName = instance.getId()
157
158 print objectName
159
160 if objectName == "cannonspread5":
161 powerup = CannonSpread5PU(self, 'cannonspread5', instance, False)
162 elif objectName == "extralife":
163 powerup = ExtraLifePU(self, 'extralife', instance, False)
164 else:
165 powerup = PowerUp(self, 'powerup', instance, False)
166
167 powerup.start()
168
169 loc = instance.getLocation().getExactLayerCoordinates()
170 nodeindex = int(loc.x * self._xscale)
171 powerup.scenenodeid = nodeindex
172 self._nodes[nodeindex].spaceobjects.append(powerup)
173
148 #and finally add the player to the scene 174 #and finally add the player to the scene
149 self.addObjectToScene(self._player) 175 self.addObjectToScene(self._player)
150 176
151 self.startCamera() 177 self.startCamera()
152 178
279 if obj.changedposition: 305 if obj.changedposition:
280 self.moveObjectInScene(obj) 306 self.moveObjectInScene(obj)
281 307
282 if obj.type != SHTR_PLAYER and obj.type != SHTR_PROJECTILE: 308 if obj.type != SHTR_PLAYER and obj.type != SHTR_PROJECTILE:
283 if obj.running and obj.boundingbox.intersects(self._player.boundingbox): 309 if obj.running and obj.boundingbox.intersects(self._player.boundingbox):
284 #player touched an enemy. Destroy player and 310 if obj.type == SHTR_ENEMYSHIP:
285 #re-initialize scene 311 #player touched an enemy. Destroy player and
286 if not self._player.invulnerable: 312 #re-initialize scene
287 #collision damage of 1 313 if not self._player.invulnerable:
288 self.playerHit(1) 314 #collision damage of 1
289 obj.applyHit(1) 315 self.playerHit(1)
316 obj.applyHit(1)
317 elif obj.type == SHTR_POWERUP:
318 obj.applyPowerUp(self._player)
290 319
291 elif obj.type == SHTR_PROJECTILE: 320 elif obj.type == SHTR_PROJECTILE:
292 321
293 #projectile went off the right edge of the screen. Remove it from the scene. 322 #projectile went off the right edge of the screen. Remove it from the scene.
294 if obj.scenenodeid >= rightnode: 323 if obj.scenenodeid >= rightnode:
299 #use a range to be sure. 328 #use a range to be sure.
300 pcollide = self.getObjectsInRange(obj.scenenodeid - 1, obj.scenenodeid + 1) 329 pcollide = self.getObjectsInRange(obj.scenenodeid - 1, obj.scenenodeid + 1)
301 330
302 for o in pcollide: 331 for o in pcollide:
303 #cant get hit by your own bullet 332 #cant get hit by your own bullet
304 if obj.owner != o and o.type != SHTR_PROJECTILE: 333 if obj.owner != o and o.type != SHTR_PROJECTILE and o.type != SHTR_POWERUP:
305 if o.running and obj.boundingbox.intersects(o.boundingbox): 334 if o.running and obj.boundingbox.intersects(o.boundingbox):
306 if o != self._player and obj.owner.type == SHTR_PLAYER: 335 if o != self._player and obj.owner.type == SHTR_PLAYER:
307 o.applyHit(obj.damage) 336 o.applyHit(obj.damage)
308 #check if enemy ship was destroyed 337 #check if enemy ship was destroyed
309 if not o.running: 338 if not o.running: