def start_soundtrack(self): """Choose and play music for the intro scene.""" sources = screens['Intro']['music'] self.source = choice(sources) Logger.info('Chose "{}" as the intro music.'.format(self.source)) try: SoundManager.music[self.source] except KeyError: SoundManager.add_music(self.source, self) SoundManager.play_music(self.source)
def generate_asteroid(self): positions = [] while len(positions) < 10: location = (randint(1, Window.width), randint(1, Window.height)) if abs(self.player.pos[0] - location[0]) < 100: pass elif abs(self.player.pos[1] - location[1]) < 100: pass else: positions.append(location) position = choice(positions) asteroid = AsteroidObstacle() asteroid.randomize_trajectory() asteroid.pos = position SoundManager.add_sfx(asteroid.states['exploded']['sfx'], asteroid) self.ids.GameView.add_widget(asteroid) # self.add_widget(asteroid) self.asteroids.append(asteroid) return asteroid
def fire(self): """Fire the ship's weapons.""" Logger.debug('Entities: Firing weapons.') shell = PlayerWeapons(type=self.weapontype) if shell.sfx != self.weaponsound: # The sound effect has changed. # Remove the old sound effect. if self.weaponsound is not None: sfx = SoundManager.sfx.get(self.weaponsound) SoundManager.remove_sfx(sfx, self) # Add the new sound effect. self.weaponsound = shell.sfx SoundManager.add_sfx(shell.sfx, self) Logger.debug('Entities: Last Fired: {}'.format(self.lastfired)) if self.lastfired >= shell.stats['recharge']: self.lastfired = 0.0 # Position the shell in front of the ship. shell.origin = "player" shell.angle = self.angle shell.speed = shell.stats['speed'] shell.pos = self.pos # Add the shell to the list of fired weapons to track. self.shells.append(shell) self.parent.add_widget(shell) SoundManager.play_sfx(shell.sfx) Logger.debug('Entities: Bombs away!') else: Logger.debug('Entities: Weapons are not charged.')
def explosion(self, obj1, obj2, dt): print("Explosion between %s and %s" % (obj1, obj2)) print("----------------Collidable List on Impact: ", self.collidables) Logger.info('Explode: "{}" and "{}" have collided: '.format( obj1, obj2)) try: self.collidables.remove(obj1) except: pass try: self.collidables.remove(obj2) except: pass print("+++++++++++++++Collidable List AFTER Impact", self.collidables) try: obj1.destroyed = True except: pass try: obj2.destroyed = True except: pass SoundManager.play_sfx(obj1.states['exploded']['sfx']) SoundManager.play_sfx(obj2.states['exploded']['sfx']) try: SoundManager.remove_sfx(obj1.states['exploded']['sfx'], obj1) except: pass try: SoundManager.remove_sfx(obj2.states['exploded']['sfx'], obj2) except: pass obj1.skin = obj1.states['exploded']['skin'] obj2.skin = obj2.states['exploded']['skin'] Clock.schedule_once(partial(self.new_remove_widget, obj1), .3) Clock.schedule_once(partial(self.new_remove_widget, obj2), .3)
def stop_soundtrack(self): """Stop the intro scene music.""" SoundManager.remove_music(self.source, self)
def init_hostiles(self, number): """Prepare the level's hostiles.""" for i in range(number): self.spaceships.append(self.hostile) SoundManager.add_sfx(self.hostile.states['exploded']['sfx'], self.hostile)
def init_players(self): """Prepare the player ships.""" self.spaceships.append(self.player) SoundManager.add_sfx(self.player.states['exploded']['sfx'], self.player)