Shooting satellites works

This commit is contained in:
2021-04-11 18:42:22 +02:00
parent 2f7759d190
commit c989202d93
10 changed files with 116 additions and 13 deletions
+56
View File
@@ -0,0 +1,56 @@
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 Vector3 Direction;
private Vector3 StartPos;
private float Range;
public Projectile(IScreen screen, Vector3 pos, Vector3 direction) : base(screen)
{
StartPos = pos;
Position = pos;
Dimensions = new Vector3(5, 5, 5);
Direction = direction;
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)
{
Position += Direction;
if (Vector3.Distance(StartPos, Position) > Range)
{
Destroy();
}
}
public override void OnCollision(IGameObject obj)
{
if (obj.Type == ObjectType.Player) return;
Screen.Manager.Sound.PlayOneshot(@"sfx/physics/impacts/bullet/1.wav", new System.Numerics.Vector3(Position.X, Position.Y, Position.Z), Screen.Manager.EnvironmentEffect);
Destroy();
}
}
}