#include "basicBullet.hpp"
#include "../world.hpp"

#include <cstdio>

namespace game::entity {

BasicBullet::BasicBullet(World *world, const vec2f &position, float speed, float angle): Entity(world) {
    this->body = world->CreateBody(position, b2_dynamicBody);
    this->body->SetBullet(true);

    sincosf(angle*DTOR, &this->velocity.y, &this->velocity.x);

    this->angle = angle;

    this->velocity *= speed;

    this->body->SetLinearVelocity(this->velocity);

    this->world->AddManagedEntity(this);
}

BasicBullet::~BasicBullet()
{
    this->world->RemoveManagedEntity(this);
}


void BasicBullet::Update() noexcept
{
    this->position.x = this->body->GetPosition().x;
    this->position.y = this->body->GetPosition().y;
}

void BasicBullet::OnCollide()
{
    this->world->RemoveManagedEntity(this);
}

void BasicBullet::OnCollide(Entity *entity)
{
    this->world->RemoveManagedEntity(this);
}

}
