diff --git a/cmake-build-debug/LotoStatek.exe b/cmake-build-debug/LotoStatek.exe new file mode 100644 index 0000000..d93b482 Binary files /dev/null and b/cmake-build-debug/LotoStatek.exe differ diff --git a/headers/Actor.h b/headers/Actor.h index 43ffc73..56b704a 100644 --- a/headers/Actor.h +++ b/headers/Actor.h @@ -5,11 +5,12 @@ #include "SFML/Graphics/Texture.hpp" #include "Bullet.h" +struct Position { + int x; + int y; +}; + class Actor { - struct Position { - int x; - int y; - }; public: Actor(int x, int y, std::string path); diff --git a/headers/Bullet.h b/headers/Bullet.h index 74d2539..bd59539 100644 --- a/headers/Bullet.h +++ b/headers/Bullet.h @@ -11,14 +11,14 @@ class Bullet { }; public: - Bullet(float x, float y, sf::Texture &texture); + Bullet(float x, float y); sf::Sprite &getSprite(); void setSpeed(float speed); bool getStatus() const; void update(); + static sf::Texture bulletTexture; private: sf::Sprite bulletSprite; - sf::Texture bulletTexture; Position bulletPosition; float bulletSpeed; bool outOfBounds; diff --git a/sources/Actor.cpp b/sources/Actor.cpp index ae74aff..5525c1c 100644 --- a/sources/Actor.cpp +++ b/sources/Actor.cpp @@ -25,7 +25,7 @@ Position Actor::getPosition() { } void Actor::shoot() { - bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft); +// bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2, position.y, bulletTextureLeft); } std::vector &Actor::getBullets() { diff --git a/sources/Bullet.cpp b/sources/Bullet.cpp index dc9f8a6..92e6006 100644 --- a/sources/Bullet.cpp +++ b/sources/Bullet.cpp @@ -1,12 +1,11 @@ #include #include "../headers/Bullet.h" -Bullet::Bullet(float x, float y, sf::Texture &texture) { +Bullet::Bullet(float x, float y) { bulletPosition.x = x; bulletPosition.y = y; outOfBounds = false; - bulletTexture = texture; - bulletSprite.setTexture(texture); + bulletSprite.setTexture(Bullet::bulletTexture); bulletSprite.setOrigin(bulletSprite.getLocalBounds().width/2, bulletSprite.getLocalBounds().height/2); bulletSprite.setPosition(x, y); bulletSpeed = -10.0f; @@ -31,3 +30,5 @@ void Bullet::update() { bool Bullet::getStatus() const { return outOfBounds; } + +sf::Texture Bullet::bulletTexture = sf::Texture(); // plain init of static field diff --git a/sources/Player.cpp b/sources/Player.cpp index 058fb29..c29fede 100644 --- a/sources/Player.cpp +++ b/sources/Player.cpp @@ -1,11 +1,15 @@ #include "../headers/Player.h" +#include "../headers/Bullet.h" -Player::Player(int x, int y, std::string path) : Actor(x, y, path) {}; +// TODO: Podzielić na klasy Bullet i Rocket. +Player::Player(int x, int y, std::string path) : Actor(x, y, path) { + Bullet::bulletTexture.loadFromFile("../assets/img/bullet_left.png"); +}; void Player::shoot() { auto now = std::chrono::steady_clock::now(); if (std::chrono::duration_cast(now - lastShotTime).count() >= firerate) { - bullets.emplace_back(position.x, position.y, bulletTextureLeft); + bullets.emplace_back(position.x, position.y); lastShotTime = now; } } @@ -14,7 +18,7 @@ void Player::shoot() { void Player::alternate_shoot() { auto now = std::chrono::steady_clock::now(); if (std::chrono::duration_cast(now - lastShotTime).count() >= firerate) { - bullets.emplace_back(position.x, position.y, bulletTextureRight).getSprite().scale(1.5f, 1.5f); + bullets.emplace_back(position.x, position.y).getSprite().scale(1.5f, 1.5f); lastShotTime = now; } }