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]:
lives: int = 3
+class MainMenu(Component):
+ pass
+
+
+class GameMenu(Component):
+ pass
+
+
+class GameGui(Component):
+ pass
+
+
class PacGum(Component):
pass
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:
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
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())
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(
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)
.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()