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-18 22:35:49 +02:00
|
|
|
private SoundPatch sfxElevator;
|
|
|
|
|
private SoundPatch sfxVacuum;
|
|
|
|
|
private SoundPatch sfxTurn;
|
2021-04-11 17:09:57 +02:00
|
|
|
public IWeapon CurrentWeapon;
|
2021-04-18 22:35:49 +02:00
|
|
|
private int Turning;
|
|
|
|
|
private int Elevating;
|
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-18 22:35:49 +02:00
|
|
|
Turning = 0;
|
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);
|
2021-04-18 22:35:49 +02:00
|
|
|
sfxTurn = new SoundPatch(Screen.Manager.Sound, @"sfx/ship/turn", 200);
|
|
|
|
|
sfxVacuum = new SoundPatch(Screen.Manager.Sound, @"sfx/ship/vacuum", 500);
|
|
|
|
|
sfxElevator = new SoundPatch(Screen.Manager.Sound, @"sfx/ship/elevator", 250);
|
2021-04-11 02:01:24 +02:00
|
|
|
sfxEngine.Loop = true;
|
|
|
|
|
sfxWhine.Loop = true;
|
2021-04-15 01:30:13 +02:00
|
|
|
sfxEngine.ConnectToEffect(Screen.Manager.EnvironmentEffect);
|
|
|
|
|
sfxWhine.ConnectToEffect(Screen.Manager.EnvironmentEffect);
|
2021-04-11 02:01:24 +02:00
|
|
|
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);
|
2021-04-18 22:35:49 +02:00
|
|
|
if (Turning == -1)
|
|
|
|
|
{
|
|
|
|
|
RotateY(0.035f);
|
|
|
|
|
}
|
|
|
|
|
if (Turning == 1)
|
|
|
|
|
{
|
|
|
|
|
RotateY(-0.035f);
|
|
|
|
|
}
|
|
|
|
|
if (Elevating == -1)
|
|
|
|
|
{
|
|
|
|
|
RotateX(-0.035f);
|
|
|
|
|
}
|
|
|
|
|
if (Elevating == 1)
|
|
|
|
|
{
|
|
|
|
|
RotateX(0.035f);
|
|
|
|
|
}
|
2021-04-11 02:01:24 +02:00
|
|
|
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);
|
2021-04-18 22:35:49 +02:00
|
|
|
sfxTurn.Update(gameTime);
|
|
|
|
|
sfxElevator.Update(gameTime);
|
|
|
|
|
sfxVacuum.Update(gameTime);
|
2021-04-11 02:01:24 +02:00
|
|
|
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
|
|
|
}
|
2021-04-18 22:35:49 +02:00
|
|
|
|
|
|
|
|
public void StartTurning(int dir, GameTime time)
|
|
|
|
|
{
|
|
|
|
|
Turning = dir;
|
|
|
|
|
sfxTurn.Start(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopTurning()
|
|
|
|
|
{
|
|
|
|
|
Turning = 0;
|
|
|
|
|
sfxTurn.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartElevating(int dir, GameTime time)
|
|
|
|
|
{
|
|
|
|
|
Elevating = dir;
|
|
|
|
|
sfxElevator.Start(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopElevating()
|
|
|
|
|
{
|
|
|
|
|
Elevating = 0;
|
|
|
|
|
sfxElevator.Stop();
|
|
|
|
|
}
|
2021-04-10 14:08:20 +02:00
|
|
|
}
|
|
|
|
|
}
|