]> Untitled Git - axy/ft/pacman.git/commitdiff
Highscores and instruction added to main menu
authorThomas Rimelen <trimelen@k1r1p12.42mulhouse.fr>
Mon, 19 Oct 2026 11:54:49 +0000 (13:54 +0200)
committerThomas Rimelen <trimelen@k1r1p12.42mulhouse.fr>
Mon, 19 Oct 2026 11:54:49 +0000 (13:54 +0200)
highscores.json
src/pacman/game/__init__.py

index 28f485b80a9115d35dba70d5d8c88734c322db0a..2ff216e6bf67fc3f3b7050c345b736ded4a29d03 100644 (file)
@@ -1,7 +1,7 @@
 {
     "scores": {
-        "A": 10,
-        "B": 30,
-        "C": 20
+        "Axel": 30,
+        "Thomas": 20,
+        "Garobert": 1
     }
 }
\ No newline at end of file
index 87473fbf43f810e363bb9cd7134d88c813c20cb7..bebebbdff75fc9613e09228c36a9c73f652c5b14 100644 (file)
@@ -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))