#include "../headers/Actor.h"

Actor::Actor(int x, int y, std::string path) {
    loadTexture(path);
    position.x = x;
    position.y = y;
    actorSprite.setOrigin(actorSprite.getLocalBounds().width / 2, actorSprite.getLocalBounds().height / 2); // wycentrowanie sprite
    actorSprite.setPosition(float(x), float(y));
}

void Actor::loadTexture(std::string path) {
    actorTexture.loadFromFile(path);
    actorSprite.setTexture(actorTexture);

    bulletTextureLeft.loadFromFile("../assets/img/bullet_left.png");
    bulletTextureRight.loadFromFile("../assets/img/Rocket_111.png");
}

sf::Sprite &Actor::getSprite() {
    return actorSprite;
}

Position Actor::getPosition() {
    return {position.x, position.y};
}

void Actor::shoot() {
    bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft);
}

std::vector<Bullet> &Actor::getBullets() {
    return bullets;
}

void Actor::updateBullets() {
    for (auto& bullet : bullets) {
        if(bullet.getStatus()) {
            bullets.erase(bullets.begin());
        }
    }
}

void Actor::setMovingSpeed(float speed) {
    moving_speed = speed;
}
