From: Thomas Rimelen Date: Mon, 12 Oct 2026 14:26:52 +0000 (+0200) Subject: main menu + fix X-Git-Url: https://git.uwuaxy.net/Project%20Status.png?a=commitdiff_plain;h=23fb95305f10a00072d70c4d35ffee120630ede2;p=axy%2Fft%2Fpacman.git main menu + fix --- diff --git a/src/pacman/ecs/gui.py b/src/pacman/ecs/gui.py index b5b3884..6fcac7a 100644 --- a/src/pacman/ecs/gui.py +++ b/src/pacman/ecs/gui.py @@ -21,7 +21,7 @@ from pacman.ecs.graphics import ( dir_lookup, ) from pacman.ecs.schedule import StartupSchedule, UpdateSchedule -from pacman.ecs.update import PostUpdate +from pacman.ecs.update import PostUpdate, PreUpdate from pacman.ecs.world import ( CommandQueue, Component, @@ -186,7 +186,5 @@ def gui_plugins(world: World) -> None: update_text_sprites, ) .chain() - .in_set(PostUpdate) - .before(GraphicsSystems) - .after(PropagateTransform), + .in_set(PreUpdate) ) diff --git a/src/pacman/ecs/world.py b/src/pacman/ecs/world.py index ce049c7..ddf30eb 100644 --- a/src/pacman/ecs/world.py +++ b/src/pacman/ecs/world.py @@ -769,14 +769,19 @@ class World(FromWorld): if ty is None: ty = type(comp) - type Ty = ty # type: ignore - - def remove(query: Query[Entity, Ty], world: World) -> None: - world.remove_many(ty, list(query)) - - self.run_raw_system(remove) + self.despawn_resource(ty) return self.spawn(ty, comp) + def despawn_resource[T: Resource]( + self, ty: type[T] + ) -> None: + type Ty = ty # type: ignore + + def remove(query: Query[Entity, Ty], world: World) -> None: + world.remove_many(ty, list(query)) + + self.run_raw_system(remove) + def spawn_many[T: Components]( self, ty: type[T], comps: list[T] ) -> list[Entity]: diff --git a/src/pacman/game/__init__.py b/src/pacman/game/__init__.py index 1e364d7..bc4e0bd 100644 --- a/src/pacman/game/__init__.py +++ b/src/pacman/game/__init__.py @@ -121,6 +121,18 @@ class GameState(Resource): lives: int = 3 +class MainMenu(Component): + pass + + +class GameMenu(Component): + pass + + +class GameGui(Component): + pass + + class PacGum(Component): pass @@ -711,6 +723,10 @@ def setup_new_maze(world: World) -> None: world.run_raw_system(sys) +def in_game(itr: Query[Maze]) -> bool: + return len(list(itr)) != 0 + + def level_is_finished( pacgums: Query[SuperPacGum | PacGum], _: Not[GameIsOver] ) -> bool: @@ -726,7 +742,7 @@ def victory( for maze in mazes: queue.queue(hierarchy.despawn_with_children(maze)) if state.level == 2: - queue.queue(lambda world: world.add_raw_system(game_over)()) + queue.queue(lambda world: world.run_raw_system(game_over)) return state.level += 1 state.lives += 1 @@ -784,9 +800,16 @@ def print_timer(state: GameState, config: Config) -> str: return f"{time // 60}" -def start_game() -> None: - print("Game started") - +def start_game( + world: World, + hierarchy: Hierarchy[tuple[()]], + menus: Query[Entity, MainMenu], +) -> None: + world.run_raw_system(setup_new_maze) + for menu in menus: + hierarchy.despawn_with_children(menu)(world) + world.despawn_resource(SelectedButton) + def quit_game(world: World) -> None: world.spawn_resource(WorldShouldExit()) @@ -868,20 +891,25 @@ def setup_text(world: World, fonts: Assets[Font]) -> None: start_game, ) - world.run_system( + quit_button = world.run_system( spawn_button, Vector2((1600 - 300) / 2, (1200 - 200) / 2 + 120), "Quit", quit_game, ) + world.spawn( + tuple[MainMenu, Children, CoordBundle], + (MainMenu(), Children((selected, quit_button)), CoordBundle()), + ) + world.spawn_resource(SelectedButton(selected)) def run_game() -> None: World().with_plugins(graphics_plugins, minimal_plugins).with_systems( StartupSchedule, - Systems(setup_resources, setup_new_maze, setup_text).chain(), + Systems(setup_resources, setup_text).chain(), ).with_systems( UpdateSchedule, Systems( @@ -895,7 +923,7 @@ def run_game() -> None: update_game_timer, ) .chain() - .run_if(initial_pause_done) + .run_if(initial_pause_done, in_game) .in_set(Update), Systems(update_pacman_anim, update_ghost_anim) .before(GraphicsSystems) @@ -908,6 +936,6 @@ def run_game() -> None: .chain() .after(PropagateTransform) .before(GraphicsSystems), - Systems(victory).run_if(level_is_finished), + Systems(victory).run_if(level_is_finished, in_game), Systems(lose).run_if(level_is_lost), ).run_main()