Files
blackhole-escape/Assets/Scripts/Scripts/CoreHoverMovement.cs
iDunnoDev 3ab4b78a79 Added Accessors for the GameManager to get the Score, Cores and Level values
Added a Score to the Game
Added an actual blackhole material and shader to the black hole
Added a new Main menu and How to Play menu system
Added Beam swords to all ships (replacing the light saber things the player had)
Added a pause menu
Overhauled the UI for the game scene
Added List to hold the amount of core energy needed for each level
Added the URP package for better rendering (apparently)
Added a GameState enum to set which part of the game the player is in
Added Magnet powerup to game
Changed the way powerups are spawned, enemies now have a loot table
Changed cores to core energy which is a percentage needed to pass a level
Changed all the Ints to Hidden Value ints to maybe stop cheat engine users finding the important values
Changed all level loads to use sceneloadasync
Updated all of the materials to use URP shaders
Removed Junk Files from external sources
Rearranged the folders inside the unity project to try and reduce some name length issues
2022-06-30 01:09:48 +01:00

165 lines
5.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the cores movement around the blackhole
/// </summary>
public class CoreHoverMovement : HoverMovement
{
// Residual Thrust variables to handle the "glide" after the gameObject has moved
public float residualThrustStep;
public float residualThrustMax;
public float residualThrustTimeTickMax;
public float residualThrustDecayRate;
public float residualThrustIdleDecayRate;
private float _residualThrust;
private float _residualThrustCurrentTime;
// RNG Variables used for the fake AI (for testing) movement
private float _rngVert;
private float _rngHorz;
// Start is called before the first frame update
void Start()
{
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_rngHorz = 0.0f;
_rngVert = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
/// <summary>
/// Calculates some RNG movement for the attached core.
/// </summary>
/// <param name="currentTimeStep">The time unit currently used, typically deltatime or deltafixed time depending on if its the fixed update or not.</param>
void DoRNG(float currentTimeStep)
{
// Cores dont move at the moment but the movescript can be used above if they need to orbit around the blackhole
_rngHorz = 0;
_rngVert = 1;
}
/// <summary>
/// Processes the inputs needed to move the gameobject, the turn direction, thrust direction and any residual thrust calculations so that we dont just stop in place.
/// </summary>
/// <param name="currentTimeStep">The time unit currently used, typically deltatime or deltafixed time depending on if its the fixed update or not.</param>
public override void ProcessPreMovement(float currentTimeStep)
{
// Check if the movement has been frozen
if (!freezeMovement)
{
// Get the horz and vert values for the left/right, up/down movement
float horzInput = _rngHorz;
float vertInput = _rngVert;
// Turn Right
if (horzInput > 0)
{
_turnDirection = 1;
}
// Turn Left
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Forward/Thrust
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
// If our momentum isnt full keep adding to the value
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
// Backwards/Breaking
else if (vertInput < 0)
{
// If we have momentum drain it faster when hitting backwards
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
// Continue movement if there is momentum remaining
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the thrust to 0 and the max value
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
private void FixedUpdate()
{
if (!GameEngine.isPaused)
{
if (objectIsActive)
{
//ProcessJump();
}
}
}
// Update is called once per frame
void Update()
{
if (!GameEngine.isPaused)
{
if (objectIsActive)
{
DoRNG(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
}
}
}
}