#include "enemy.hpp"
#include "../world.hpp"
#include "../block.hpp"

namespace game::entity {

Enemy::Enemy(Block *root, const vec2f &position) noexcept: Entity(root->GetWorld()), position(position)
{
    this->root = root;
    this->root->AddEnemy(this);
    this->world->AddManagedEntity(this);
}

bool Enemy::IsBoss() const noexcept
{
    return false;
}

bool Enemy::IsOnScreen() const noexcept
{
    return this->position.x < 30 && this->position.x > 0;
}

bool Enemy::IsLeftScreen() const noexcept
{
    return this->position.x < -2;
}

void Enemy::Unlink() noexcept
{
    this->root = nullptr;
}

void Enemy::Die() noexcept
{
    if (this->root) {
        this->root->RemoveEnemy(this);
    } else {
        this->world->RemoveManagedEntity(this);
    }

    this->world->AddScores(this->points);
    this->points = 0;
}

}

