diff --git a/BeamWeapon.h b/BeamWeapon.h index 9f1925c..a9dbc2e 100644 --- a/BeamWeapon.h +++ b/BeamWeapon.h @@ -5,6 +5,7 @@ #ifndef SFML_TEMPLATE_BEAMWEAPON_H #define SFML_TEMPLATE_BEAMWEAPON_H +#include #include "Beam.h" class BeamWeapon : public Weapon { @@ -19,20 +20,24 @@ public: Shootable* shoot(const Ship* shooter) override { framesShot++; + + if (noise.getStatus() != sf::Sound::Playing) noise.play(); + + projectile.setShooter((GameSprite *) shooter); + + sf::Vector2f adjusted(shooter->getXPos() + shooter->getLocalBounds().width/4 * shooter->getScale().x * cos(shooter->getDirection()*GameSprite::PI/180), shooter->getYPos() - shooter->getLocalBounds().width/4 * shooter->getScale().x * sin(shooter->getDirection()*GameSprite::PI/180)); + double newWidth = shooter->getTarget() == nullptr ? projectile.getRange() : GameSprite::distance(adjusted, shooter->getTarget()->getPosition()); + projectile.setTextureRect(sf::IntRect(projectile.getTextureRect().left, projectile.getTextureRect().top, newWidth > projectile.getRange() ? projectile.getRange() * (1/projectile.getScale().x) : newWidth * (1/projectile.getScale().x), projectile.getTextureRect().height)); + projectile.setOrigin(0, projectile.getLocalBounds().height/2); + projectile.setPosition(adjusted); + projectile.setDirection(shooter->getTarget() == nullptr ? shooter->getDirection() : -GameSprite::getAimAngle(shooter->getTarget()->getPosition(), projectile.getPosition())); + if (framesShot == duration) { framesShot = 0; currentFrame = 0; + noise.stop(); } - noise.play(); - - projectile.setShooter((GameSprite *) shooter); - double newWidth = shooter->getTarget() == nullptr ? projectile.getRange() : GameSprite::distance(shooter->getPosition(), shooter->getTarget()->getPosition()); - projectile.setTextureRect(sf::IntRect(projectile.getTextureRect().left, projectile.getTextureRect().top, newWidth > projectile.getRange() ? projectile.getRange() * (1/projectile.getScale().x) : newWidth * (1/projectile.getScale().x), projectile.getTextureRect().height)); - projectile.setOrigin(0, projectile.getLocalBounds().height/2); - projectile.setDirection(shooter->getTarget() == nullptr ? shooter->getDirection() : -GameSprite::getAimAngle(shooter->getTarget()->getPosition(), shooter->getPosition())); - projectile.setPosition(shooter->getPosition()); - return new Shootable(projectile); } }; diff --git a/Game.cpp b/Game.cpp index cd053d1..f659a8b 100644 --- a/Game.cpp +++ b/Game.cpp @@ -454,7 +454,7 @@ void Game::init() { sf::Vector2f currentPos; Ship *player = new Ship(ship, 50, window.getSize().x / (float) 2.0, window.getSize().y / (float) 2.0, 0, 10, -45, 2,3, 500, 100, 5); - player->addWeapon(new BeamWeapon(Beam(beam, sf::IntRect(0, 207, 535, 91), 10, 12, 1, 0, 513, 3, 1, 1500), beamBuffer, 50, 360 , 25, 40)); + player->addWeapon(new BeamWeapon(Beam(beam, sf::IntRect(0, 207, 535, 91), 10, 12, 1, 0, 513, 3, 1, 1500), beamBuffer, 100, 360 , 25, 40)); int playerMoney = 100000; System *currentSystem = systems[0]; diff --git a/data/Sounds/Projectiles/beam.wav b/data/Sounds/Projectiles/beam.wav new file mode 100644 index 0000000..cdcacbc Binary files /dev/null and b/data/Sounds/Projectiles/beam.wav differ diff --git a/data/Sounds/Projectiles/beamOld.wav b/data/Sounds/Projectiles/beamOld.wav new file mode 100644 index 0000000..3f8b9e2 Binary files /dev/null and b/data/Sounds/Projectiles/beamOld.wav differ