Files
evilsatellites/EvilSatellites/Objects/Player.cs
T
2021-04-11 17:09:57 +02:00

92 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using SynthySound;
using EvilSatellites.Screens;
using EvilSatellites.Weapons;
namespace EvilSatellites.Objects
{
public class Player : AbstractGameObject
{
private Vector3 _PrevPos;
private Vector3 MaxSpeed = new Vector3(1, 1, 1);
private Vector3 Deceleration = new Vector3(0.005f, 0.005f, 0.005f);
private ISoundEffect sfxEngine;
private ISoundEffect sfxWhine;
public IWeapon CurrentWeapon;
public Player(IScreen screen): base(screen)
{
Type = ObjectType.Player;
Position = new Vector3(10, 0, 0);
Dimensions = new Vector3(5, 5, 5);
Movement = new Vector3(0, 0, 0);
Rotation = Matrix.Identity;
Orientation = Rotation.Forward;
CurrentWeapon = new LaserMG(this, Screen);
Activate();
}
override public void Activate()
{
sfxEngine = Screen.Manager.Sound.Load(@"sfx/engine/int/engineThrust.wav", false);
sfxWhine = Screen.Manager.Sound.Load(@"sfx/engine/int/engineWhine.wav", false);
sfxEngine.Loop = true;
sfxWhine.Loop = true;
sfxEngine.Play();
sfxWhine.Play();
return;
}
public override void Destroy()
{
return;
}
override public void Update(GameTime gameTime)
{
CurrentWeapon.Update(gameTime);
Move(Movement);
sfxEngine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 4;
sfxWhine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 1;
sfxWhine.Volume = MathF.Pow(Movement.Length() / MaxSpeed.Length(), 2f);
if (Movement.Length() != 0)
{
if (Movement.X > 0)
{
Movement.X -= Deceleration.X;
} else
{
Movement.X += Deceleration.X;
}
if (Movement.Y > 0)
{
Movement.Y -= Deceleration.Y;
}
else
{
Movement.Y += Deceleration.Y;
}
if (Movement.Z > 0)
{
Movement.Z -= Deceleration.Z;
}
else
{
Movement.Z += Deceleration.Z;
}
}
}
public void Accelerate(Vector3 direction)
{
if (Math.Abs(Movement.X) < MaxSpeed.X && Math.Abs(Movement.Y) < MaxSpeed.Y && Math.Abs(Movement.Z) < MaxSpeed.Z)
{
Movement += direction;
}
}
}
}