rogueliketutorials/engine.py

47 lines
1.2 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from tcod.context import Context
from tcod.console import Console
from tcod.map import compute_fov
from input_handlers import MainGameEventHandler
if TYPE_CHECKING:
from entity import Actor
from input_handlers import EventHandler
from game_map import GameMap
class Engine:
gamemap: GameMap
def __init__(self, player: Actor):
self.event_handler: EventHandler = MainGameEventHandler(self)
self.player = player
def handle_enemy_turns(self) -> None:
for entity in set(self.gamemap.actors) - {self.player}:
if entity.ai:
entity.ai.perform()
def update_fov(self) -> None:
self.gamemap.visible[:] = compute_fov(
self.gamemap.tiles["transparent"],
(self.player.x, self.player.y),
radius=8,
)
self.gamemap.explored |= self.gamemap.visible
def render(self, console: Console, context: Context) -> None:
self.gamemap.render(console)
console.print(
x=1,
y=47,
string=f"HP: {self.player.fighter.hp}/{self.player.fighter.max_hp}",
)
context.present(console)
console.clear()