From: = <=> Date: Thu, 17 Sep 2026 14:14:57 +0000 (+0200) Subject: minor cleanup X-Git-Url: https://git.uwuaxy.net/sitemap.xml?a=commitdiff_plain;h=8773e7daf33f8da3fe795ffdddc83cf3a39f2da8;p=axy%2Fft%2Fpacman.git minor cleanup --- diff --git a/src/pacman/ecs/__init__.py b/src/pacman/ecs/__init__.py index 71428a4..e4a15e6 100644 --- a/src/pacman/ecs/__init__.py +++ b/src/pacman/ecs/__init__.py @@ -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(),