#include "powerup.hpp"
#include "../world.hpp"
#include <resources.h>

namespace game::entity {

PowerUp::PowerUp(World *world, const vec2f &position, float speed):
    BasicBullet(world, position, speed, -180) {
    this->Setup();

    int types[6] = {
        POWERUP_WEAPON_1,
        POWERUP_WEAPON_2,
        POWERUP_WEAPON_3,
        POWERUP_HEAL,
        POWERUP_DAMAGE_UP,
        POWERUP_DAMAGE_UP,
    };

    this->type = types[rand() % 6];

    const char *names[] = {
        "w0.png",
        "w1.png",
        "w2.png",
        "hl.png",
        "du.png",
    };

    resources::atlas.getIcon(names[this->type], this->icon);
    this->icon.scale.x = 1 / 16.0;
    this->icon.scale.y = 1 / 16.0;
}

void PowerUp::Setup()
{
    b2CircleShape shape;
    shape.m_radius = 0.1;

    b2FixtureDef fixDef;
    fixDef.filter.categoryBits = TYPE_POWERUP;
    fixDef.filter.maskBits = TYPE_TRIGGER | TYPE_WALL;
    fixDef.shape = &shape;
    fixDef.density = 1.0f;
    fixDef.userData = this;

    this->body->CreateFixture(&fixDef);
}

void PowerUp::Render() noexcept
{
    this->icon.draw(this->position);
}

}
