From: Thomas Rimelen Date: Mon, 28 Sep 2026 15:14:38 +0000 (+0200) Subject: Initial game implementation X-Git-Url: https://git.uwuaxy.net/Project%20Status.png?a=commitdiff_plain;h=c4714ef474caa32ebd730ab711d216c73ca43418;p=axy%2Fft%2Fpacman.git Initial game implementation --- diff --git a/config.json b/config.json deleted file mode 100644 index 39bbc53..0000000 --- a/config.json +++ /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 index 02d2466..0000000 --- a/score.json +++ /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 diff --git a/src/pacman/__init__.py b/src/pacman/__init__.py index e69de29..a0c5722 100644 --- a/src/pacman/__init__.py +++ b/src/pacman/__init__.py @@ -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 index 0000000..48a75f7 --- /dev/null +++ b/src/pacman/game/__init__.py @@ -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()