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