Files
evilsatellites/EvilSatellites/Weapons/LaserMG.cs
T
2021-04-25 02:07:37 +02:00

145 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EvilSatellites.Objects;
using SynthySound;
using EvilSatellites.Screens;
using Microsoft.Xna.Framework;
namespace EvilSatellites.Weapons
{
public class LaserMG : AbstractWeapon
{
public AudioAsset sfxShoot;
public ISoundEffect sfxReload;
public ISoundEffect sfxSpindown;
public ISoundEffect sfxSpinup;
public ISoundEffect sfxSpinning;
public ISoundEffect sfxEmpty;
public GameScreen Screen;
public LaserMG(IGameObject wielder, GameScreen screen)
{
_wielder = wielder;
Screen = screen;
MaxAmmo = 250;
RemainingAmmo = MaxAmmo;
FireRate = 150;
State = WeaponState.Stopped;
LoadSounds();
}
public void LoadSounds()
{
sfxReload = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/reload.wav", false);
sfxSpindown = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/spindown.wav", false);
sfxSpinup = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/spinup.wav", false);
sfxSpinning = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/spinning.wav", false);
sfxSpinning.Loop = true;
sfxShoot = new AudioAsset(Screen.Manager.Sound, @"sfx/weapons/LaserMG/fire", 1, 5);
sfxEmpty = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/empty.wav", false);
sfxEmpty.ConnectToEffect(Screen.Manager.EnvironmentEffect);
sfxReload.ConnectToEffect(Screen.Manager.EnvironmentEffect);
sfxShoot.AddEffect(Screen.Manager.EnvironmentEffect);
sfxSpindown.ConnectToEffect(Screen.Manager.EnvironmentEffect);
sfxSpinup.ConnectToEffect(Screen.Manager.EnvironmentEffect);
sfxSpinning.ConnectToEffect(Screen.Manager.EnvironmentEffect);
}
public override void Shoot(GameTime time)
{
if (State != WeaponState.Stopped)
{
return;
}
State = WeaponState.Starting;
sfxSpinup.Reset();
sfxSpinup.Play();
TimerStart = 0;
}
public override void Stop()
{
if (State != WeaponState.Stopped)
{
sfxSpinning.Pause();
sfxSpinup.Pause();
sfxSpindown.Reset();
sfxSpindown.Play();
State = WeaponState.Stopping;
}
}
public override void Update(GameTime time)
{
TimerStart += time.ElapsedGameTime.TotalMilliseconds;
if (State == WeaponState.Starting)
{
if (TimerStart > 800)
{
State = WeaponState.Firing;
sfxSpinning.Play();
TimerStart = 0;
}
}
if (State == WeaponState.Firing)
{
if (TimerStart > FireRate)
{
if (RemainingAmmo > 0)
{
sfxShoot.Play();
Screen.Manager.Vibrations.AddVibration(1, 1, 70);
RemainingAmmo--;
TimerStart = TimerEnd;
Projectile proj = new Projectile(Screen, _wielder.Position, _wielder.Rotation, _wielder);
Screen.AddObject(proj);
GameStats.ShotsFired++;
var scr = (EvilSatellites.Screens.GameScreen)Screen;
if (scr.ObjectRadar.RadarPitch < 0.8)
{
scr.Manager.Computer.Play("FarMiss");
} else if (scr.ObjectRadar.RadarPitch < 1)
{
scr.Manager.Computer.Play("NearMiss");
}
} else
{
sfxEmpty.Reset();
sfxEmpty.Play();
TimerStart = TimerEnd;
}
}
}
if (State == WeaponState.Stopping)
{
if (TimerStart > 500)
{
State = WeaponState.Stopped;
TimerStart = 0;
}
}
base.Update(time);
}
public override void Reload(int amount)
{
RemainingAmmo += amount;
sfxReload.Reset();
sfxReload.Play();
Screen.Manager.Vibrations.AddVibration(1, 1, 500);
}
public override void Destroy()
{
sfxEmpty.Destroy();
sfxReload.Destroy();
sfxShoot.Destroy();
sfxSpindown.Destroy();
sfxSpinning.Destroy();
sfxSpinup.Destroy();
}
}
}