Files
evilsatellites/EvilSatellites/Objects/Projectile.cs
T

60 lines
1.7 KiB
C#
Raw Normal View History

2021-04-11 18:42:22 +02:00
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;
2021-04-11 20:43:29 +02:00
private Random rnd = new Random();
2021-04-11 18:42:22 +02:00
private Vector3 Direction;
private Vector3 StartPos;
private float Range;
2021-04-11 20:43:29 +02:00
public Projectile(IScreen screen, Vector3 pos, Matrix rotation) : base(screen)
2021-04-11 18:42:22 +02:00
{
StartPos = pos;
Position = pos;
Dimensions = new Vector3(5, 5, 5);
2021-04-11 20:43:29 +02:00
Direction = new Vector3(0, 0, -1);
Rotation = rotation;
2021-04-11 18:42:22 +02:00
Range = 500;
Type = ObjectType.Projectile;
Activate();
}
public override void Activate()
{
ShouldDestroy = false;
Active = true;
}
public override void Destroy()
{
ShouldDestroy = true;
Active = false;
}
override public void Update(GameTime gameTime)
{
2021-04-11 20:43:29 +02:00
Move(Direction);
2021-04-11 18:42:22 +02:00
if (Vector3.Distance(StartPos, Position) > Range)
{
Destroy();
}
}
public override void OnCollision(IGameObject obj)
{
2021-04-11 20:43:29 +02:00
if (obj.Type == ObjectType.Projectile) return;
2021-04-11 18:42:22 +02:00
if (obj.Type == ObjectType.Player) return;
2021-04-11 20:43:29 +02:00
Screen.Manager.Sound.PlayOneshot(@"sfx/physics/impacts/bullet/"+(rnd.Next(5)+1)+".wav", new System.Numerics.Vector3(Position.X, Position.Y, Position.Z), Screen.Manager.EnvironmentEffect);
2021-04-11 18:42:22 +02:00
Destroy();
}
}
}