changeset 469:5994e61cdebd

Added a widget to be displayed after the player completes the game. Renamed the showHighScoreDialog function to saveScore. Player can no longer collide with the boss causing the boss to be destroyed. The player now gets destroyed and the boss takes no damage.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 14 Apr 2010 17:42:24 +0000
parents ebbb420a90b9
children 3b04e921c93d
files demos/shooter/gui/winner.xml demos/shooter/scripts/gui/guis.py demos/shooter/scripts/scene.py demos/shooter/scripts/world.py
diffstat 4 files changed, 55 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/shooter/gui/winner.xml	Wed Apr 14 17:42:24 2010 +0000
@@ -0,0 +1,7 @@
+<Container name="YouWin" position="0,0" size="1024,768" border_size="0" base_color="0,0,0" opaque="0">
+
+	<VBox opaque='1' base_color="188, 0, 0" position="412,200" name="you_win">
+		<Label text="Congrats! You are the champion!" min_size="200,0" border_size="5"/>
+	</VBox>
+
+</Container>
--- a/demos/shooter/scripts/gui/guis.py	Wed Apr 14 16:35:07 2010 +0000
+++ b/demos/shooter/scripts/gui/guis.py	Wed Apr 14 17:42:24 2010 +0000
@@ -76,6 +76,10 @@
 	def hide(self):
 		self._widget.hide()
 		
+	def isVisible(self):
+		return self._widget.isVisible()
+		
+	
 class HeadsUpDisplay(object):
 	def __init__(self, world):
 		self._world = world
@@ -119,6 +123,16 @@
 	def hide(self):
 		self._widget.hide()
 		
+class WinnerDisplay(object):
+	def __init__(self):
+		self._widget = pychan.loadXML('gui/winner.xml')
+		
+	def show(self):
+		self._widget.show()
+		
+	def hide(self):
+		self._widget.hide()
+		
 class HighScore(object):
 	def __init__(self, name, score):
 		self._name = name
@@ -342,4 +356,7 @@
 		
 	def hide(self):
 		self.saveHighScores()
-		self._widget.hide()
\ No newline at end of file
+		self._widget.hide()
+
+	def isVisible(self):
+		return self._widget.isVisible()
\ No newline at end of file
--- a/demos/shooter/scripts/scene.py	Wed Apr 14 16:35:07 2010 +0000
+++ b/demos/shooter/scripts/scene.py	Wed Apr 14 17:42:24 2010 +0000
@@ -283,7 +283,8 @@
 					#re-initialize scene
 					if not self._player.invulnerable:
 						self.playerHit()
-						obj.destroy()
+						if obj != self._boss:
+							obj.destroy()
 						
 #			self._world.renderBoundingBox(obj)
 					
--- a/demos/shooter/scripts/world.py	Wed Apr 14 16:35:07 2010 +0000
+++ b/demos/shooter/scripts/world.py	Wed Apr 14 17:42:24 2010 +0000
@@ -77,9 +77,12 @@
 		self._highscores = HighScores(self)
 		self._highscores.hide()
 		
+		self._winner = WinnerDisplay()
+		self._winner.hide()
+		
 		self._genericrenderer = None
 		
-		self._sceneended = False
+		self._gamecomplete = False
 		
 	def showMainMenu(self):
 		if self.scene:
@@ -101,7 +104,6 @@
 		self._applictaion.requestQuit()
 		
 	def reset(self):
-		#TODO: ensure these get destroyed correctly
 		if self.map:
 			self.model.deleteMap(self.map)
 		self.map = None
@@ -112,12 +114,15 @@
 			self.scene.destroyScene()
 			self.scene = None
 			
-		self._sceneended = False
+		self._gamecomplete = False
 
 	def loadLevel(self, filename):
 		"""
 		Load a xml map and setup cameras.
 		"""
+		
+		self.resetKeys()
+		
 		self.filename = filename
 		self.reset()
 		self.map = loadMapFile(self.filename, self.engine)
@@ -129,6 +134,7 @@
 
 		self._hudwindow.show()
 		self._gameover.hide()
+		self._winner.hide()
 		
 		self._starttime = self.timemanager.getTime()
 		
@@ -195,21 +201,20 @@
 
 	def gameOver(self):
 		self._gameover.show()
+		self._hudwindow.hide()
 		
-		if self._highscores.isHighScore(self.scene.player.score):
-			dlg = pychan.loadXML('gui/highscoredialog.xml')
-			dlg.execute({ 'okay' : "Yay!" })
-			name = dlg.findChild(name='name').text
-			
-			self._highscores.addHighScore(HighScore(name, self.scene.player.score))
-			self._highscores.show()
+		self.saveScore()
 	
 	def endLevel(self):
 		self._paused = True
-		self._sceneended = True
+		
+		#only one level so the game is over once you complete it.
+		self._gamecomplete = True
+		self._winner.show()
+		self._hudwindow.hide()
 
-	def showHighScoreDialog(self):
-		self._sceneended = False
+	def saveScore(self):
+		self._gamecomplete = False
 	
 		if self._highscores.isHighScore(self.scene.player.score):
 			score = self.scene.player.score
@@ -243,6 +248,14 @@
 				
 		self.scene.attachCamera(self.cameras['main'])
 		
+	def resetKeys(self):
+		self.keystate['UP'] = False
+		self.keystate['DOWN'] = False
+		self.keystate['LEFT'] = False
+		self.keystate['RIGHT'] = False
+		self.keystate['SPACE'] = False
+		self.keystate['CTRL'] = False
+
 
 	def keyPressed(self, evt):
 		keyval = evt.getKey().getValue()
@@ -300,8 +313,8 @@
 		Called every frame.
 		"""
 	
-		if self._sceneended:
-			self.showHighScoreDialog()
+		if self._gamecomplete:
+			self.saveScore()
 			self.reset()
 	
 		if self._genericrenderer: