70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using SynthySound;
|
|
using Microsoft.Xna.Framework;
|
|
using EvilSatellites.Screens;
|
|
|
|
namespace EvilSatellites.Objects
|
|
{
|
|
public class Projectile : AbstractGameObject
|
|
{
|
|
private ISoundEffect3D Sound;
|
|
private Random rnd = new Random();
|
|
public Vector3 Direction;
|
|
private Vector3 StartPos;
|
|
private float Range;
|
|
public IGameObject Owner;
|
|
public Projectile(IScreen screen, Vector3 pos, Matrix rotation, IGameObject owner) : base(screen)
|
|
{
|
|
Owner = owner;
|
|
StartPos = pos;
|
|
Position = pos;
|
|
Dimensions = new Vector3(5, 5, 5);
|
|
Direction = new Vector3(0, 0, -1);
|
|
Rotation = rotation;
|
|
Range = 500;
|
|
Type = ObjectType.Projectile;
|
|
Activate();
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
ShouldDestroy = false;
|
|
Active = true;
|
|
Sound = Screen.Manager.Sound.Load3D(@"sfx/bullets/1.wav");
|
|
Sound.Loop = true;
|
|
Sound.Play();
|
|
Sound.Pitch = 0.9 + rnd.NextDouble()*0.3;
|
|
Sound.Position = new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2);
|
|
}
|
|
public override void Destroy()
|
|
{
|
|
Sound.Stop();
|
|
Sound.Destroy();
|
|
ShouldDestroy = true;
|
|
Active = false;
|
|
}
|
|
|
|
override public void Update(GameTime gameTime)
|
|
{
|
|
Move(Direction);
|
|
if (Vector3.Distance(StartPos, Position) > Range)
|
|
{
|
|
Destroy();
|
|
}
|
|
Sound.Position = new System.Numerics.Vector3(Position.X + Dimensions.X / 2, Position.Y + Dimensions.Y / 2, Position.Z + Dimensions.Z / 2);
|
|
}
|
|
|
|
public override void OnCollision(IGameObject obj)
|
|
{
|
|
if (obj.Type == ObjectType.Projectile || obj.Type == ObjectType.Debris) return;
|
|
if (obj == Owner) return;
|
|
Screen.Manager.Sound.PlayOneshot(@"sfx/physics/impacts/bullet/"+(rnd.Next(5)+1)+".wav", new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2), Screen.Manager.EnvironmentEffect);
|
|
Destroy();
|
|
}
|
|
}
|
|
}
|