51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#include "../headers/Actor.h"
|
|
|
|
#include <iostream>
|
|
|
|
Actor::Actor(int x, int y, const sf::Texture& texture) {
|
|
actorSprite.setTexture(texture);
|
|
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/bullets/bullet_pink.png");
|
|
bulletTextureRight.loadFromFile("../assets/img/rockets/Rocket_111.png");
|
|
}
|
|
|
|
sf::Sprite &Actor::getSprite() {
|
|
if (!actorSprite.getTexture()) {
|
|
std::cerr << "actorSprite has no texture set!" << std::endl;
|
|
}
|
|
return actorSprite;
|
|
}
|
|
|
|
Position Actor::getPosition() {
|
|
return {position.x, position.y};
|
|
}
|
|
|
|
std::vector<Bullet> &Actor::getBullets() {
|
|
return bullets;
|
|
}
|
|
|
|
void Actor::updateBullets() {
|
|
for (auto it = bullets.begin(); it != bullets.end(); ) {
|
|
if (it->isOutOfBounds()) {
|
|
it = bullets.erase(it); // Usuwa element i zwraca iterator na następny element
|
|
} else {
|
|
++it; // Przechodzi do następnego elementu
|
|
}
|
|
}
|
|
//std::cout << "Liczba pociskow: " << bullets.size() << std::endl;
|
|
}
|
|
|
|
|
|
void Actor::setMovingSpeed(float speed) {
|
|
moving_speed = speed;
|
|
}
|