added weapon sounds and AI doesnt shoot if not in range

This commit is contained in:
bMorgan01 2021-04-27 18:43:40 -06:00
parent d1a7053149
commit 8016bab3e8
8 changed files with 48 additions and 13 deletions

View file

@ -12,18 +12,20 @@ private:
int duration;
int framesShot = 0;
public:
BeamWeapon(Beam _proj, int _duration, int frameDelay) : Weapon(frameDelay) {
BeamWeapon(Beam _proj, const sf::SoundBuffer& buffer, float volume, double effectiveAngle, int _duration, int frameDelay) : Weapon(frameDelay, effectiveAngle, buffer, volume) {
projectile = std::move(_proj);
duration = _duration;
}
Shootable* shoot(const Ship* shooter) {
Shootable* shoot(const Ship* shooter) override {
framesShot++;
if (framesShot == duration) {
framesShot = 0;
currentFrame = 0;
}
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));