def init(fname): mixer.init(22050, -16, 2, 1024) music.load(fname) music.rewind() music.play() music.pause() music.rewind()
def level_menu(g, keys): if keys[K_r]: g.restart_game() g.mode = F_GAME if (g.opt_music == True): music.rewind() music.play(-1) if keys[K_q]: g.mode = F_MAIN_MENU if (g.opt_music == True): music.load(os.path.join(media_folder, 'main_menu_music.wav')) music.play(-1) g.menu_timer -= g.dt if g.menu_timer <= 0: if keys[K_RETURN]: g.level_menu.function[g.level_menu.text.new_pos - g.level_menu.text.offset_title_select](g) g.menu_timer = MENU_INPUT_DELAY if keys[K_UP]: if (g.opt_sfx is True): g.sound_move_cursor.play() g.level_menu.text.move_up() g.menu_timer = MENU_INPUT_DELAY if keys[K_DOWN]: if (g.opt_sfx is True): g.sound_move_cursor.play() g.level_menu.text.move_down() g.menu_timer = MENU_INPUT_DELAY
def restart_level(g): g.restart_level() g.mode = F_GAME music.rewind() if (g.opt_sfx is True): g.sound_select.play() if (g.opt_music == True): music.play(-1)
def switch_sound(g): if (g.opt_music == False): g.opt_music = True if (g.opt_sfx is True): g.sound_on.play() if (g.previous_mode == F_MAIN_MENU): # music.play(-1) music.rewind() music.unpause() # else : else: if (g.opt_sfx is True): g.sound_off.play() g.opt_music = False music.pause()
def general(g, keys): if keys[K_ESCAPE]: sys.exit(0) if (g.mode == F_GAME): g.menu_timer -= g.dt if (g.menu_timer <= 0): if keys[K_m]: if (g.opt_music == False): g.opt_music = True if (g.opt_sfx is True): g.sound_on.play() if ((g.mode != F_GAME and g.previous_mode == F_MAIN_MENU) or g.mode == F_GAME): # music.play(-1) music.rewind() music.unpause() else: if (g.opt_sfx is True): g.sound_off.play() g.opt_music = False music.pause() g.menu_timer = MENU_INPUT_DELAY