Files
evilsatellites/EvilSatellites/Objects/Player.cs
T

95 lines
2.9 KiB
C#
Raw Normal View History

2021-04-10 14:08:20 +02:00
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
2021-04-11 02:01:24 +02:00
using SynthySound;
2021-04-11 17:09:57 +02:00
using EvilSatellites.Screens;
using EvilSatellites.Weapons;
2021-04-10 14:08:20 +02:00
namespace EvilSatellites.Objects
{
public class Player : AbstractGameObject
{
private Vector3 _PrevPos;
2021-04-11 20:43:29 +02:00
private Vector3 MaxSpeed = new Vector3(0.2f, 0.2f, 0.2f);
public Vector3 Acceleration = new Vector3(0.008f, 0.008f, 0.008f);
private Vector3 Deceleration = new Vector3(0.0025f, 0.0025f, 0.0025f);
2021-04-11 02:01:24 +02:00
private ISoundEffect sfxEngine;
private ISoundEffect sfxWhine;
2021-04-11 17:09:57 +02:00
public IWeapon CurrentWeapon;
2021-04-10 14:08:20 +02:00
public Player(IScreen screen): base(screen)
{
2021-04-11 18:42:22 +02:00
ShouldDestroy = false;
Active = true;
2021-04-10 14:08:20 +02:00
Type = ObjectType.Player;
2021-04-11 20:43:29 +02:00
Position = new Vector3(0, 0, 0);
2021-04-11 02:01:24 +02:00
Dimensions = new Vector3(5, 5, 5);
Movement = new Vector3(0, 0, 0);
2021-04-10 14:08:20 +02:00
Rotation = Matrix.Identity;
Orientation = Rotation.Forward;
2021-04-11 18:42:22 +02:00
CurrentWeapon = new LaserMG(this, (GameScreen)Screen);
2021-04-10 14:08:20 +02:00
Activate();
}
override public void Activate()
{
2021-04-11 02:01:24 +02:00
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();
2021-04-10 14:08:20 +02:00
return;
}
public override void Destroy()
{
return;
}
override public void Update(GameTime gameTime)
{
2021-04-11 17:09:57 +02:00
CurrentWeapon.Update(gameTime);
2021-04-11 02:01:24 +02:00
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;
}
}
}
2021-04-11 14:12:55 +02:00
public void Accelerate(Vector3 direction)
2021-04-11 02:01:24 +02:00
{
if (Math.Abs(Movement.X) < MaxSpeed.X && Math.Abs(Movement.Y) < MaxSpeed.Y && Math.Abs(Movement.Z) < MaxSpeed.Z)
{
2021-04-11 14:12:55 +02:00
Movement += direction;
2021-04-11 02:01:24 +02:00
}
2021-04-10 14:08:20 +02:00
}
}
}