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 8b4b25747e Zmiana sposobu tworzenia gracza.
Użyto singleton pattern.
Zmieniono konstruktor klasy Plansza
2024-12-13 13:36:41 +01:00

43 lines
1.1 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));
}
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;
}