Multiple entities + pathfinding

This commit is contained in:
Jan Mrna
2025-10-10 10:45:27 +02:00
parent 2f80129dce
commit 3d34b68133
5 changed files with 99 additions and 55 deletions

View File

@@ -46,6 +46,28 @@ void Entity::Update(float time_delta) {
m_Position += m_ActualVelocity * time_delta;
}
std::optional<WorldPos> Entity::GetMoveTarget()
{
auto& path = GetPath();
if (path.empty()) {
return {};
}
WorldPos current_pos = GetPosition();
WorldPos next_pos = path.front();
if (current_pos.DistanceTo(next_pos) > 1.0) {
// target not reached yet
return next_pos;
}
// target reached, pop it
//m_MoveQueue.pop();
path.erase(path.begin());
// return nothing - if there's next point in the queue,
// we'll get it in the next iteration
return {};
}
Player::Player() {
LOG_DEBUG(".");
if (m_Sprite == nullptr) {