Mercurial > fife-parpg
comparison demos/shooter/scripts/world.py @ 456:41fd97da94d1
Moved guis to their own file.
Added a continue button to the main menu.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 07 Apr 2010 21:26:26 +0000 |
parents | e686b82d93d0 |
children | 597b066d5ccb |
comparison
equal
deleted
inserted
replaced
455:e686b82d93d0 | 456:41fd97da94d1 |
---|---|
28 | 28 |
29 from scripts.common.eventlistenerbase import EventListenerBase | 29 from scripts.common.eventlistenerbase import EventListenerBase |
30 from scripts.common.helpers import normalize | 30 from scripts.common.helpers import normalize |
31 from fife.extensions.loaders import loadMapFile | 31 from fife.extensions.loaders import loadMapFile |
32 | 32 |
33 from scripts.gui.guis import * | |
34 | |
33 from scripts.ships.shipbase import Ship | 35 from scripts.ships.shipbase import Ship |
34 from scripts.ships.player import Player | 36 from scripts.ships.player import Player |
35 from scripts.scene import Scene | 37 from scripts.scene import Scene |
36 | |
37 class MainMenu(object): | |
38 def __init__(self, world): | |
39 self._world = world | |
40 self._widget = pychan.loadXML('gui/mainmenu.xml') | |
41 | |
42 self._continue = self._widget.findChild(name="continue") | |
43 self._newgame = self._widget.findChild(name="new_game") | |
44 self._credits = self._widget.findChild(name="credits") | |
45 self._highscores = self._widget.findChild(name="high_scores") | |
46 self._quit = self._widget.findChild(name="quit") | |
47 | |
48 self._widget.position = (0,0) | |
49 | |
50 eventMap = { | |
51 'continue': self._world.continueGame, | |
52 'new_game': self._world.newGame, | |
53 'credits': self._world.showCredits, | |
54 'high_scores': self._world.showHighScores, | |
55 'quit': self._world.quit, | |
56 } | |
57 | |
58 self._widget.mapEvents(eventMap) | |
59 | |
60 self._continueMinWidth = self._continue.min_width | |
61 self._continueMinHeight = self._continue.min_height | |
62 self._continueMaxWidth = self._continue.max_width | |
63 self._continueMaxHeight = self._continue.max_height | |
64 | |
65 | |
66 def show(self, cont=False): | |
67 if cont: | |
68 self._continue.min_width = self._continueMinWidth | |
69 self._continue.min_height = self._continueMinHeight | |
70 self._continue.max_width = self._continueMaxWidth | |
71 self._continue.max_height = self._continueMaxHeight | |
72 | |
73 else: | |
74 self._continue.min_width = 0 | |
75 self._continue.min_height = 0 | |
76 self._continue.max_width = 0 | |
77 self._continue.max_height = 0 | |
78 | |
79 self._continue.adaptLayout() | |
80 self._widget.show() | |
81 | |
82 def hide(self): | |
83 self._widget.hide() | |
84 | |
85 | 38 |
86 class World(EventListenerBase): | 39 class World(EventListenerBase): |
87 """ | 40 """ |
88 The world! | 41 The world! |
89 | 42 |
112 self._starttime = 0 | 65 self._starttime = 0 |
113 | 66 |
114 self._mainmenu = MainMenu(self) | 67 self._mainmenu = MainMenu(self) |
115 self.showMainMenu() | 68 self.showMainMenu() |
116 | 69 |
117 self._hudwindow = None | 70 self._hudwindow = HeadsUpDisplay(self) |
71 self._hudwindow.hide() | |
118 | 72 |
119 | 73 |
120 def showMainMenu(self): | 74 def showMainMenu(self): |
121 if self.scene: | 75 if self.scene: |
122 self._paused = True | 76 self._paused = True |
152 self.filename = filename | 106 self.filename = filename |
153 self.reset() | 107 self.reset() |
154 self.map = loadMapFile(self.filename, self.engine) | 108 self.map = loadMapFile(self.filename, self.engine) |
155 | 109 |
156 self.scene = Scene(self.engine, self.map.getLayer('objects')) | 110 self.scene = Scene(self.engine, self.map.getLayer('objects')) |
157 | |
158 if not self._hudwindow: | |
159 self._hudwindow = pychan.loadXML('gui/mainwindow.xml') | |
160 self.fpstext = self._hudwindow.findChild(name="fps") | |
161 self.velocitytext = self._hudwindow.findChild(name="velocity") | |
162 self.positiontext = self._hudwindow.findChild(name="position") | |
163 self.scoretext = self._hudwindow.findChild(name="score") | |
164 self._hudwindow.position = (0,0) | |
165 | |
166 self.scene.initScene(self.map) | 111 self.scene.initScene(self.map) |
112 | |
167 self.initCameras() | 113 self.initCameras() |
168 | 114 |
169 self._hudwindow.show() | 115 self._hudwindow.show() |
170 | 116 |
171 self._starttime = self.timemanager.getTime() | 117 self._starttime = self.timemanager.getTime() |
265 if avgframe > 0: | 211 if avgframe > 0: |
266 fps = 1 / (avgframe / 1000) | 212 fps = 1 / (avgframe / 1000) |
267 else: | 213 else: |
268 fps = 0 | 214 fps = 0 |
269 fpstxt = "%3.2f" % fps | 215 fpstxt = "%3.2f" % fps |
270 self.fpstext.text = unicode(fpstxt) | 216 self._hudwindow.setFPSText(unicode(fpstxt)) |
271 | 217 |
272 player = self.scene.player | 218 player = self.scene.player |
273 exactcoords = player.location.getExactLayerCoordinates() | 219 exactcoords = player.location.getExactLayerCoordinates() |
274 pos = "%1.2f" % exactcoords.x + ", %1.2f" % exactcoords.y | 220 pos = "%1.2f" % exactcoords.x + ", %1.2f" % exactcoords.y |
275 self.positiontext.text = unicode(pos) | 221 self._hudwindow.setPositionText(unicode(pos)) |
276 | 222 |
277 vel = "%1.2f" % player.velocity.x + ", %1.2f" % player.velocity.y | 223 vel = "%1.2f" % player.velocity.x + ", %1.2f" % player.velocity.y |
278 self.velocitytext.text = unicode(vel) | 224 self._hudwindow.setVelocityText(unicode(vel)) |
279 | 225 |
280 score = unicode(str(player.score)) | 226 score = unicode(str(player.score)) |
281 self.scoretext.text = score | 227 self._hudwindow.setScoreText(score) |
282 | 228 |
283 else: | 229 else: |
284 if not self.scene.paused: | 230 if not self.scene.paused: |
285 self.scene.pause(self.timemanager.getTime() - self._starttime) | 231 self.scene.pause(self.timemanager.getTime() - self._starttime) |
286 | 232 |