Add basic radar and weapon
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SynthySound;
|
||||
using EvilSatellites.Screens;
|
||||
using EvilSatellites.Objects;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace EvilSatellites
|
||||
{
|
||||
public class Radar
|
||||
{
|
||||
public bool Active { get; set; }
|
||||
public IGameObject Owner;
|
||||
public IGameObject Target;
|
||||
public IScreen Screen;
|
||||
public ISoundEffect RadarNoise;
|
||||
public Radar(IGameObject owner, IScreen screen)
|
||||
{
|
||||
Owner = owner;
|
||||
Screen = screen;
|
||||
RadarNoise = Screen.Manager.Sound.Load(@"sfx/ui/radar/pingEnemy.wav", false);
|
||||
RadarNoise.Loop = true;
|
||||
Active = false;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
RadarNoise.Reset();
|
||||
RadarNoise.Play();
|
||||
Active = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
RadarNoise.Pause();
|
||||
Active = false;
|
||||
}
|
||||
|
||||
public void Update(List<IGameObject> objects)
|
||||
{
|
||||
float minDistance = 1000;
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
if (obj == Owner) continue;
|
||||
float distance = Vector3.Distance(obj.Position, Owner.Position);
|
||||
if (distance < minDistance)
|
||||
{
|
||||
minDistance = distance;
|
||||
Target = obj;
|
||||
}
|
||||
}
|
||||
Vector3 radarTarget = (Target.Position - Owner.Position);
|
||||
radarTarget.Normalize();
|
||||
RadarNoise.Pitch = MathHelper.Clamp(0.1f / Vector3.Distance(Owner.Rotation.Forward, radarTarget) * 3f, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user