world.spawn_resource(SelectedButton(selected))
-def set_up_highsores(world: World, scores: Highscores) -> Entity:
- return world.spawn_empty()
+def set_up_instructions(world: World, fonts: Assets[Font]) -> list[Entity]:
+ text = """Use 'WASD'to move pacman in the maze.
+Collect all pacgums to go to the next level.
+Complete all levels to win the game.
+If a ghost touch pacman you lose a life.
+If your lives reach 0 the game is over.
+If the timer reach 0 the game is over.
+When you eat a super pacgum, you can eat ghost.
+"""
+ entities = [
+ world.spawn(
+ tuple[
+ WindowPositionned,
+ ShouldRender,
+ TextDisplay,
+ ],
+ (
+ WindowPositionned(Vector2(0, 0), Vector2(50, 100)),
+ ShouldRender(),
+ TextDisplay(
+ "Instructions",
+ fonts.load("./asset/fonts/JetBrainsMonoNL-Regular.ttf:50"),
+ ),
+ ),
+ )
+ ]
+
+ entities.extend(
+ world.spawn_many(
+ tuple[
+ WindowPositionned,
+ ShouldRender,
+ TextDisplay,
+ ],
+ [
+ (
+ WindowPositionned(
+ Vector2(0, 0), Vector2(50, 200 + i * 50)
+ ),
+ ShouldRender(),
+ TextDisplay(
+ s,
+ fonts.load(
+ "./asset/fonts/JetBrainsMonoNL-Regular.ttf:20"
+ ),
+ ),
+ )
+ for i, s in enumerate(text.split("\n"))
+ ],
+ )
+ )
+
+ return entities
+
+
+def set_up_highsores(
+ world: World, scores: Highscores, fonts: Assets[Font]
+) -> list[Entity]:
+ highscores = [(name, value) for name, value in scores.scores.items()]
+ highscores.sort(key=lambda x: x[1], reverse=True)
+ entities = [
+ world.spawn(
+ tuple[
+ WindowPositionned,
+ ShouldRender,
+ TextDisplay,
+ ],
+ (
+ WindowPositionned(Vector2(1, 0), Vector2(-400, 100)),
+ ShouldRender(),
+ TextDisplay(
+ "Highscores",
+ fonts.load("./asset/fonts/JetBrainsMonoNL-Regular.ttf:50"),
+ ),
+ ),
+ )
+ ]
+ entities.extend(
+ world.spawn_many(
+ tuple[
+ WindowPositionned,
+ ShouldRender,
+ TextDisplay,
+ ],
+ [
+ (
+ WindowPositionned(
+ Vector2(1, 0), Vector2(-380, 200 + i * 70)
+ ),
+ ShouldRender(),
+ TextDisplay(
+ f"{i + 1}. {highscores[i][0]} - {highscores[i][1]}",
+ fonts.load(
+ "./asset/fonts/JetBrainsMonoNL-Regular.ttf:30"
+ ),
+ ),
+ )
+ for i in range(min(len(highscores), 10))
+ ],
+ )
+ )
+
+ return entities
def setup_main_menu(world: World) -> None:
+
selected = world.run_system(
spawn_button,
WindowPositionned(Vector2(0.5), Vector2(-150, -100)),
start_game,
)
- quit_button = world.run_system(
- spawn_button,
- WindowPositionned(Vector2(0.5), Vector2(-150, 20)),
- "Quit",
- quit_game,
+ entities = [selected]
+
+ entities.append(
+ world.run_system(
+ spawn_button,
+ WindowPositionned(Vector2(0.5), Vector2(-150, 20)),
+ "Quit",
+ quit_game,
+ )
)
- scores = world.run_raw_system(set_up_highsores)
+ entities.extend(world.run_raw_system(set_up_highsores))
+ entities.extend(world.run_raw_system(set_up_instructions))
world.spawn(
tuple[MainMenu, Children, CoordBundle],
- (MainMenu(), Children((selected, quit_button, scores)), CoordBundle()),
+ (MainMenu(), Children(entities), CoordBundle()),
)
world.spawn_resource(SelectedButton(selected))