Files

145 lines
4.9 KiB
C#
Raw Permalink Normal View History

2021-04-11 17:09:57 +02:00
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;
2021-04-19 23:37:40 +02:00
public ISoundEffect sfxEmpty;
2021-04-11 18:42:22 +02:00
public GameScreen Screen;
public LaserMG(IGameObject wielder, GameScreen screen)
2021-04-11 17:09:57 +02:00
{
_wielder = wielder;
Screen = screen;
MaxAmmo = 250;
RemainingAmmo = MaxAmmo;
2021-04-24 02:47:17 +02:00
FireRate = 150;
2021-04-11 17:09:57 +02:00
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;
2021-04-24 02:47:17 +02:00
sfxShoot = new AudioAsset(Screen.Manager.Sound, @"sfx/weapons/LaserMG/fire", 1, 5);
2021-04-19 23:37:40 +02:00
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);
2021-04-11 17:09:57 +02:00
}
public override void Shoot(GameTime time)
{
if (State != WeaponState.Stopped)
{
return;
}
2021-04-11 17:09:57 +02:00
State = WeaponState.Starting;
sfxSpinup.Reset();
sfxSpinup.Play();
2021-04-23 15:07:50 +02:00
TimerStart = 0;
2021-04-11 17:09:57 +02:00
}
public override void Stop()
{
if (State != WeaponState.Stopped)
2021-04-11 17:09:57 +02:00
{
sfxSpinning.Pause();
sfxSpinup.Pause();
2021-04-11 17:09:57 +02:00
sfxSpindown.Reset();
sfxSpindown.Play();
State = WeaponState.Stopping;
2021-04-11 17:09:57 +02:00
}
}
public override void Update(GameTime time)
{
2021-04-23 15:07:50 +02:00
TimerStart += time.ElapsedGameTime.TotalMilliseconds;
2021-04-11 17:09:57 +02:00
if (State == WeaponState.Starting)
{
2021-04-23 15:07:50 +02:00
if (TimerStart > 800)
2021-04-11 17:09:57 +02:00
{
State = WeaponState.Firing;
sfxSpinning.Play();
2021-04-23 15:07:50 +02:00
TimerStart = 0;
2021-04-11 17:09:57 +02:00
}
}
if (State == WeaponState.Firing)
{
2021-04-23 15:07:50 +02:00
if (TimerStart > FireRate)
2021-04-11 17:09:57 +02:00
{
2021-04-19 23:37:40 +02:00
if (RemainingAmmo > 0)
{
sfxShoot.Play();
2021-04-24 14:34:15 +02:00
Screen.Manager.Vibrations.AddVibration(1, 1, 70);
2021-04-19 23:37:40 +02:00
RemainingAmmo--;
TimerStart = TimerEnd;
Projectile proj = new Projectile(Screen, _wielder.Position, _wielder.Rotation, _wielder);
Screen.AddObject(proj);
2021-04-23 20:28:06 +02:00
GameStats.ShotsFired++;
2021-04-24 23:31:43 +02:00
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");
}
2021-04-19 23:37:40 +02:00
} else
{
sfxEmpty.Reset();
sfxEmpty.Play();
TimerStart = TimerEnd;
}
2021-04-11 17:09:57 +02:00
}
}
if (State == WeaponState.Stopping)
{
2021-04-23 15:07:50 +02:00
if (TimerStart > 500)
{
State = WeaponState.Stopped;
2021-04-23 15:07:50 +02:00
TimerStart = 0;
}
}
2021-04-11 17:09:57 +02:00
base.Update(time);
}
2021-04-21 14:14:14 +02:00
public override void Reload(int amount)
{
RemainingAmmo += amount;
sfxReload.Reset();
sfxReload.Play();
2021-04-24 02:47:17 +02:00
Screen.Manager.Vibrations.AddVibration(1, 1, 500);
2021-04-21 14:14:14 +02:00
}
2021-04-25 02:07:37 +02:00
public override void Destroy()
{
sfxEmpty.Destroy();
sfxReload.Destroy();
sfxShoot.Destroy();
sfxSpindown.Destroy();
sfxSpinning.Destroy();
sfxSpinup.Destroy();
}
2021-04-11 17:09:57 +02:00
}
}