comparison demos/shooter/scripts/scene.py @ 455:e686b82d93d0

Added the ability to pause the game. Added the main menu.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 07 Apr 2010 19:37:42 +0000
parents bd7e8f708adf
children 597b066d5ccb
comparison
equal deleted inserted replaced
454:bd7e8f708adf 455:e686b82d93d0
60 self._timedelta = 0 60 self._timedelta = 0
61 self._lasttime = 0 61 self._lasttime = 0
62 62
63 self._xscale = self._layer.getCellGrid().getXScale() 63 self._xscale = self._layer.getCellGrid().getXScale()
64 self._yscale = self._layer.getCellGrid().getYScale() 64 self._yscale = self._layer.getCellGrid().getYScale()
65
66 self._paused = False
67 self._timemod = 0
65 68
66 def initScene(self, mapobj): 69 def initScene(self, mapobj):
67 self._player = Player(self, 'player') 70 self._player = Player(self, 'player')
68 self._player.width = 0.075 71 self._player.width = 0.075
69 self._player.height = 0.075 72 self._player.height = 0.075
95 self._nodes[nodeindex].spaceobjects.append(enemy) 98 self._nodes[nodeindex].spaceobjects.append(enemy)
96 99
97 #and finally add the player to the scene 100 #and finally add the player to the scene
98 self.addObjectToScene(self._player) 101 self.addObjectToScene(self._player)
99 102
103 def pause(self, time):
104 self._pausedtime = time
105 self._paused = True
106
107 def unpause(self, time):
108 self._timemod += time - self._pausedtime
109 self._paused = False
110
100 def getObjectsInNode(self, nodeindex): 111 def getObjectsInNode(self, nodeindex):
101 return self._nodes[nodeindex].instances 112 return self._nodes[nodeindex].instances
102 113
103 def getObjectsInRange(self, rangeL, rangeR): 114 def getObjectsInRange(self, rangeL, rangeR):
104 objects = list() 115 objects = list()
137 def attachCamera(self, cam): 148 def attachCamera(self, cam):
138 self._camera = cam 149 self._camera = cam
139 self._camera.setLocation(self._player.location) 150 self._camera.setLocation(self._player.location)
140 151
141 def update(self, time, keystate): 152 def update(self, time, keystate):
142 timedelta = time - self._time 153 timedelta = (time - self._timemod) - self._time
143 self._timedelta = timedelta 154 self._timedelta = timedelta
144 self._time = time 155 self._time = time - self._timemod
145 156
146 self._keystate = keystate 157 self._keystate = keystate
147 158
148 #update camera location 159 #update camera location
149 loc = self._camera.getLocation() 160 loc = self._camera.getLocation()
227 def _getTime(self): 238 def _getTime(self):
228 return self._time 239 return self._time
229 240
230 def _getTimeDelta(self): 241 def _getTimeDelta(self):
231 return self._timedelta 242 return self._timedelta
232 243
244 def _getPaused(self):
245 return self._paused
246
233 player = property(_getPlayer) 247 player = property(_getPlayer)
234 keystate = property(_getKeyState) 248 keystate = property(_getKeyState)
235 camera = property(_getCamera) 249 camera = property(_getCamera)
236 objectlayer = property(_getObjectLayer) 250 objectlayer = property(_getObjectLayer)
237 model = property(_getModel) 251 model = property(_getModel)
238 time = property(_getTime) 252 time = property(_getTime)
239 timedelta = property(_getTimeDelta) 253 timedelta = property(_getTimeDelta)
240 254 paused = property(_getPaused)