comparison demos/shooter/scripts/world.py @ 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 7a79dc2a0592
comparison
equal deleted inserted replaced
468:ebbb420a90b9 469:5994e61cdebd
75 self._gameover.hide() 75 self._gameover.hide()
76 76
77 self._highscores = HighScores(self) 77 self._highscores = HighScores(self)
78 self._highscores.hide() 78 self._highscores.hide()
79 79
80 self._winner = WinnerDisplay()
81 self._winner.hide()
82
80 self._genericrenderer = None 83 self._genericrenderer = None
81 84
82 self._sceneended = False 85 self._gamecomplete = False
83 86
84 def showMainMenu(self): 87 def showMainMenu(self):
85 if self.scene: 88 if self.scene:
86 self._paused = True 89 self._paused = True
87 cont = True 90 cont = True
99 def quit(self): 102 def quit(self):
100 self.reset() 103 self.reset()
101 self._applictaion.requestQuit() 104 self._applictaion.requestQuit()
102 105
103 def reset(self): 106 def reset(self):
104 #TODO: ensure these get destroyed correctly
105 if self.map: 107 if self.map:
106 self.model.deleteMap(self.map) 108 self.model.deleteMap(self.map)
107 self.map = None 109 self.map = None
108 110
109 self.cameras = {} 111 self.cameras = {}
110 112
111 if self.scene: 113 if self.scene:
112 self.scene.destroyScene() 114 self.scene.destroyScene()
113 self.scene = None 115 self.scene = None
114 116
115 self._sceneended = False 117 self._gamecomplete = False
116 118
117 def loadLevel(self, filename): 119 def loadLevel(self, filename):
118 """ 120 """
119 Load a xml map and setup cameras. 121 Load a xml map and setup cameras.
120 """ 122 """
123
124 self.resetKeys()
125
121 self.filename = filename 126 self.filename = filename
122 self.reset() 127 self.reset()
123 self.map = loadMapFile(self.filename, self.engine) 128 self.map = loadMapFile(self.filename, self.engine)
124 129
125 self.scene = Scene(self, self.engine, self.map.getLayer('objects')) 130 self.scene = Scene(self, self.engine, self.map.getLayer('objects'))
127 132
128 self.initCameras() 133 self.initCameras()
129 134
130 self._hudwindow.show() 135 self._hudwindow.show()
131 self._gameover.hide() 136 self._gameover.hide()
137 self._winner.hide()
132 138
133 self._starttime = self.timemanager.getTime() 139 self._starttime = self.timemanager.getTime()
134 140
135 self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main']) 141 self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main'])
136 self._genericrenderer.clearActiveLayers() 142 self._genericrenderer.clearActiveLayers()
193 node_bottomright.thisown = 0 199 node_bottomright.thisown = 0
194 node_bottomleft.thisown = 0 200 node_bottomleft.thisown = 0
195 201
196 def gameOver(self): 202 def gameOver(self):
197 self._gameover.show() 203 self._gameover.show()
198 204 self._hudwindow.hide()
199 if self._highscores.isHighScore(self.scene.player.score): 205
200 dlg = pychan.loadXML('gui/highscoredialog.xml') 206 self.saveScore()
201 dlg.execute({ 'okay' : "Yay!" })
202 name = dlg.findChild(name='name').text
203
204 self._highscores.addHighScore(HighScore(name, self.scene.player.score))
205 self._highscores.show()
206 207
207 def endLevel(self): 208 def endLevel(self):
208 self._paused = True 209 self._paused = True
209 self._sceneended = True 210
210 211 #only one level so the game is over once you complete it.
211 def showHighScoreDialog(self): 212 self._gamecomplete = True
212 self._sceneended = False 213 self._winner.show()
214 self._hudwindow.hide()
215
216 def saveScore(self):
217 self._gamecomplete = False
213 218
214 if self._highscores.isHighScore(self.scene.player.score): 219 if self._highscores.isHighScore(self.scene.player.score):
215 score = self.scene.player.score 220 score = self.scene.player.score
216 221
217 dlg = pychan.loadXML('gui/highscoredialog.xml') 222 dlg = pychan.loadXML('gui/highscoredialog.xml')
241 if cam.getId() == 'main': 246 if cam.getId() == 'main':
242 self.cameras['main'] = cam 247 self.cameras['main'] = cam
243 248
244 self.scene.attachCamera(self.cameras['main']) 249 self.scene.attachCamera(self.cameras['main'])
245 250
251 def resetKeys(self):
252 self.keystate['UP'] = False
253 self.keystate['DOWN'] = False
254 self.keystate['LEFT'] = False
255 self.keystate['RIGHT'] = False
256 self.keystate['SPACE'] = False
257 self.keystate['CTRL'] = False
258
246 259
247 def keyPressed(self, evt): 260 def keyPressed(self, evt):
248 keyval = evt.getKey().getValue() 261 keyval = evt.getKey().getValue()
249 keystr = evt.getKey().getAsString().lower() 262 keystr = evt.getKey().getAsString().lower()
250 if keyval == fife.Key.UP: 263 if keyval == fife.Key.UP:
298 def pump(self): 311 def pump(self):
299 """ 312 """
300 Called every frame. 313 Called every frame.
301 """ 314 """
302 315
303 if self._sceneended: 316 if self._gamecomplete:
304 self.showHighScoreDialog() 317 self.saveScore()
305 self.reset() 318 self.reset()
306 319
307 if self._genericrenderer: 320 if self._genericrenderer:
308 self._genericrenderer.removeAll("quads") 321 self._genericrenderer.removeAll("quads")
309 322