This repository has been archived on 2025-06-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LotoStatek/sources/Actor.cpp
hamx01 fcabc0534a A little code refactor
+ new bullet texture added
2024-11-16 16:01:01 +01:00

42 lines
985 B
C++

#include "../headers/Actor.h"
// TODO: Naprawić krzywy sprite statku
Actor::Actor(int x, int y, std::string path) {
loadTexture(path);
position.x = x;
position.y = y;
actorSprite.setPosition(x, y);
}
void Actor::loadTexture(std::string path) {
actorTexture.loadFromFile(path);
actorSprite.setTexture(actorTexture);
bulletTextureLeft.loadFromFile("../assets/img/bullet.png");
bulletTextureRight.loadFromFile("../assets/img/bullet_right.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-62, position.y, bulletTextureLeft);
}
std::vector<Bullet> &Actor::getBullets() {
return bullets;
}
void Actor::updateBullets() {
for (auto& bullet : bullets) {
if(bullet.getStatus()) {
bullets.erase(bullets.begin());
}
}
}