97 lines
3.4 KiB
C#
97 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using SynthySound;
|
|
using EvilSatellites.Screens;
|
|
using Microsoft.Xna.Framework;
|
|
|
|
namespace EvilSatellites.Objects
|
|
{
|
|
public class Satellite : AbstractGameObject
|
|
{
|
|
private ISoundEffect3D Sound;
|
|
private int Health;
|
|
private int SatelliteID;
|
|
private Random rnd = new Random();
|
|
private Matrix FlightPath;
|
|
public Satellite(IScreen screen, Vector3 pos, int satelliteID = 1) : base(screen)
|
|
{
|
|
Type = ObjectType.Satellite;
|
|
SatelliteID = satelliteID;
|
|
Sound = Screen.Manager.Sound.Load3D(@"sfx/satellite/"+SatelliteID.ToString()+"/loop.wav");
|
|
Sound.Loop = true;
|
|
Sound.Pitch = 0.9 + rnd.NextDouble()*0.5;
|
|
Position = pos;
|
|
Dimensions = new Vector3(5, 5, 5);
|
|
Sound.Position = new System.Numerics.Vector3(pos.X, pos.Y, pos.Z);
|
|
Sound.ConnectToEffect(Screen.Manager.EnvironmentEffect);
|
|
FlightPath = Matrix.CreateFromAxisAngle(Rotation.Right, (float)rnd.NextDouble()*0.1f);
|
|
Rotation = FlightPath;
|
|
Activate();
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
Sound.Play();
|
|
Active = true;
|
|
ShouldDestroy = false;
|
|
Health = 100;
|
|
}
|
|
public override void Destroy()
|
|
{
|
|
Sound.Destroy();
|
|
ShouldDestroy = true;
|
|
Active = false;
|
|
}
|
|
|
|
override public void Update(GameTime gameTime)
|
|
{
|
|
Move(new Vector3(0, 0, -0.05f));
|
|
Sound.Position = new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2);
|
|
if (rnd.Next(500) == 250)
|
|
{
|
|
var scr = (GameScreen)Screen;
|
|
var player = scr.GetPlayer();
|
|
var view = player.Position - Position;
|
|
var rotationAxis = Vector3.Cross(Rotation.Forward, view);
|
|
var rotationAngle = (float)Math.Acos(Vector3.Dot(Rotation.Forward, view) / Rotation.Forward.Length() / view.Length());
|
|
var rotationMatrix = Matrix.CreateFromAxisAngle(rotationAxis, rotationAngle);
|
|
var proj = new Projectile(Screen, Position, rotationMatrix, this);
|
|
proj.Direction = new Vector3(0, 0, 1);
|
|
scr.AddObject(proj);
|
|
DavyKager.Tolk.Output("Shoot!");
|
|
}
|
|
}
|
|
|
|
public override void OnCollision(IGameObject obj)
|
|
{
|
|
if (obj.Type == ObjectType.Projectile)
|
|
{
|
|
var proj = (Projectile)obj;
|
|
if (proj.Owner == this) return;
|
|
}
|
|
Health -= 10;
|
|
if (obj.Type == ObjectType.Player)
|
|
{
|
|
var player = (Player)obj;
|
|
player.TakeDamage(66);
|
|
Destroy();
|
|
}
|
|
if (Health <= 0)
|
|
{
|
|
Screen.Manager.Sound.PlayOneshot(@"sfx/satellite/"+SatelliteID.ToString()+"/explode.wav", new System.Numerics.Vector3(Position.X, Position.Y, Position.Z));
|
|
SpawnDebris();
|
|
Destroy();
|
|
}
|
|
}
|
|
|
|
public void SpawnDebris()
|
|
{
|
|
var screen = (GameScreen)Screen;
|
|
screen.AddObject(new Debris(screen, Position));
|
|
}
|
|
}
|
|
}
|