]> Untitled Git - axy/ft/pacman.git/commitdiff
Initial game implementation
authorThomas Rimelen <trimelen@k1r1p14.42mulhouse.fr>
Mon, 28 Sep 2026 15:14:38 +0000 (17:14 +0200)
committerThomas Rimelen <trimelen@k1r1p14.42mulhouse.fr>
Mon, 28 Sep 2026 15:14:38 +0000 (17:14 +0200)
config.json [deleted file]
score.json [deleted file]
src/pacman/__init__.py
src/pacman/game/__init__.py [new file with mode: 0644]

diff --git a/config.json b/config.json
deleted file mode 100644 (file)
index 39bbc53..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-{
-    "highscore_filename": "score.json",
-    "levels": 10,
-    "width": 20,
-    "height": 20,
-    "lives": 3,
-    "pacgum": 80,
-    "points_per_pacgum": 1,
-    "points_per_super_pacgum": 5,
-    "points_per_ghost": 20,
-    "time": 180,
-    "cheat_mod": false
-}
\ No newline at end of file
diff --git a/score.json b/score.json
deleted file mode 100644 (file)
index 02d2466..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-[
-    {
-        "name": "Garobert",
-        "score": 1
-    },
-    {
-        "name": "ssss",
-        "score": 0
-    },
-    {
-        "name": "player",
-        "score": 51
-    },
-    {
-        "name": "dd",
-        "score": 61
-    },
-    {
-        "name": "",
-        "score": 0
-    },
-    {
-        "name": "kkk",
-        "score": 0
-    }
-]
\ No newline at end of file
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a0c5722b7601558ec4a35ff2aab1a01dae539d9b 100644 (file)
@@ -0,0 +1,5 @@
+from pacman.game import run_game
+
+
+def main() -> None:
+    run_game()
diff --git a/src/pacman/game/__init__.py b/src/pacman/game/__init__.py
new file mode 100644 (file)
index 0000000..48a75f7
--- /dev/null
@@ -0,0 +1,67 @@
+import math
+from collections.abc import Callable
+from pathlib import Path
+
+import pygame
+from mazegenerator import MazeGenerator
+from pygame import Vector2, Vector3
+
+from pacman.ecs import minimal_plugins
+from pacman.ecs.assets import Assets
+from pacman.ecs.coord import Coord2D, CoordAbs2D
+from pacman.ecs.graphics import ShouldRender, Sprite2D, graphics_plugins
+from pacman.ecs.hierarchy import ChildOf
+from pacman.ecs.schedule import StartupSchedule, UpdateSchedule
+from pacman.ecs.world import Component, Entity, Query, World
+
+
+class Maze(Component):
+    pass
+
+
+def create_maze(
+    world: World, assets: Assets[Sprite2D]
+) -> Callable[[MazeGenerator], Entity]:
+    def inner(maze: MazeGenerator) -> Entity:
+        root = world.spawn(
+            tuple[Maze, Coord2D, CoordAbs2D], (Maze(), Coord2D(), CoordAbs2D())
+        )
+        cell_paths = [
+            [f"./asset/walls/{cell}.png" for cell in line]
+            for line in maze.maze
+        ]
+        cell_dims = Vector3(64, 64, 0)
+        cells = [
+            (
+                ChildOf(root),
+                Coord2D(cell_dims.elementwise() * Vector3(x, y, 0)),
+                CoordAbs2D(),
+                assets.load(cell),
+                ShouldRender(),
+            )
+            for y, line in enumerate(cell_paths)
+            for x, cell in enumerate(line)
+        ]
+        world.spawn_many(
+            tuple[ChildOf, Coord2D, CoordAbs2D, Sprite2D, ShouldRender], cells
+        )
+        return root
+
+    return inner
+
+
+def setup_maze(world: World) -> None:
+    world.add_system(create_maze)(MazeGenerator())
+
+
+def move_maze(mazes: Query[Coord2D, Maze]) -> None:
+    tick = pygame.time.get_ticks()
+    for coord in mazes:
+        n = 400
+        coord.y = n + n * math.sin(tick / 100)
+
+
+def run_game() -> None:
+    World().with_plugins(graphics_plugins, minimal_plugins).with_systems(
+        StartupSchedule, setup_maze
+    ).run_main()