Files
evilsatellites/EvilSatellites/Objects/Debris.cs
T

73 lines
2.5 KiB
C#
Raw Normal View History

2021-04-18 00:27:13 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using SynthySound;
using EvilSatellites.Screens;
namespace EvilSatellites.Objects
{
public class Debris : AbstractGameObject
{
private ISoundEffect3D Sound;
2021-04-19 15:41:37 +02:00
private Random rnd = new Random();
private Vector3 MovementVector;
2021-04-18 00:27:13 +02:00
public Debris(IScreen screen, Vector3 pos) : base(screen)
{
2021-04-19 15:41:37 +02:00
Type = ObjectType.Debris;
2021-04-18 00:27:13 +02:00
Sound = Screen.Manager.Sound.Load3D(@"sfx/debris/1/loop.wav");
Sound.Loop = true;
2021-04-19 15:41:37 +02:00
Sound.Pitch = 0.9 + (float)rnd.NextDouble()*2;
2021-04-18 00:27:13 +02:00
Position = pos;
Dimensions = new Vector3(5, 5, 5);
Sound.Position = new System.Numerics.Vector3(pos.X, pos.Y, pos.Z);
2021-04-19 15:41:37 +02:00
MovementVector = new Vector3(-0.02f + (float)rnd.NextDouble() * 0.01f, -0.02f + (float)rnd.NextDouble() * 0.01f, -0.02f + (float) rnd.NextDouble() * 0.01f);
Rotation = Matrix.CreateFromAxisAngle(new Vector3(0, 0, 1), 0);
2021-04-18 00:27:13 +02:00
Sound.ConnectToEffect(Screen.Manager.EnvironmentEffect);
Activate();
}
public override void Activate()
{
Sound.Play();
Active = true;
ShouldDestroy = false;
}
public override void Destroy()
{
Sound.Destroy();
2021-04-19 15:41:37 +02:00
ShouldDestroy = true;
Active = false;
2021-04-18 00:27:13 +02:00
}
override public void Update(GameTime gameTime)
{
2021-04-19 15:41:37 +02:00
Move(MovementVector);
Sound.Position = new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2);
2021-04-18 00:27:13 +02:00
}
public override void OnCollision(IGameObject obj)
{
2021-04-19 15:41:37 +02:00
if (obj.Type == ObjectType.Projectile) return;
if (obj.Type == ObjectType.Player)
{
var player = (Player)obj;
if (player.Vacuuming)
{
2021-04-21 18:39:33 +02:00
player.CurrentWeapon.Reload(rnd.Next(player.CurrentWeapon.MaxAmmo/4));
2021-04-24 18:47:51 +02:00
Screen.Manager.Computer.Play("CollectDebris");
2021-04-19 23:37:40 +02:00
Destroy();
2021-04-23 20:28:06 +02:00
GameStats.DebrisCollected++;
2021-04-19 15:41:37 +02:00
return;
}
player.TakeDamage(25);
2021-04-24 23:31:43 +02:00
Screen.Manager.Computer.Play("DamageDebris");
2021-04-19 15:41:37 +02:00
Destroy();
2021-04-23 20:28:06 +02:00
GameStats.SatelliteCollisions++;
2021-04-19 15:41:37 +02:00
}
2021-04-18 00:27:13 +02:00
}
}
}