diff --git a/assets/img/bullet_right.png b/assets/img/bullet_right.png new file mode 100644 index 0000000..6704ac9 Binary files /dev/null and b/assets/img/bullet_right.png differ diff --git a/headers/Actor.h b/headers/Actor.h index 1c62ef9..70319be 100644 --- a/headers/Actor.h +++ b/headers/Actor.h @@ -20,13 +20,12 @@ public: Position getPosition(); - void move(float deltaX, float deltaY); - - void moveLeft(); - - void moveRight(); - - void shoot(); + virtual void move(float deltaX, float deltaY) = 0; + virtual void moveLeft() = 0; + virtual void moveRight() = 0; + virtual void moveUp() = 0; + virtual void moveDown() = 0; + virtual void shoot() = 0; std::vector& getBullets(); @@ -39,7 +38,8 @@ public: protected: sf::Sprite actorSprite; sf::Texture actorTexture; - sf::Texture bulletTexture; + sf::Texture bulletTextureLeft; + sf::Texture bulletTextureRight; Position position; unsigned int hp; unsigned int damage; diff --git a/headers/Player.h b/headers/Player.h index 76e73ec..eee3c1f 100644 --- a/headers/Player.h +++ b/headers/Player.h @@ -7,13 +7,13 @@ class Player : public Actor { public: Player(int x, int y, std::string path); - void shoot(); + void shoot() override; void setFirerate(unsigned int firerate); - void move(float deltaX, float deltaY); - void moveLeft(); - void moveRight(); - void moveUp(); - void moveDown(); + void move(float deltaX, float deltaY) override; + void moveLeft() override; + void moveRight() override; + void moveUp() override; + void moveDown() override; private: std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now(); }; diff --git a/main.cpp b/main.cpp index cf61214..5d3bdd9 100644 --- a/main.cpp +++ b/main.cpp @@ -41,7 +41,6 @@ int main() } } - // Sprawdzanie stanu klawiszy w głównej pętli gry if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { if(ship.getPosition().x > -10) { ship.moveLeft(); diff --git a/sources/Actor.cpp b/sources/Actor.cpp index c98ec74..ffa37e3 100644 --- a/sources/Actor.cpp +++ b/sources/Actor.cpp @@ -1,5 +1,6 @@ #include "../headers/Actor.h" +// TODO: Naprawić krzywy sprite statku Actor::Actor(int x, int y, std::string path) { loadTexture(path); position.x = x; @@ -11,25 +12,20 @@ void Actor::loadTexture(std::string path) { actorTexture.loadFromFile(path); actorSprite.setTexture(actorTexture); - bulletTexture.loadFromFile("../assets/img/bullet.png"); + bulletTextureLeft.loadFromFile("../assets/img/bullet.png"); + bulletTextureRight.loadFromFile("../assets/img/bullet_right.png"); } sf::Sprite &Actor::getSprite() { return actorSprite; } -void Actor::move(float deltaX, float deltaY) {} - -void Actor::moveLeft() {} - -void Actor::moveRight() {} - Position Actor::getPosition() { return {position.x, position.y}; } void Actor::shoot() { - bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTexture); + bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureLeft); } std::vector &Actor::getBullets() { diff --git a/sources/Player.cpp b/sources/Player.cpp index 2dea282..c148797 100644 --- a/sources/Player.cpp +++ b/sources/Player.cpp @@ -5,7 +5,7 @@ Player::Player(int x, int y, std::string path) : Actor(x, y, path) {}; void Player::shoot() { auto now = std::chrono::steady_clock::now(); if (std::chrono::duration_cast(now - lastShotTime).count() >= firerate) { - bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTexture); + bullets.emplace_back(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureLeft); lastShotTime = now; } }