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
Andrii Solianyk 71f8ebe285 Statek miga
przy uderzeniu w meteoryt
2024-12-06 15:16:57 +01:00

60 lines
1.3 KiB
C++

#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/bullets/bullet_pink.png");
bulletTextureRight.loadFromFile("../assets/img/rockets/Rocket_111.png");
}
sf::Sprite &Actor::getSprite() {
return actorSprite;
}
Position Actor::getPosition() {
return {position.x, position.y};
}
unsigned int Actor::getHP() {
return hp;
}
void Actor::dealDamage() {
if(damageDealClock.getElapsedTime().asSeconds() > 1.5) {
if(hp > 0) {
hp--;
}
damageDealClock.restart();
}
}
void Actor::healUP() {
if(hp < 3){
hp++;
}
}
std::vector<Bullet> &Actor::getBullets() {
return bullets;
}
void Actor::updateBullets() {
for (auto& bullet : bullets) {
if(bullet.isOutOfBounds()) {
bullets.erase(bullets.begin());
}
}
}
void Actor::setMovingSpeed(float speed) {
moving_speed = speed;
}