def update(self, *args): gameTime, frameTime = args[:2] Screen.update(self, *args) self.ships.update(*args) self.boulders.update(*args) self.boulderFragments.update(*args) #For every boulder colliding with a ship, #kill the boulder & lose health for ship in self.ships: for boulder in ship.testMaskCollision(self.boulders): ship.health -= boulder.damage self.healthBar.updateBarWithValue(ship.health) boulder.kill() if ship.health <= 0: #Kill ship, etc... for ship in self.ships: deadScreen = DeadScreen(self.resolution, self._ui, ship.score) self._ui.clearTopScreen() self._ui.addActiveScreens(deadScreen) pygame.mixer.music.stop() if gameTime >= self.nextBoulderTime: boulderPos = random.randint(0,self.resolution[0]), 0 a = (4**random.random()-1)/2 boulderVel = (a,abs(1-a)) self.boulders.add(Boulder(self, pos=boulderPos, vel=boulderVel, screenBoundaries=(0,0)+self.resolution)) self.nextBoulderTime = gameTime + random.randint(200,1000)
def update(self, *args): gameTime, frameTime = args[:2] Screen.update(self, *args) self.ships.update(*args) self.boulders.update(*args) self.boulderFragments.update(*args) #For every boulder colliding with a ship, #kill the boulder & lose health for ship in self.ships: for boulder in ship.testMaskCollision(self.boulders): ship.health -= boulder.damage self.healthBar.updateBarWithValue(ship.health) boulder.kill() if ship.health <= 0: #Kill ship, etc... for ship in self.ships: deadScreen = DeadScreen(self.resolution, self._ui, ship.score) self._ui.clearTopScreen() self._ui.addActiveScreens(deadScreen) pygame.mixer.music.stop() if gameTime >= self.nextBoulderTime: boulderPos = random.randint(0, self.resolution[0]), 0 a = (4**random.random() - 1) / 2 boulderVel = (a, abs(1 - a)) self.boulders.add( Boulder(self, pos=boulderPos, vel=boulderVel, screenBoundaries=(0, 0) + self.resolution)) self.nextBoulderTime = gameTime + random.randint(200, 1000)