# HG changeset patch
# User prock@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1270761516 0
# Node ID 597b066d5ccb840bd4b7555a53a2e4a6d179f671
# Parent 41fd97da94d11ca39a0cc6ea6b2fb69f6e6f73f3
Player now has 3 lives and will receive a game over message once they are used up.
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/gui/gameover.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/shooter/gui/gameover.xml Thu Apr 08 21:18:36 2010 +0000
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/gui/hud.xml
--- a/demos/shooter/gui/hud.xml Wed Apr 07 21:26:26 2010 +0000
+++ b/demos/shooter/gui/hud.xml Thu Apr 08 21:18:36 2010 +0000
@@ -15,4 +15,8 @@
+
+
+
+
\ No newline at end of file
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/gui/mainmenu.xml
--- a/demos/shooter/gui/mainmenu.xml Wed Apr 07 21:26:26 2010 +0000
+++ b/demos/shooter/gui/mainmenu.xml Thu Apr 08 21:18:36 2010 +0000
@@ -1,20 +1,15 @@
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/scripts/gui/guis.py
--- a/demos/shooter/scripts/gui/guis.py Wed Apr 07 21:26:26 2010 +0000
+++ b/demos/shooter/scripts/gui/guis.py Thu Apr 08 21:18:36 2010 +0000
@@ -82,6 +82,7 @@
self._velocitytext = self._widget.findChild(name="velocity")
self._positiontext = self._widget.findChild(name="position")
self._scoretext = self._widget.findChild(name="score")
+ self._livestext = self._widget.findChild(name="lives")
self._widget.position = (0,0)
def show(self):
@@ -100,4 +101,17 @@
self._velocitytext.text = text
def setScoreText(self, text):
- self._scoretext.text = text
\ No newline at end of file
+ self._scoretext.text = text
+
+ def setLivesText(self, text):
+ self._livestext.text = text
+
+class GameOverDisplay(object):
+ def __init__(self):
+ self._widget = pychan.loadXML('gui/gameover.xml')
+
+ def show(self):
+ self._widget.show()
+
+ def hide(self):
+ self._widget.hide()
\ No newline at end of file
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/scripts/scene.py
--- a/demos/shooter/scripts/scene.py Wed Apr 07 21:26:26 2010 +0000
+++ b/demos/shooter/scripts/scene.py Thu Apr 08 21:18:36 2010 +0000
@@ -27,7 +27,6 @@
from scripts.ships.enemies import *
from scripts.common.helpers import Rect
-
class SceneNode(object):
def __init__(self, spaceobjects = None):
if not spaceobjects:
@@ -44,8 +43,9 @@
spaceobjects = property(_getObjects, _setObjects)
class Scene(object):
- def __init__(self, engine, objectLayer):
+ def __init__(self, world, engine, objectLayer):
self._engine = engine
+ self._world = world
self._model = engine.getModel()
self._layer = objectLayer
self._nodes = list()
@@ -65,11 +65,14 @@
self._paused = False
self._timemod = 0
+
+ self._gameover = False
def initScene(self, mapobj):
self._player = Player(self, 'player')
self._player.width = 0.075
self._player.height = 0.075
+ self._player.init()
self._player.start()
enemies = self._layer.getInstances('enemy')
@@ -99,7 +102,7 @@
#and finally add the player to the scene
self.addObjectToScene(self._player)
-
+
def pause(self, time):
self._pausedtime = time
self._paused = True
@@ -107,6 +110,37 @@
def unpause(self, time):
self._timemod += time - self._pausedtime
self._paused = False
+
+ def playerDied(self):
+ self._player.destroy()
+ if self._player.lives <= -1:
+ self._gameover = True
+ self._world.gameOver()
+ return
+
+ #TODO: Have to find a better way to do this. If the player
+ #dies too many times right at the start of the level he will
+ #get pushed past the edge of the map to the left.
+ #IDEA: count down to ready player to start again
+ oldpos = self._player.location
+ pos = oldpos.getExactLayerCoordinates()
+ pos.x -= 5
+ oldpos.setExactLayerCoordinates(pos)
+ self._player.location = oldpos
+ self._camera.setLocation(self._player.location)
+
+ projtodelete = list()
+ for p in self._projectiles:
+ p.destroy()
+ projtodelete.append(p)
+
+ for p in projtodelete:
+ self._projectiles.remove(p)
+
+ print len(self._projectiles)
+
+ def gameOver(self):
+ self._world.gameOver()
def getObjectsInNode(self, nodeindex):
return self._nodes[nodeindex].instances
@@ -181,7 +215,9 @@
#update objects on the screen
for obj in screenlist:
- obj.update()
+ if not (obj == self._player and self._gameover):
+ obj.update()
+
if obj.changedposition:
self.moveObjectInScene(obj)
@@ -192,7 +228,8 @@
if obj.boundingbox.intersects(self._player.boundingbox):
#player touched an enemy. Destroy player and
#re-initialize scene
- self._player.destroy()
+ self.playerDied()
+ return
#update the list of projectiles
@@ -204,12 +241,18 @@
#cant get hit by your own bullet
if p.owner != o:
if p.boundingbox.intersects(o.boundingbox):
- self._player.applyScore(100)
- p.destroy()
- o.destroy()
- #TODO: the destroy functions should spawn an explosion
- #and also destroy the instance and remove itself from the scene
- self.removeObjectFromScene(o)
+ if o != self._player:
+ self._player.applyScore(100)
+ p.destroy()
+ o.destroy()
+ #TODO: the destroy functions should spawn an explosion
+ #and also destroy the instance and remove itself from the scene
+ self.removeObjectFromScene(o)
+ else:
+ #player got hit by a projectile
+ p.destroy()
+ self.playerDied()
+ return
#build a list of projectiles to remove (ttl expired)
if not p.running:
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/scripts/ships/player.py
--- a/demos/shooter/scripts/ships/player.py Wed Apr 07 21:26:26 2010 +0000
+++ b/demos/shooter/scripts/ships/player.py Thu Apr 08 21:18:36 2010 +0000
@@ -39,6 +39,9 @@
self._lives = 3
+ def init(self):
+ self._lives = 3
+
def _getScore(self):
return self._score
@@ -47,9 +50,13 @@
def destroy(self):
self._lives -= 1
- print "player has been destroyed!"
+
+ if self._lives < 0:
+ self._lives = -1
+
def update(self):
+
key = False
oldpos = self.location
diff -r 41fd97da94d1 -r 597b066d5ccb demos/shooter/scripts/world.py
--- a/demos/shooter/scripts/world.py Wed Apr 07 21:26:26 2010 +0000
+++ b/demos/shooter/scripts/world.py Thu Apr 08 21:18:36 2010 +0000
@@ -70,6 +70,8 @@
self._hudwindow = HeadsUpDisplay(self)
self._hudwindow.hide()
+ self._gameover = GameOverDisplay()
+ self._gameover.hide()
def showMainMenu(self):
if self.scene:
@@ -107,15 +109,18 @@
self.reset()
self.map = loadMapFile(self.filename, self.engine)
- self.scene = Scene(self.engine, self.map.getLayer('objects'))
+ self.scene = Scene(self, self.engine, self.map.getLayer('objects'))
self.scene.initScene(self.map)
self.initCameras()
self._hudwindow.show()
+ self._gameover.hide()
self._starttime = self.timemanager.getTime()
-
+
+ def gameOver(self):
+ self._gameover.show()
def newGame(self):
self.loadLevel("maps/shooter_map1.xml")
@@ -226,6 +231,9 @@
score = unicode(str(player.score))
self._hudwindow.setScoreText(score)
+ lives = unicode(str(player.lives))
+ self._hudwindow.setLivesText(lives)
+
else:
if not self.scene.paused:
self.scene.pause(self.timemanager.getTime() - self._starttime)