diff --git a/engine.py b/engine.py index e639be2..f3c3890 100644 --- a/engine.py +++ b/engine.py @@ -1,4 +1,4 @@ -from typing import Set, Iterable, Any +from typing import Iterable, Any from tcod.context import Context from tcod.console import Console @@ -12,12 +12,10 @@ from input_handlers import EventHandler class Engine: def __init__( self, - entities: Set[Entity], event_handler: EventHandler, game_map: GameMap, player: Entity ): - self.entities = entities self.event_handler = event_handler self.game_map = game_map self.player = player @@ -49,11 +47,6 @@ class Engine: def render(self, console: Console, context: Context) -> None: self.game_map.render(console) - for entity in self.entities: - # Only print entities that are in FOV - if self.game_map.visible[entity.x, entity.y]: - console.print(entity.x, entity.y, entity.char, fg=entity.color) - # Actually output to screen context.present(console) console.clear() diff --git a/game_map.py b/game_map.py index 3e81a28..6c43059 100644 --- a/game_map.py +++ b/game_map.py @@ -1,12 +1,20 @@ +from __future__ import annotations + +from typing import Iterable, TYPE_CHECKING + import numpy as np # type: ignore from tcod.console import Console import tile_types +if TYPE_CHECKING: + from entity import Entity + class GameMap: - def __init__(self, width: int, height: int): + def __init__(self, width: int, height: int, entities: Iterable[Entity] = ()): self.width, self.height = width, height + self.entities = entities self.tiles = np.full((width, height), fill_value=tile_types.wall, order="F") self.visible = np.full((width, height), fill_value=False, order="F") # Tiles the player can currently see @@ -31,3 +39,8 @@ class GameMap: choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD ) + + for entity in self.entities: + # Only print entities that are in the FOV + if self.visible[entity.x, entity.y]: + console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color) diff --git a/main.py b/main.py index 9671b48..f69545e 100755 --- a/main.py +++ b/main.py @@ -28,8 +28,6 @@ def main() -> None: event_handler = EventHandler() player = Entity(int(screen_width / 2), int(screen_height / 2), "@", (255, 255, 255)) - npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@", (255, 255, 0)) - entities = {npc, player} game_map = generate_dungeon( max_rooms, @@ -40,7 +38,7 @@ def main() -> None: player, ) - engine = Engine(entities, event_handler, game_map, player) + engine = Engine(event_handler, game_map, player) with tcod.context.new_terminal( screen_width, diff --git a/procgen.py b/procgen.py index e042cd5..c746e89 100644 --- a/procgen.py +++ b/procgen.py @@ -69,7 +69,7 @@ def generate_dungeon( player: Entity, ) -> GameMap: """Generate a new dungeon map.""" - dungeon = GameMap(map_width, map_height) + dungeon = GameMap(map_width, map_height, entities=[player]) rooms: List[RectangularRoom] = []