From: Thomas Rimelen Date: Mon, 19 Oct 2026 11:54:49 +0000 (+0200) Subject: Highscores and instruction added to main menu X-Git-Url: https://git.uwuaxy.net/Project%20Status.png?a=commitdiff_plain;h=c70e47f4d257cf3733a8b0057b7f16d7eb60661d;p=axy%2Fft%2Fpacman.git Highscores and instruction added to main menu --- diff --git a/highscores.json b/highscores.json index 28f485b..2ff216e 100644 --- a/highscores.json +++ b/highscores.json @@ -1,7 +1,7 @@ { "scores": { - "A": 10, - "B": 30, - "C": 20 + "Axel": 30, + "Thomas": 20, + "Garobert": 1 } } \ No newline at end of file diff --git a/src/pacman/game/__init__.py b/src/pacman/game/__init__.py index 87473fb..bebebbd 100644 --- a/src/pacman/game/__init__.py +++ b/src/pacman/game/__init__.py @@ -1021,11 +1021,113 @@ def setup_game_menu( world.spawn_resource(SelectedButton(selected)) -def set_up_highsores(world: World, scores: Highscores) -> Entity: - return world.spawn_empty() +def set_up_instructions(world: World, fonts: Assets[Font]) -> list[Entity]: + text = """Use 'WASD'to move pacman in the maze. +Collect all pacgums to go to the next level. +Complete all levels to win the game. +If a ghost touch pacman you lose a life. +If your lives reach 0 the game is over. +If the timer reach 0 the game is over. +When you eat a super pacgum, you can eat ghost. +""" + entities = [ + world.spawn( + tuple[ + WindowPositionned, + ShouldRender, + TextDisplay, + ], + ( + WindowPositionned(Vector2(0, 0), Vector2(50, 100)), + ShouldRender(), + TextDisplay( + "Instructions", + fonts.load("./asset/fonts/JetBrainsMonoNL-Regular.ttf:50"), + ), + ), + ) + ] + + entities.extend( + world.spawn_many( + tuple[ + WindowPositionned, + ShouldRender, + TextDisplay, + ], + [ + ( + WindowPositionned( + Vector2(0, 0), Vector2(50, 200 + i * 50) + ), + ShouldRender(), + TextDisplay( + s, + fonts.load( + "./asset/fonts/JetBrainsMonoNL-Regular.ttf:20" + ), + ), + ) + for i, s in enumerate(text.split("\n")) + ], + ) + ) + + return entities + + +def set_up_highsores( + world: World, scores: Highscores, fonts: Assets[Font] +) -> list[Entity]: + highscores = [(name, value) for name, value in scores.scores.items()] + highscores.sort(key=lambda x: x[1], reverse=True) + entities = [ + world.spawn( + tuple[ + WindowPositionned, + ShouldRender, + TextDisplay, + ], + ( + WindowPositionned(Vector2(1, 0), Vector2(-400, 100)), + ShouldRender(), + TextDisplay( + "Highscores", + fonts.load("./asset/fonts/JetBrainsMonoNL-Regular.ttf:50"), + ), + ), + ) + ] + entities.extend( + world.spawn_many( + tuple[ + WindowPositionned, + ShouldRender, + TextDisplay, + ], + [ + ( + WindowPositionned( + Vector2(1, 0), Vector2(-380, 200 + i * 70) + ), + ShouldRender(), + TextDisplay( + f"{i + 1}. {highscores[i][0]} - {highscores[i][1]}", + fonts.load( + "./asset/fonts/JetBrainsMonoNL-Regular.ttf:30" + ), + ), + ) + for i in range(min(len(highscores), 10)) + ], + ) + ) + + return entities def setup_main_menu(world: World) -> None: + selected = world.run_system( spawn_button, WindowPositionned(Vector2(0.5), Vector2(-150, -100)), @@ -1033,18 +1135,23 @@ def setup_main_menu(world: World) -> None: start_game, ) - quit_button = world.run_system( - spawn_button, - WindowPositionned(Vector2(0.5), Vector2(-150, 20)), - "Quit", - quit_game, + entities = [selected] + + entities.append( + world.run_system( + spawn_button, + WindowPositionned(Vector2(0.5), Vector2(-150, 20)), + "Quit", + quit_game, + ) ) - scores = world.run_raw_system(set_up_highsores) + entities.extend(world.run_raw_system(set_up_highsores)) + entities.extend(world.run_raw_system(set_up_instructions)) world.spawn( tuple[MainMenu, Children, CoordBundle], - (MainMenu(), Children((selected, quit_button, scores)), CoordBundle()), + (MainMenu(), Children(entities), CoordBundle()), ) world.spawn_resource(SelectedButton(selected))