def load_game_loop(window: sf.RenderWindow, input_clock=sf.Clock(), cursor=0): name = '' password = '' password_md5 = 'd41d8cd98f00b204e9800998ecf8427e' typing_text = False while True: for event in window.events: if event.type == sf.Event.RELEASED: window.close() exit() if typing_text: if cursor == 0: name += input.text.text_input(input_clock) elif cursor == 1: password += input.text.text_input(input_clock) password_md5 = hashlib.md5(password.encode()).hexdigest() else: game_loop(window, get_player_identifier(name, password_md5)) if input.key.key_pressed(input.key.Key.BACK_SPACE, input_clock): if cursor == 0: name = name[:-1] elif cursor == 1: password = password[:-1] if input.key.key_pressed(input.key.Key.RETURN, input_clock): print(name) print(password_md5) typing_text = False else: if input.key.key_pressed(input.key.Key.DOWN, input_clock): cursor = (cursor + 1) % 3 elif input.key.key_pressed(input.key.Key.UP, input_clock): cursor = (cursor - 1) % 3 if input.key.key_pressed(input.key.Key.RETURN, input_clock): if cursor == 0 or cursor == 1: typing_text = True if cursor == 2: player = get_player_identifier(name, password_md5) break draw.draw_load_game_menu(window, cursor, name) window.display() if cursor == 2: del password load_maps() game_loop(window, player, input_clock)
def game_loop(window: sf.RenderWindow, player: int, input_clock=sf.Clock()): moving = 0 running = conf.auto_run menu = False cursor = 0 direction = world.Direction.DOWN battle = None while True: for event in window.events: if event.type == sf.Event.RELEASED: window.close() exit() if battle is not None: draw.draw_battle(window, player, battle) window.display() else: if moving: moving -= 2 + int(running) if moving <= 0: moving = 0 world.activate_walk_event(player) elif menu: if input.key.key_pressed(input.key.Key.DOWN, input_clock): cursor = (cursor + 1) % 3 elif input.key.key_pressed(input.key.Key.UP, input_clock): cursor = (cursor - 1) % 3 elif input.key.key_pressed(input.key.Key.MENU, input_clock): menu = False else: if input.key.key_pressed(input.key.Key.RIGHT, input_clock): moving, direction, battle = world.move_player(player, world.Direction.RIGHT) elif input.key.key_pressed(input.key.Key.UP, input_clock): moving, direction, battle = world.move_player(player, world.Direction.UP) elif input.key.key_pressed(input.key.Key.LEFT, input_clock): moving, direction, battle = world.move_player(player, world.Direction.LEFT) elif input.key.key_pressed(input.key.Key.DOWN, input_clock): moving, direction, battle = world.move_player(player, world.Direction.DOWN) elif input.key.key_pressed(input.key.Key.MENU, input_clock): menu = True draw.draw_game(window, player, moving, direction.value) if menu: draw.draw_game_menu(window, player, cursor) window.display() music.play_music(player)
def main_menu_loop(window: sf.RenderWindow, input_clock=sf.Clock()): cursor = 0 while True: for event in window.events: if event.type == sf.Event.RELEASED: window.close() exit() if input.key.key_pressed(input.key.Key.DOWN, input_clock): cursor = (cursor + 1) % 3 elif input.key.key_pressed(input.key.Key.UP, input_clock): cursor = (cursor - 1) % 3 if input.key.key_pressed(input.key.Key.RETURN, input_clock): if cursor == 2: window.close() exit() else: break draw.draw_main_menu(window, cursor) window.display() if cursor == 0: load_players() load_game_loop(window, input_clock)