def post_collision_handle(self, impulse, **data): impulse = impulse.length if impulse > 4000: AudioManager.play_sound('crate_wood_hit', self.pos, self.body.velocity, volume=impulse / 20000)
def update(dt): # USER EVENTS exit_code = userInput() if exit_code: return exit_code # PHYSIC AND UPDATE [!!! PHYSICS UPDATE FIXED AND NOT BASED ON FPS !!!] # TODO: JUST WARNING ^ puf = PHYSIC_UPDATE_FREQUENCY MainPhysicSpace.step(dt=puf) updateGroups(dt=puf) # SOUND AudioManager.update_listener(hero.pos, hero.body.velocity)
def initScreen(hero_life=True, first_load=False): AudioManager.reset_listener() AudioManager.set_stream('music', 'main_menu', True) global buttons, selected_button selected_button = 0 camera.set_filed(WINDOW_RECT) global first, exit_code, hero_is_alive exit_code, first, hero_is_alive = None, first_load, hero_is_alive MainFrame() buttons = [FullButton(700 - x * 100, x) for x in range(5)] Button.hover(0, -1)
def gameLoop(): global running, screen_type, start_time, seconds # Focus selected screen scr = screens[screen_type] # Visualization scr.render() # Update screen dt = clock.tick(FPS_LOCK) / 1000 exit_code = scr.update(dt) seconds += dt if seconds >= 1: seconds = 0.0 AudioManager.clear_empty_sources() # Profile.disable() # Profile.print_stats('cumtime') # running = False AudioManager.update_streams(dt) # Screen feedback if exit_code in {'menu', 'game', 'Quit'}: # if exit_code == 'game': # seconds = 0.0 # Profile.enable() if exit_code == 'Quit': running = False elif exit_code != screen_type: screen_type = exit_code screens[exit_code].initScreen() # End phase pg.display.flip() if FPS_SHOW: print(f'\rFPS: {clock.get_fps() // 1}', end='')
# if exit_code == 'game': # seconds = 0.0 # Profile.enable() if exit_code == 'Quit': running = False elif exit_code != screen_type: screen_type = exit_code screens[exit_code].initScreen() # End phase pg.display.flip() if FPS_SHOW: print(f'\rFPS: {clock.get_fps() // 1}', end='') if __name__ == '__main__': _main() import core.screens.menu as rmenu import core.screens.game as rgame screens = {'menu': rmenu, 'game': rgame} screens[screen_type].initScreen(first_load=True) while running: gameLoop() # finally AudioManager.destroy()
def closeMenu(): AudioManager.fade_stream('music', 2) decoration.delete_all() back.delete_all() buttons_group.delete_all()
def hover(this: int, prev: int): if -1 < prev <= buttons_count: buttons[prev].setTexture(0) buttons[this].setTexture(1) AudioManager.play_sound('menu_button_select', [0, 0, 0])