adg5/Actor.cpp
2025-04-21 12:10:51 +10:00

40 lines
922 B
C++

#include <cstdio>
#include "libtcod.hpp"
#include "Actor.h"
#include "Map.h"
#include "Engine.h"
#include "Ai.h"
#include "Destructible.h"
#include "Attacker.h"
#include "Container.h"
#include "Pickable.h"
Actor::Actor(int x, int y, std::string_view ch, std::string name, const TCOD_ColorRGB& col) :
x(x), y(y), ch(ch), col(col), name(name),
blocks(true), attacker(nullptr), destructible(nullptr), ai(nullptr), pickable(nullptr), container(nullptr) {
}
void Actor::render(TCOD_Console& cons) const {
tcod::print(cons, { x, y }, ch, col, std::nullopt);
}
void Actor::update() {
if (ai) {
ai->update(this);
}
}
Actor::~Actor() {
if (attacker) delete attacker;
if (destructible) delete destructible;
if (ai) delete ai;
if (pickable) delete pickable;
if (container) delete container;
}
float Actor::getDistance(int cx, int cy) const {
int dx = x - cx;
int dy = y - cy;
return sqrtf(dx * dx + dy * dy);
}