diff --git a/assets/img/bullet.png b/assets/img/bullet_left.png similarity index 100% rename from assets/img/bullet.png rename to assets/img/bullet_left.png diff --git a/assets/img/bullet_right.png b/assets/img/bullet_right.png index 6704ac9..d19bfe5 100644 Binary files a/assets/img/bullet_right.png and b/assets/img/bullet_right.png differ diff --git a/headers/Player.h b/headers/Player.h index eee3c1f..8138296 100644 --- a/headers/Player.h +++ b/headers/Player.h @@ -2,12 +2,14 @@ #define LOTOSTATEK_PLAYER_H +#include #include "Actor.h" class Player : public Actor { public: Player(int x, int y, std::string path); void shoot() override; + void alternate_shoot(); void setFirerate(unsigned int firerate); void move(float deltaX, float deltaY) override; void moveLeft() override; @@ -16,6 +18,8 @@ public: void moveDown() override; private: std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now(); + std::vector rightBullets; + }; diff --git a/main.cpp b/main.cpp index 5d3bdd9..6e883d3 100644 --- a/main.cpp +++ b/main.cpp @@ -36,27 +36,31 @@ int main() if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { ship.shoot(); } - if(event.type == sf::Event::MouseButtonPressed) { - ship.shoot(); - } } - if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { + if(event.type == sf::Event::MouseButtonPressed) { + if(event.mouseButton.button == sf::Mouse::Left) + ship.shoot(); + else + ship.alternate_shoot(); + } + + if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { if(ship.getPosition().x > -10) { ship.moveLeft(); } } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { if(ship.getPosition().x < 480) { ship.moveRight(); } } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { if(ship.getPosition().y > 0) { ship.moveUp(); } } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { if(ship.getPosition().y < 700) { ship.moveDown(); } diff --git a/sources/Actor.cpp b/sources/Actor.cpp index ffa37e3..afe34e4 100644 --- a/sources/Actor.cpp +++ b/sources/Actor.cpp @@ -12,7 +12,7 @@ void Actor::loadTexture(std::string path) { actorTexture.loadFromFile(path); actorSprite.setTexture(actorTexture); - bulletTextureLeft.loadFromFile("../assets/img/bullet.png"); + bulletTextureLeft.loadFromFile("../assets/img/bullet_left.png"); bulletTextureRight.loadFromFile("../assets/img/bullet_right.png"); } diff --git a/sources/Player.cpp b/sources/Player.cpp index c148797..eca9dc5 100644 --- a/sources/Player.cpp +++ b/sources/Player.cpp @@ -10,6 +10,14 @@ 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(float(position.x) + actorSprite.getGlobalBounds().width / 2-62, position.y, bulletTextureRight); + lastShotTime = now; + } +} + void Player::setFirerate(unsigned int firerate) { this->firerate = firerate; }