]> Untitled Git - axy/ft/pacman.git/commitdiff
minor cleanup
author= <=>
Thu, 17 Sep 2026 14:14:57 +0000 (16:14 +0200)
committer= <=>
Thu, 17 Sep 2026 14:14:57 +0000 (16:14 +0200)
src/pacman/ecs/__init__.py

index 71428a42671275076264d0063dcfff2acc851d8a..e4a15e670c618d3d8406fa6dd7659d0697a969c4 100644 (file)
@@ -5,7 +5,7 @@ from time import time
 from typing import Any, Literal, cast, overload
 
 import pygame
-from pygame import Vector2
+from pygame import Vector2, Vector3
 
 from pacman.ecs.hierarchy import (
     Children,
@@ -58,16 +58,14 @@ class CoordAbs2D:
         self.depth = 0.0
 
 
-@dataclass
-class Coord2D:
-    vec: Vector2
-    depth: float
+class Coord2D(Vector3):
+    pass
 
 
 def update_coord(world: World) -> None:
     for abs_coord, coord in world.query(tuple[CoordAbs2D, Coord2D]):
-        abs_coord.vec = coord.vec.copy()
-        abs_coord.depth = coord.depth
+        abs_coord.vec = coord.xy
+        abs_coord.depth = coord.z
 
 
 def update_coord_hierarchy(world: World) -> None:
@@ -165,8 +163,8 @@ def move_sprites(world: World) -> None:
 
     time = pygame.time.get_ticks() / 100
     for coord, _ in world[tuple[Coord2D, WiggleSprite]]:
-        pos = max(time - coord.depth * 0.3, 0.0)
-        coord.vec.y = 500.0 + math.sin(pos) * 30.0
+        pos = max(time - coord.z * 0.3, 0.0)
+        coord.y = 500.0 + math.sin(pos) * 30.0
 
 
 class WiggleRoot:
@@ -178,7 +176,7 @@ def move_root(world: World) -> None:
 
     time = pygame.time.get_ticks() / 100
     for coord, _ in world[tuple[Coord2D, WiggleRoot]]:
-        coord.vec.x = 30.0 + math.cos(time) * 30.0
+        coord.x = 30.0 + math.cos(time) * 30.0
 
 
 if __name__ == "__main__":
@@ -190,7 +188,7 @@ if __name__ == "__main__":
     assets = list(Path("./asset").rglob("*.png"))
     root = Entity()
     world[root] = (
-        Coord2D(Vector2(100.0, 0.0), 0.0),
+        Coord2D(100.0, 0.0, 0.0),
         CoordAbs2D(),
         WiggleRoot(),
     )
@@ -199,7 +197,7 @@ if __name__ == "__main__":
             i += j
             i = i % len(assets)
             world[Entity()] = (
-                Coord2D(Vector2(30.0 * i, 500.0 + 10.0), 1.0 * i + j),
+                Coord2D(30.0 * i, 500.0 + 10.0, 1.0 * i + j),
                 CoordAbs2D(),
                 Sprite2D(pygame.image.load(asset)),
                 ShouldRender(),