mini_arcade_core.scenes.systems.builtins.bomberman ================================================== .. py:module:: mini_arcade_core.scenes.systems.builtins.bomberman .. autoapi-nested-parse:: Reusable arena bomb/explosion helpers for Bomberman-style games. Classes ------- .. autoapisummary:: mini_arcade_core.scenes.systems.builtins.bomberman.ArenaTile mini_arcade_core.scenes.systems.builtins.bomberman.BombState mini_arcade_core.scenes.systems.builtins.bomberman.BombField mini_arcade_core.scenes.systems.builtins.bomberman.ExplosionCellState mini_arcade_core.scenes.systems.builtins.bomberman.ExplosionField mini_arcade_core.scenes.systems.builtins.bomberman.BombPlacementBinding mini_arcade_core.scenes.systems.builtins.bomberman.BombPlacementSystem mini_arcade_core.scenes.systems.builtins.bomberman.BombFuseBinding mini_arcade_core.scenes.systems.builtins.bomberman.BombFuseSystem mini_arcade_core.scenes.systems.builtins.bomberman.ExplosionLifetimeBinding mini_arcade_core.scenes.systems.builtins.bomberman.ExplosionLifetimeSystem mini_arcade_core.scenes.systems.builtins.bomberman.ChainReactionBinding mini_arcade_core.scenes.systems.builtins.bomberman.ChainReactionSystem mini_arcade_core.scenes.systems.builtins.bomberman.DestructibleTileBinding mini_arcade_core.scenes.systems.builtins.bomberman.DestructibleTileSystem mini_arcade_core.scenes.systems.builtins.bomberman.HazardCollisionBinding mini_arcade_core.scenes.systems.builtins.bomberman.HazardCollisionSystem Functions --------- .. autoapisummary:: mini_arcade_core.scenes.systems.builtins.bomberman.arena_tile_map_from_strings mini_arcade_core.scenes.systems.builtins.bomberman.is_walkable_arena_tile mini_arcade_core.scenes.systems.builtins.bomberman.blast_cells mini_arcade_core.scenes.systems.builtins.bomberman.spawn_explosion_from_bomb Module Contents --------------- .. py:class:: ArenaTile Bases: :py:obj:`str`, :py:obj:`enum.Enum` Common arena tile kinds for bomb-based grid games. .. py:attribute:: FLOOR :value: 'floor' .. py:attribute:: SOLID :value: 'solid' .. py:attribute:: BREAKABLE :value: 'breakable' .. py:attribute:: SPAWN :value: 'spawn' .. py:attribute:: VOID :value: 'void' .. py:function:: arena_tile_map_from_strings(*rows: str) -> mini_arcade_core.scenes.systems.builtins.maze.TileMap[ArenaTile] Build a common arena tile map from ASCII rows. .. py:function:: is_walkable_arena_tile(tile: ArenaTile | None) -> bool Return whether an arena tile can be entered by a player/enemy. .. py:class:: BombState Mutable bomb metadata stored in a bomb field. .. py:attribute:: cell :type: mini_arcade_core.scenes.systems.builtins.grid.GridCoord .. py:attribute:: fuse_seconds :type: float :value: 2.0 .. py:attribute:: blast_range :type: int :value: 2 .. py:attribute:: owner_id :type: int | None :value: None .. py:attribute:: payload :type: Any :value: None .. py:class:: BombField Dense bomb occupancy keyed by cell. .. py:attribute:: bombs :type: dict[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, BombState] .. py:method:: bomb_at(cell: mini_arcade_core.scenes.systems.builtins.grid.GridCoord) -> BombState | None Return the bomb currently occupying one cell, if any. .. py:method:: active_bombs() -> tuple[BombState, Ellipsis] Return all currently active bombs. .. py:method:: occupied_cells() -> tuple[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, Ellipsis] Return every cell that currently contains a bomb. .. py:method:: add(bomb: BombState) -> BombState Insert or replace a bomb entry and return it. .. py:method:: remove(cell: mini_arcade_core.scenes.systems.builtins.grid.GridCoord) -> BombState | None Remove and return the bomb at one cell, if present. .. py:method:: count_for_owner(owner_id: int | None) -> int Count bombs owned by a specific actor. .. py:class:: ExplosionCellState Mutable active explosion metadata for one cell. .. py:attribute:: ttl_seconds :type: float .. py:attribute:: owner_id :type: int | None :value: None .. py:attribute:: origin :type: mini_arcade_core.scenes.systems.builtins.grid.GridCoord | None :value: None .. py:attribute:: payload :type: Any :value: None .. py:class:: ExplosionField Dense active explosion occupancy keyed by cell. .. py:attribute:: cells :type: dict[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, ExplosionCellState] .. py:method:: cell_at(cell: mini_arcade_core.scenes.systems.builtins.grid.GridCoord) -> ExplosionCellState | None Return the explosion metadata for one cell, if active. .. py:method:: active_cells() -> tuple[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, Ellipsis] Return the cells currently covered by an active explosion. .. py:method:: set_or_refresh(cell: mini_arcade_core.scenes.systems.builtins.grid.GridCoord, *, ttl_seconds: float, owner_id: int | None = None, origin: mini_arcade_core.scenes.systems.builtins.grid.GridCoord | None = None, payload: Any = None) -> ExplosionCellState Create or refresh the active explosion metadata for one cell. .. py:method:: tick(dt: float) -> tuple[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, Ellipsis] Advance explosion lifetimes and return the cells that expired. .. py:function:: blast_cells(tile_map: mini_arcade_core.scenes.systems.builtins.maze.TileMap[ArenaTile], origin: mini_arcade_core.scenes.systems.builtins.grid.GridCoord, *, blast_range: int) -> tuple[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, Ellipsis] Compute explosion coverage from one bomb origin. .. py:function:: spawn_explosion_from_bomb(explosions: ExplosionField, tile_map: mini_arcade_core.scenes.systems.builtins.maze.TileMap[ArenaTile], bomb: BombState, *, ttl_seconds: float) -> tuple[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, Ellipsis] Populate explosion cells from one bomb and return covered cells. .. py:class:: BombPlacementBinding Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Declarative bomb placement rule. .. py:attribute:: should_place :type: Callable[[TCtx], bool] .. py:attribute:: placement_cell_getter :type: Callable[[TCtx], mini_arcade_core.scenes.systems.builtins.grid.GridCoord] .. py:attribute:: bombs_getter :type: Callable[[TCtx], BombField] .. py:attribute:: tile_map_getter :type: Callable[[TCtx], mini_arcade_core.scenes.systems.builtins.maze.TileMap[ArenaTile]] .. py:attribute:: build_bomb :type: Callable[[TCtx, mini_arcade_core.scenes.systems.builtins.grid.GridCoord], BombState] .. py:attribute:: owner_id_getter :type: Callable[[TCtx], int | None] .. py:attribute:: max_active_getter :type: Callable[[TCtx], int] .. py:attribute:: on_placed :type: Callable[[TCtx, BombState], None] | None :value: None .. py:class:: BombPlacementSystem Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Place bombs onto walkable floor cells when rules allow. .. py:attribute:: name :type: str :value: 'common_bomb_placement' .. py:attribute:: phase :type: int .. py:attribute:: order :type: int :value: 24 .. py:attribute:: enabled_when :type: Callable[[TCtx], bool] .. py:attribute:: bindings :type: tuple[BombPlacementBinding[TCtx], Ellipsis] :value: () .. py:method:: step(ctx: TCtx) -> None Place bombs for every binding whose placement rule passes. .. py:class:: BombFuseBinding Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Declarative fuse ticking and detonation rule. .. py:attribute:: bombs_getter :type: Callable[[TCtx], BombField] .. py:attribute:: on_detonated :type: Callable[[TCtx, BombState], None] | None :value: None .. py:class:: BombFuseSystem Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Tick bomb fuses and emit detonation callbacks when they expire. .. py:attribute:: name :type: str :value: 'common_bomb_fuse' .. py:attribute:: phase :type: int .. py:attribute:: order :type: int :value: 32 .. py:attribute:: enabled_when :type: Callable[[TCtx], bool] .. py:attribute:: bindings :type: tuple[BombFuseBinding[TCtx], Ellipsis] :value: () .. py:method:: step(ctx: TCtx) -> None Advance bomb fuses and notify bindings when bombs detonate. .. py:class:: ExplosionLifetimeBinding Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Declarative active-explosion lifetime rule. .. py:attribute:: explosions_getter :type: Callable[[TCtx], ExplosionField] .. py:attribute:: on_expired :type: Callable[[TCtx, tuple[mini_arcade_core.scenes.systems.builtins.grid.GridCoord, Ellipsis]], None] | None :value: None .. py:class:: ExplosionLifetimeSystem Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Tick active explosion cells until they expire. .. py:attribute:: name :type: str :value: 'common_explosion_lifetime' .. py:attribute:: phase :type: int .. py:attribute:: order :type: int :value: 38 .. py:attribute:: enabled_when :type: Callable[[TCtx], bool] .. py:attribute:: bindings :type: tuple[ExplosionLifetimeBinding[TCtx], Ellipsis] :value: () .. py:method:: step(ctx: TCtx) -> None Tick active explosion cells and emit expiration callbacks. .. py:class:: ChainReactionBinding Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Declarative bomb chain-reaction rule. .. py:attribute:: bombs_getter :type: Callable[[TCtx], BombField] .. py:attribute:: explosions_getter :type: Callable[[TCtx], ExplosionField] .. py:attribute:: on_triggered :type: Callable[[TCtx, BombState], None] | None :value: None .. py:class:: ChainReactionSystem Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Trigger bombs early when an active explosion reaches them. .. py:attribute:: name :type: str :value: 'common_chain_reaction' .. py:attribute:: phase :type: int .. py:attribute:: order :type: int :value: 34 .. py:attribute:: enabled_when :type: Callable[[TCtx], bool] .. py:attribute:: bindings :type: tuple[ChainReactionBinding[TCtx], Ellipsis] :value: () .. py:method:: step(ctx: TCtx) -> None Detonate bombs early when an active blast reaches them. .. py:class:: DestructibleTileBinding Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Declarative breakable-tile destruction rule. .. py:attribute:: tile_map_getter :type: Callable[[TCtx], mini_arcade_core.scenes.systems.builtins.maze.TileMap[ArenaTile]] .. py:attribute:: explosions_getter :type: Callable[[TCtx], ExplosionField] .. py:attribute:: replacement_tile :type: ArenaTile .. py:attribute:: on_destroyed :type: Callable[[TCtx, mini_arcade_core.scenes.systems.builtins.grid.GridCoord], None] | None :value: None .. py:class:: DestructibleTileSystem Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Destroy breakable tiles touched by active explosion cells. .. py:attribute:: name :type: str :value: 'common_destructible_tiles' .. py:attribute:: phase :type: int .. py:attribute:: order :type: int :value: 36 .. py:attribute:: enabled_when :type: Callable[[TCtx], bool] .. py:attribute:: bindings :type: tuple[DestructibleTileBinding[TCtx], Ellipsis] :value: () .. py:method:: step(ctx: TCtx) -> None Replace breakable tiles touched by active explosion cells. .. py:class:: HazardCollisionBinding Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Declarative explosion hazard collision rule. .. py:attribute:: hazard_cells_getter :type: Callable[[TCtx], Iterable[mini_arcade_core.scenes.systems.builtins.grid.GridCoord]] .. py:attribute:: targets_getter :type: Callable[[TCtx], Iterable[object]] .. py:attribute:: target_cell_getter :type: Callable[[TCtx, object], mini_arcade_core.scenes.systems.builtins.grid.GridCoord] .. py:attribute:: on_hit :type: Callable[[TCtx, object, mini_arcade_core.scenes.systems.builtins.grid.GridCoord], None] .. py:class:: HazardCollisionSystem Bases: :py:obj:`Generic`\ [\ :py:obj:`TCtx`\ ] Invoke callbacks for targets occupying active hazard cells. .. py:attribute:: name :type: str :value: 'common_hazard_collision' .. py:attribute:: phase :type: int .. py:attribute:: order :type: int :value: 37 .. py:attribute:: enabled_when :type: Callable[[TCtx], bool] .. py:attribute:: bindings :type: tuple[HazardCollisionBinding[TCtx], Ellipsis] :value: () .. py:method:: step(ctx: TCtx) -> None Invoke hit callbacks for targets occupying active hazard cells.