2022-01-07 16:25:07 -05:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
2022-01-06 11:28:03 -05:00
|
|
|
|
|
|
|
from tcod.context import Context
|
|
|
|
from tcod.console import Console
|
2022-01-07 14:18:47 -05:00
|
|
|
from tcod.map import compute_fov
|
2022-01-06 11:28:03 -05:00
|
|
|
|
2022-01-10 14:22:33 -05:00
|
|
|
from input_handlers import MainGameEventHandler
|
2022-01-11 16:08:57 -05:00
|
|
|
from message_log import MessageLog
|
2022-01-11 16:21:42 -05:00
|
|
|
from render_functions import render_bar, render_names_at_mouse_location
|
2022-01-06 11:28:03 -05:00
|
|
|
|
2022-01-07 16:25:07 -05:00
|
|
|
if TYPE_CHECKING:
|
2022-01-10 14:13:01 -05:00
|
|
|
from entity import Actor
|
2022-01-07 16:25:07 -05:00
|
|
|
from game_map import GameMap
|
|
|
|
|
2022-01-06 11:28:03 -05:00
|
|
|
|
|
|
|
class Engine:
|
2022-01-07 16:25:07 -05:00
|
|
|
game_map: GameMap
|
|
|
|
|
2022-01-10 14:13:01 -05:00
|
|
|
def __init__(self, player: Actor):
|
2022-01-10 14:22:33 -05:00
|
|
|
self.event_handler: EventHandler = MainGameEventHandler(self)
|
2022-01-11 16:08:57 -05:00
|
|
|
self.message_log = MessageLog()
|
2022-01-11 16:21:42 -05:00
|
|
|
self.mouse_location = (0, 0)
|
2022-01-06 11:28:03 -05:00
|
|
|
self.player = player
|
|
|
|
|
2022-01-07 15:55:08 -05:00
|
|
|
def handle_enemy_turns(self) -> None:
|
2022-01-10 13:21:17 -05:00
|
|
|
for entity in set(self.game_map.actors) - {self.player}:
|
|
|
|
if entity.ai:
|
|
|
|
entity.ai.perform()
|
2022-01-07 15:55:08 -05:00
|
|
|
|
2022-01-07 14:18:47 -05:00
|
|
|
def update_fov(self) -> None:
|
|
|
|
"""Recompute the visible area based on the player's point of view."""
|
|
|
|
self.game_map.visible[:] = compute_fov(
|
|
|
|
self.game_map.tiles["transparent"],
|
|
|
|
(self.player.x, self.player.y),
|
|
|
|
radius=8,
|
|
|
|
)
|
|
|
|
|
|
|
|
# If a tile is "visible" it should be added to "explored"
|
|
|
|
self.game_map.explored |= self.game_map.visible
|
|
|
|
|
2022-01-11 16:21:42 -05:00
|
|
|
def render(self, console: Console) -> None:
|
2022-01-06 11:56:08 -05:00
|
|
|
self.game_map.render(console)
|
|
|
|
|
2022-01-11 16:08:57 -05:00
|
|
|
self.message_log.render(console=console, x=21, y=45, width=40, height=5)
|
|
|
|
|
2022-01-10 14:49:59 -05:00
|
|
|
render_bar(
|
|
|
|
console,
|
|
|
|
current_value=self.player.fighter.hp,
|
|
|
|
maximum_value=self.player.fighter.max_hp,
|
|
|
|
total_width=20,
|
2022-01-10 14:13:01 -05:00
|
|
|
)
|
|
|
|
|
2022-01-11 16:21:42 -05:00
|
|
|
render_names_at_mouse_location(console, x=21, y=44, engine=self)
|