do zrobienia jeszcze animacja uderzenia się w meteoryt (miganie) i wybuch statku przy uderzeniu się w meteoryt po raz trzeci
60 lines
1.3 KiB
C++
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) {
|
|
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;
|
|
} |