def __init__(self): """ We load the playlist. """ self.previous_state = None self.playlists = {} self.music_volume = CONFIG.audio.MUSIC_VOLUME preload = ['credits.ogg'] for plist in ['menu', 'game', 'credits', 'victory']: self.playlists[plist] = [ os.path.join( CONFIG.system_path, 'music', 'ogg', f) for f in os.listdir(os.path.join( CONFIG.system_path, 'music', 'ogg')) if plist in f] for f in os.listdir(os.path.join( CONFIG.system_path, 'music', 'ogg')): if f in preload: loaders.track(os.path.join( CONFIG.system_path, 'music', 'ogg', f)) self.current_track = None self.time_begin = 0
def __init__(self): """ We load the playlist. """ self.previous_state = None self.playlists = {} self.music_volume = CONFIG.audio.MUSIC_VOLUME preload = ['credits.ogg'] for plist in ['menu', 'game', 'credits', 'victory']: self.playlists[plist] = [ os.path.join(CONFIG.system_path, 'music', 'ogg', f) for f in os.listdir( os.path.join(CONFIG.system_path, 'music', 'ogg')) if plist in f ] for f in os.listdir( os.path.join(CONFIG.system_path, 'music', 'ogg')): if f in preload: loaders.track( os.path.join(CONFIG.system_path, 'music', 'ogg', f)) self.current_track = None self.time_begin = 0
def _get_env_collision(self, blocks): """ DEPRECATED? react to collision with some environments as water """ for block in blocks: if self.foot_rect.colliderect(block) == 1: if not self.in_water: loaders.track(os.path.join(CONFIG.system_path, "sounds", "splash1.wav")).play() self.in_water = True return 5 self.in_water = False return 1
def change_animation(self, anim_name, game=None, params=dict()): """ Change animation of the entity skin, updating hardshape and agressiv points. Add associated events to game. """ if self.valid_animation(anim_name): if 'entity' in params and params['entity'].upgraded: if anim_name + '_upgraded' in self.animations: self.current_animation = anim_name + '_upgraded' else: logging.debug( ' '.join((self.name, 'character has no upgraded version of ', anim_name, 'falling back to normal version'))) self.current_animation = anim_name else: self.current_animation = anim_name self.animation_change = True params['world'] = game params['gametime'] = game is not None or 0 params['anim_name'] = anim_name self.add_events(anim_name, game, params) #logging.debug(self.vectors[anim_name]) self.add_vectors(anim_name, game, params) if self.sounds[anim_name] != []: # XXX reactivate the try/except with the good exception when you # know it #try: loaders.track(random.choice(self.sounds[anim_name])).play() #except (Exception), e: #logging.warning(e) else: #logging.debug( "entity_skin "+self.name+" has no "+anim_name+"\ #animation.") pass
def change_animation(self, anim_name, game=None, params=dict()): """ Change animation of the entity skin, updating hardshape and agressiv points. Add associated events to game. """ if self.valid_animation(anim_name): if 'entity' in params and params['entity'].upgraded: if anim_name + '_upgraded' in self.animations: self.current_animation = anim_name + '_upgraded' else: logging.debug(' '.join( (self.name, 'character has no upgraded version of ', anim_name, 'falling back to normal version'))) self.current_animation = anim_name else: self.current_animation = anim_name self.animation_change = True params['world'] = game params['gametime'] = game is not None or 0 params['anim_name'] = anim_name self.add_events(anim_name, game, params) #logging.debug(self.vectors[anim_name]) self.add_vectors(anim_name, game, params) if self.sounds[anim_name] != []: # XXX reactivate the try/except with the good exception when you # know it #try: loaders.track(random.choice(self.sounds[anim_name])).play() #except (Exception), e: #logging.warning(e) else: #logging.debug( "entity_skin "+self.name+" has no "+anim_name+"\ #animation.") pass
def change_music(self, music, fading=True): """ This change the currently played music. With an optional fading. """ #logging.debug('launching music: '+str(music.get_length())) self.time_begin = time.time() if fading: if self.current_track: self.current_track.fadeout(3000) self.current_track = loaders.track(random.choice(music)) if self.current_track: self.current_track.set_volume( CONFIG.audio.MUSIC_VOLUME / 100.0) self.current_track.play(fade_ms=3000) else: self.current_track = music self.current_track.play()
def change_music(self, music, fading=True): """ This change the currently played music. With an optional fading. """ #logging.debug('launching music: '+str(music.get_length())) self.time_begin = time.time() if fading: if self.current_track: self.current_track.fadeout(3000) self.current_track = loaders.track(random.choice(music)) if self.current_track: self.current_track.set_volume(CONFIG.audio.MUSIC_VOLUME / 100.0) self.current_track.play(fade_ms=3000) else: self.current_track = music self.current_track.play()
def handle_reply(self, reply): """ This function handles the callback return by the screens with the function event_callback(). This callback needs to be a dictionary, otherwise, it will be ignored. The reply can be: {'goto': 'myscreen'} where my screen is the name of the screen loaded in __init__() {'goto': 'back'} go to the last menu, it is usually used for a back button {'game': 'new'} to start a new game {'game': 'new_server'} to start a new game in server mode {'game': 'join_server'} to join a network game {'game': 'continue'} to resume the game, it is used in the in-game menu {'game': 'stop' } to stop the game, it is used to qui the game in the in-game menu """ if hasattr(reply, 'get'): sound = loaders.track(os.path.join(CONFIG.system_path, "sounds", "mouseClick2.wav")) sound.set_volume(CONFIG.audio.SOUND_VOLUME / 100.0) sound.play() # not using elifs so that replies may be complex if reply.get('goto'): if reply['goto'] == 'back': self.screen_back() else: self.screen_history.append(self.current_screen) self.current_screen = reply['goto'] if reply.get('game'): if reply['game'] == 'new': self.game = self.launch_game() self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'new_server': self.game = self.launch_game(server=True) self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'join_server': self.game = self.launch_game( server=self.screens['network_join'].ip) self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'continue': self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'stop': self.state = "menu" self.game = None self.current_screen = 'main_screen' self.screen_history = []
def handle_reply(self, reply): """ This function handles the callback return by the screens with the function event_callback(). This callback needs to be a dictionary, otherwise, it will be ignored. The reply can be: {'goto': 'myscreen'} where my screen is the name of the screen loaded in __init__() {'goto': 'back'} go to the last menu, it is usually used for a back button {'game': 'new'} to start a new game {'game': 'new_server'} to start a new game in server mode {'game': 'join_server'} to join a network game {'game': 'continue'} to resume the game, it is used in the in-game menu {'game': 'stop' } to stop the game, it is used to qui the game in the in-game menu """ if hasattr(reply, 'get'): sound = loaders.track( os.path.join(CONFIG.system_path, "sounds", "mouseClick2.wav")) sound.set_volume(CONFIG.audio.SOUND_VOLUME / 100.0) sound.play() # not using elifs so that replies may be complex if reply.get('goto'): if reply['goto'] == 'back': self.screen_back() else: self.screen_history.append(self.current_screen) self.current_screen = reply['goto'] if reply.get('game'): if reply['game'] == 'new': self.game = self.launch_game() self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'new_server': self.game = self.launch_game(server=True) self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'join_server': self.game = self.launch_game( server=self.screens['network_join'].ip) self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'continue': self.current_screen = 'resume' self.screen_history = [] self.state = "menu" elif reply['game'] == 'stop': self.state = "menu" self.game = None self.current_screen = 'main_screen' self.screen_history = []