beams shoot from further forward on the ship, noised added

This commit is contained in:
bMorgan01 2021-04-29 11:36:53 -06:00
parent 0c2a21e4da
commit eaf5a55d18
4 changed files with 15 additions and 10 deletions

View file

@ -5,6 +5,7 @@
#ifndef SFML_TEMPLATE_BEAMWEAPON_H #ifndef SFML_TEMPLATE_BEAMWEAPON_H
#define SFML_TEMPLATE_BEAMWEAPON_H #define SFML_TEMPLATE_BEAMWEAPON_H
#include <thread>
#include "Beam.h" #include "Beam.h"
class BeamWeapon : public Weapon { class BeamWeapon : public Weapon {
@ -19,20 +20,24 @@ public:
Shootable* shoot(const Ship* shooter) override { Shootable* shoot(const Ship* shooter) override {
framesShot++; 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) { if (framesShot == duration) {
framesShot = 0; framesShot = 0;
currentFrame = 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); return new Shootable(projectile);
} }
}; };

View file

@ -454,7 +454,7 @@ void Game::init() {
sf::Vector2f currentPos; 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); 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; int playerMoney = 100000;
System *currentSystem = systems[0]; System *currentSystem = systems[0];

Binary file not shown.

Binary file not shown.