#include #include "libtcod.hpp" #include "Actor.h" #include "Map.h" #include "Engine.h" #include "Destructible.h" #include "Attacker.h" #include "Ai.h" Engine::Engine(int screenWidth, int screenHeight, tcod::Context *context, tcod::Console *console) { this->context = context; this->console = console; this->screenWidth = screenWidth; this->screenHeight = screenHeight; map = nullptr; player = nullptr; fovRadius = 10; computeFov = true; gameStatus = STARTUP; } void Engine::init() { player = new Actor(40, 25, "@", "player", TCOD_ColorRGB(255, 255, 255)); player->destructible = new PlayerDestructible(30, 2, "player corpse"); player->attacker = new Attacker(5); player->ai = new PlayerAi(); actors.push(player); map = new Map(80, 45); } Engine::~Engine() { actors.clearAndDelete(); delete map; } bool Engine::update() { if (gameStatus == STARTUP) map->computeFov(); gameStatus = IDLE; player->update(); if (gameStatus == NEW_TURN) { for (Actor** iterator = actors.begin(); iterator != actors.end(); iterator++) { Actor* actor = *iterator; if (actor != player) { actor->update(); } } } if (gameStatus == QUIT) { return false; } return true; } void Engine::render() { console->clear(); // draw the map map->render(*console); // draw the actors for (Actor** iterator = actors.begin(); iterator != actors.end(); iterator++) { Actor* actor = *iterator; if (actor != player && map->isInFov(actor->x, actor->y)) { actor->render(*console); } } player->render(*console); std::string hp = "HP : " + std::to_string(player->destructible->hp) + "/" + std::to_string(player->destructible->maxHp); tcod::print(*console, { 1, 1 }, hp, TCOD_ColorRGB(255, 255, 255), std::nullopt); context->present(*console); } void Engine::sendToBack(Actor* actor) { actors.remove(actor); actors.insertBefore(actor, 0); }