#include #include "libtcod.hpp" #include "Actor.h" #include "Map.h" #include "Engine.h" #include "Destructible.h" #include "Attacker.h" #include "Ai.h" #include "Gui.h" #include "Container.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; gui = nullptr; map = nullptr; player = nullptr; fovRadius = 10; computeFov = true; gameStatus = STARTUP; mouse.cx = 0; mouse.cy = 0; } void Engine::init() { gui = new Gui(context, console); 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(); player->container = new Container(26); actors.push(player); map = new Map(80, 45); gui->message(TCOD_ColorRGB(150,0,0), "Welcome stranger!\nPrepare to perish in the Tombs of Andrew's Dunegon."); } Engine::~Engine() { actors.clearAndDelete(); delete map; delete gui; } 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); gui->render(); context->present(*console); } void Engine::sendToBack(Actor* actor) { actors.remove(actor); actors.insertBefore(actor, 0); }