Added Main menu Changes to UI

Added Rules Menu Changes to UI
Added Cutscenes to the rules scene
Reorganised Files
This commit is contained in:
iDunnoDev
2022-06-22 13:30:58 +01:00
committed by iDunnoDev
parent e30ffcfc80
commit 0360907df1
1276 changed files with 55430 additions and 32901 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 141976293a22f1442be78e5bf7ad9427
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,315 @@
using UnityEngine;
public class ChaserEnemyHoverMovement : HoverMovement
{
// Game object to track the player GO
private GameObject _player;
private GameObject _blackHole;
// 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;
public float jumpForce;
public float jumpMaxTime;
private float _residualThrust;
private float _residualThrustCurrentTime;
private float _currentJumpTime;
private bool _isJumping;
// Variables for RNG movement
private float _aiVert;
private float _aiHorz;
private bool _aiJump;
public float chargePower;
public float chargeCooldown;
public float chargeCooldownSpeed;
private bool _charged;
private float _currentChargeCooldownTick;
public override void DoAwakeTasks()
{
base.DoAwakeTasks();
}
// Start is called before the first frame update
void Start()
{
// We have to find the player since setting it in the editor doesnt work correctly
_player = GameObject.Find("Player");
_blackHole = GameObject.Find("BlackHole");
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
_aiHorz = 0.0f;
_aiVert = 0.0f;
_charged = false;
_currentChargeCooldownTick = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
void DoAIPhysics(float currentTimeStep)
{
RaycastHit belowCheck;
Physics.SphereCast(transform.position, 2.0f, -transform.up, out belowCheck, 5.0f, LayerMask.GetMask("Player"));
if (belowCheck.rigidbody != null)
{
if (!_charged)
{
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
if (playerHeight + 1.0f < GetCurrentHeight())
{
_objectRigidbody.AddRelativeForce(Vector3.down * chargePower, ForceMode.Impulse);
_charged = true;
}
}
}
}
/// <summary>
/// Calculates some RNG movement for the attached Enemy.
/// </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 DoAI(float currentTimeStep)
{
// Get the Up vector of each gameObject so we can compare its X values rather than the Y
Vector3 playerDirection = _player.transform.position - transform.position;
Vector3 playerLocation = Vector3.ProjectOnPlane(_player.transform.position, Vector3.forward);
Vector3 myLocation = Vector3.ProjectOnPlane(transform.position, Vector3.forward);
Vector3 direction = playerLocation - myLocation;
float angleDiff = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
float facingPlayer = Vector3.Dot(playerDirection.normalized, transform.forward);
// Added a check to see if the difference is big enough to warrant a turn otherwise they just get stuck turning forever
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
_aiVert = 1;
if (facingPlayer > 0.8f)
{
_aiHorz = 0.0f;
if (playerDirection.magnitude <= 10.0f)
{
if (!_charged)
{
if (playerHeight + 1.5f > GetCurrentHeight())
{
_aiJump = false;
}
else
{
_aiJump = true;
}
}
}
else
{
if (playerHeight > GetCurrentHeight())
{
_aiJump = true;
}
}
}
else
{
_aiHorz = angleDiff;
if ((playerHeight - 0.5f) >= GetCurrentHeight())
{
RaycastHit aboveCheck;
Physics.SphereCast(transform.position, 3.0f, transform.up, out aboveCheck, 5.0f, LayerMask.GetMask("Player"));
if (aboveCheck.rigidbody != null)
{
if (GetCurrentHeight() < playerHeight)
{
_objectRigidbody.velocity = Vector3.zero;
_aiJump = false;
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = false;
}
}
}
/// <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.
/// Anything in this method can be removed, as long as the _turnDirection and _thrustDirection are set then the parent script with handle the orbit and positioning.
/// </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 movement has been frozen
if (!freezeMovement)
{
// Get the Horz and Vert axis from the RNG (or whatever vars you want)
float horzInput = _aiHorz;
float vertInput = _aiVert;
// Check horz direction value, pos = Right, neg = Left
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Check if the vert is pushed forwards or back, pos = forward, neg = back
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
// If the Enemy is holding backwards
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the residual thrust so we cant fall below 0 or greater than the max value set
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Check if the jump button
if (_aiJump && !_isJumping)
{
_isJumping = true;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
/// <summary>
/// Method for dealing with the jump physics, this should be in the fixed update since it uses rigidbody physics
/// </summary>
void ProcessJump()
{
// If the enemy is jumping add the jump force
if (_isJumping)
{
_objectRigidbody.AddRelativeForce(Vector3.up * jumpForce * Time.fixedDeltaTime, ForceMode.Impulse);
if (_currentJumpTime >= jumpMaxTime)
{
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
}
else
{
_currentJumpTime += Time.fixedDeltaTime;
}
}
}
void ProcessCooldowns(float currentTimeStep)
{
if (_charged)
{
if (_currentChargeCooldownTick >= chargeCooldown)
{
_charged = false;
_currentChargeCooldownTick = 0.0f;
}
else
{
_currentChargeCooldownTick += currentTimeStep;
}
}
}
private void FixedUpdate()
{
if (objectIsActive)
{
DoAIPhysics(Time.fixedDeltaTime);
ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoAI(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
ProcessCooldowns(Time.deltaTime);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d1418ef6aa254b447abe9685693e37c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,374 @@
using UnityEngine;
public class CowardEnemyHoverMovement : HoverMovement
{
public GameObject minePrefab;
public float mineSpawnChance;
public float mineSpawnCooldown;
private float _mineSpawnTick;
private bool _canSpawnMine;
// Game object to track the player GO
private GameObject _player;
private GameObject _blackHole;
// 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;
public float jumpForce;
public float jumpMaxTime;
private float _residualThrust;
private float _residualThrustCurrentTime;
private float _currentJumpTime;
private bool _isJumping;
// Variables for RNG movement
private float _aiVert;
private float _aiHorz;
private bool _aiJump;
public float cowerDistance;
public float emergencyBoostSpeed;
public float emergencyBoostCooldownSpeed;
public float emergencyBoostTime;
public float emergencyBoostCooldown;
private bool _emergencyBoosting;
private bool _emergencyBoosted;
private float _currentEmergencyBoostingTick;
private float _currentEmergencyBoosterCooldownTick;
private float _currentHoldHeight;
private float _heightChangeTick;
public float heightChangeInterval;
public override void DoAwakeTasks()
{
base.DoAwakeTasks();
}
// Start is called before the first frame update
void Start()
{
// We have to find the player since setting it in the editor doesnt work correctly
_player = GameObject.Find("Player");
_blackHole = GameObject.Find("BlackHole");
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
_aiHorz = 0.0f;
_aiVert = 0.0f;
_emergencyBoosting = false;
_emergencyBoosted = false;
_currentEmergencyBoosterCooldownTick = 0.0f;
_currentHoldHeight = GetCurrentHeight();
_heightChangeTick = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
void DoAIPhysics(float currentTimeStep)
{
}
/// <summary>
/// Calculates some RNG movement for the attached Enemy.
/// </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 DoAI(float currentTimeStep)
{
// Get the Up vector of each gameObject so we can compare its X values rather than the Y
Vector3 playerDirection = _player.transform.position - transform.position;
Vector3 playerLocation = Vector3.ProjectOnPlane(_player.transform.position, Vector3.up);
Vector3 myLocation = Vector3.ProjectOnPlane(transform.position, Vector3.forward);
Vector3 direction = playerLocation - myLocation;
float facingPlayer = Vector3.Dot(playerDirection.normalized, transform.forward);
// Added a check to see if the difference is big enough to warrant a turn otherwise they just get stuck turning forever
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
_aiVert = 1;
_aiHorz = 0.0f;
if (playerDirection.magnitude <= cowerDistance)
{
if (!_emergencyBoosting && !_emergencyBoosted)
{
// Try to boost away
_emergencyBoosting = true;
_canSpawnMine = false;
_mineSpawnTick = 0.0f;
// Force a height change for fun
_heightChangeTick = heightChangeInterval;
}
}
if (!(facingPlayer < 0.5f && facingPlayer > -0.5f))
{
_aiHorz = -direction.normalized.x;
}
if (_currentHoldHeight >= GetCurrentHeight())
{
RaycastHit aboveCheck;
Physics.SphereCast(transform.position, 3.0f, transform.up, out aboveCheck, 5.0f, LayerMask.GetMask("Player"));
if (aboveCheck.rigidbody != null)
{
if ((GetCurrentHeight() < playerHeight))
{
_objectRigidbody.velocity = Vector3.zero;
_aiJump = false;
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = false;
}
if (minePrefab != null)
{
if (_canSpawnMine && _emergencyBoosting)
{
DoAMineSpawn();
}
}
}
private void DoAMineSpawn()
{
GameObject newMine = Instantiate(minePrefab);
MineHoverMovement mineMovement = newMine.GetComponent<MineHoverMovement>();
if (mineMovement)
{
mineMovement.startPositionVector = transform.position + (-transform.forward * 2.0f);
mineMovement.startHeight = GetCurrentHeight() - 0.5f;
}
newMine.SetActive(true);
_canSpawnMine = false;
}
/// <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.
/// Anything in this method can be removed, as long as the _turnDirection and _thrustDirection are set then the parent script with handle the orbit and positioning.
/// </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 movement has been frozen
if (!freezeMovement)
{
// Get the Horz and Vert axis from the RNG (or whatever vars you want)
float horzInput = _aiHorz;
float vertInput = _aiVert;
// Check horz direction value, pos = Right, neg = Left
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Check if the vert is pushed forwards or back, pos = forward, neg = back
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_emergencyBoosting)
{
_thrustDirection *= emergencyBoostSpeed;
}
else if (_emergencyBoosted)
{
_thrustDirection *= emergencyBoostCooldownSpeed;
}
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
// If the Enemy is holding backwards
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the residual thrust so we cant fall below 0 or greater than the max value set
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Check if the jump button
if (_aiJump && !_isJumping)
{
_isJumping = true;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
/// <summary>
/// Method for dealing with the jump physics, this should be in the fixed update since it uses rigidbody physics
/// </summary>
void ProcessJump()
{
// If the enemy is jumping add the jump force
if (_isJumping)
{
_objectRigidbody.AddRelativeForce(Vector3.up * jumpForce * Time.fixedDeltaTime, ForceMode.Impulse);
if (_currentJumpTime >= jumpMaxTime)
{
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
}
else
{
_currentJumpTime += Time.fixedDeltaTime;
}
}
}
void ProcessCooldowns(float currentTimeStep)
{
if (_emergencyBoosting)
{
if (_currentEmergencyBoostingTick >= emergencyBoostTime)
{
_emergencyBoosted = true;
_emergencyBoosting = false;
_currentEmergencyBoostingTick = 0.0f;
}
else
{
_currentEmergencyBoostingTick += currentTimeStep;
}
}
if (_emergencyBoosted)
{
if (_currentEmergencyBoosterCooldownTick >= emergencyBoostCooldown)
{
_emergencyBoosted = false;
_currentEmergencyBoosterCooldownTick = 0.0f;
}
else
{
_currentEmergencyBoosterCooldownTick += currentTimeStep;
}
}
if (_heightChangeTick >= heightChangeInterval)
{
_currentHoldHeight = Random.Range(startHeight, startHeight + 5.0f);
_heightChangeTick = 0.0f;
}
else
{
_heightChangeTick += currentTimeStep;
}
if (!_canSpawnMine)
{
if (_mineSpawnTick >= mineSpawnCooldown)
{
_mineSpawnTick = 0.0f;
_canSpawnMine = true;
}
else
{
_mineSpawnTick += currentTimeStep;
}
}
}
private void FixedUpdate()
{
if (objectIsActive)
{
DoAIPhysics(Time.fixedDeltaTime);
ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoAI(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
ProcessCooldowns(Time.deltaTime);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ba55a93cceb2a445b30aa36e7374902
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,303 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DropperEnemyHoverMovement : HoverMovement
{
// Game object to track the player GO
private GameObject _player;
private GameObject _blackHole;
// 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;
public float jumpForce;
public float jumpMaxTime;
private float _residualThrust;
private float _residualThrustCurrentTime;
private float _currentJumpTime;
private bool _isJumping;
// Variables for RNG movement
private float _aiVert;
private float _aiHorz;
private bool _aiJump;
public float dropPower;
public float dropCooldown;
public float dropCooldownSpeed;
private bool _dropped;
private float _currentDropCooldownTick;
public override void DoAwakeTasks()
{
base.DoAwakeTasks();
}
// Start is called before the first frame update
void Start()
{
// We have to find the player since setting it in the editor doesnt work correctly
_player = GameObject.Find("Player");
_blackHole = GameObject.Find("BlackHole");
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
_aiHorz = 0.0f;
_aiVert = 0.0f;
_dropped = false;
_currentDropCooldownTick = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
void DoAIPhysics(float currentTimeStep)
{
RaycastHit belowCheck;
Physics.SphereCast(transform.position, 5.0f, -transform.up, out belowCheck, 6.0f, LayerMask.GetMask("Player"));
if (belowCheck.rigidbody != null)
{
if (!_dropped)
{
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
if (playerHeight + 1.0f < GetCurrentHeight())
{
_objectRigidbody.AddRelativeForce(Vector3.down * dropPower, ForceMode.Impulse);
_dropped = true;
}
}
}
}
/// <summary>
/// Calculates some RNG movement for the attached Enemy.
/// </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 DoAI(float currentTimeStep)
{
// Get the Up vector of each gameObject so we can compare its X values rather than the Y
Vector3 playerDirection = _player.transform.position - transform.position;
Vector3 playerLocation = Vector3.ProjectOnPlane(_player.transform.position, Vector3.forward);
Vector3 myLocation = Vector3.ProjectOnPlane(transform.position, Vector3.forward);
Vector3 direction = playerLocation - myLocation;
float angleDiff = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
float facingPlayer = Vector3.Dot(playerDirection.normalized, transform.forward);
// Added a check to see if the difference is big enough to warrant a turn otherwise they just get stuck turning forever
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
_aiVert = 1;
if (facingPlayer > 0.8f)
{
_aiHorz = 0.0f;
}
else
{
_aiHorz = angleDiff;
}
if (!_dropped)
{
if ((playerHeight + 1.5f) >= GetCurrentHeight())
{
RaycastHit aboveCheck;
Physics.SphereCast(transform.position, 3.0f, transform.up, out aboveCheck, 5.0f, LayerMask.GetMask("Player"));
if (aboveCheck.rigidbody != null)
{
if (GetCurrentHeight() < playerHeight)
{
_objectRigidbody.velocity = Vector3.zero;
_aiJump = false;
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = false;
}
}
else
{
_aiJump = false;
}
}
/// <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.
/// Anything in this method can be removed, as long as the _turnDirection and _thrustDirection are set then the parent script with handle the orbit and positioning.
/// </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 movement has been frozen
if (!freezeMovement)
{
// Get the Horz and Vert axis from the RNG (or whatever vars you want)
float horzInput = _aiHorz;
float vertInput = _aiVert;
// Check horz direction value, pos = Right, neg = Left
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Check if the vert is pushed forwards or back, pos = forward, neg = back
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
// If the Enemy is holding backwards
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the residual thrust so we cant fall below 0 or greater than the max value set
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Check if the jump button
if (_aiJump && !_isJumping)
{
_isJumping = true;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
/// <summary>
/// Method for dealing with the jump physics, this should be in the fixed update since it uses rigidbody physics
/// </summary>
void ProcessJump()
{
// If the enemy is jumping add the jump force
if (_isJumping)
{
_objectRigidbody.AddRelativeForce(Vector3.up * jumpForce * Time.fixedDeltaTime, ForceMode.Impulse);
if (_currentJumpTime >= jumpMaxTime)
{
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
}
else
{
_currentJumpTime += Time.fixedDeltaTime;
}
}
}
void ProcessCooldowns(float currentTimeStep)
{
if (_dropped)
{
if (_currentDropCooldownTick >= dropCooldown)
{
_dropped = false;
_currentDropCooldownTick = 0.0f;
}
else
{
_currentDropCooldownTick += currentTimeStep;
}
}
}
private void FixedUpdate()
{
if (objectIsActive)
{
DoAIPhysics(Time.fixedDeltaTime);
ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoAI(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
ProcessCooldowns(Time.deltaTime);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e62a29b488c07c746902280cf28c0cc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,299 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DumbEnemyHoverMovement : HoverMovement
{
// Game object to track the player GO
private GameObject _player;
private GameObject _blackHole;
// 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;
public float jumpForce;
public float jumpMaxTime;
private float _residualThrust;
private float _residualThrustCurrentTime;
private float _currentJumpTime;
private bool _isJumping;
// Variables for RNG movement
private float _aiVert;
private float _aiHorz;
private bool _aiJump;
public float maxRNGThrust;
public float movementDecayRate;
public float movementTickMax;
private float _movementCurrentTick;
private float _currentHoldHeight;
private float _heightChangeTick;
public float heightChangeInterval;
public override void DoAwakeTasks()
{
base.DoAwakeTasks();
}
// Start is called before the first frame update
void Start()
{
// We have to find the player since setting it in the editor doesnt work correctly
_player = GameObject.Find("Player");
_blackHole = GameObject.Find("BlackHole");
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
_aiHorz = 0.0f;
_aiVert = 0.0f;
_currentHoldHeight = GetCurrentHeight();
_heightChangeTick = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
void DoAIPhysics(float currentTimeStep)
{
}
/// <summary>
/// Calculates some RNG movement for the attached Enemy.
/// </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 DoAI(float currentTimeStep)
{
// Get the Up vector of each gameObject so we can compare its X values rather than the Y
Vector3 playerDirection = _player.transform.position - transform.position;
Vector3 playerLocation = Vector3.ProjectOnPlane(_player.transform.position, Vector3.up);
Vector3 myLocation = Vector3.ProjectOnPlane(transform.position, Vector3.forward);
// Added a check to see if the difference is big enough to warrant a turn otherwise they just get stuck turning forever
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
_aiVert = 1;
if (_movementCurrentTick >= movementTickMax)
{
// Pick a random horz value
if (_aiHorz == 0)
{
_aiHorz = Random.Range(0, maxRNGThrust);
}
// Pick a random vert value
if (_aiVert == 0)
{
_aiVert = Random.Range(0, maxRNGThrust);
}
_movementCurrentTick = 0.0f;
}
else
{
// Reset the variables to stop it turning/moving
if (_aiHorz > 0)
{
_aiHorz = Mathf.Clamp(_aiHorz - movementDecayRate, 0, maxRNGThrust); ;
}
if (_aiVert > 0)
{
_aiVert = Mathf.Clamp(_aiVert - movementDecayRate, 0, maxRNGThrust);
}
_movementCurrentTick += currentTimeStep;
}
if (_currentHoldHeight >= GetCurrentHeight())
{
RaycastHit aboveCheck;
Physics.SphereCast(transform.position, 3.0f, transform.up, out aboveCheck, 5.0f, LayerMask.GetMask("Player"));
if (aboveCheck.rigidbody != null)
{
if ((GetCurrentHeight() < playerHeight))
{
_objectRigidbody.velocity = Vector3.zero;
_aiJump = false;
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = false;
}
}
/// <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.
/// Anything in this method can be removed, as long as the _turnDirection and _thrustDirection are set then the parent script with handle the orbit and positioning.
/// </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 movement has been frozen
if (!freezeMovement)
{
// Get the Horz and Vert axis from the RNG (or whatever vars you want)
float horzInput = _aiHorz;
float vertInput = _aiVert;
// Check horz direction value, pos = Right, neg = Left
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Check if the vert is pushed forwards or back, pos = forward, neg = back
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
// If the Enemy is holding backwards
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the residual thrust so we cant fall below 0 or greater than the max value set
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Check if the jump button
if (_aiJump && !_isJumping)
{
_isJumping = true;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
/// <summary>
/// Method for dealing with the jump physics, this should be in the fixed update since it uses rigidbody physics
/// </summary>
void ProcessJump()
{
// If the enemy is jumping add the jump force
if (_isJumping)
{
_objectRigidbody.AddRelativeForce(Vector3.up * jumpForce * Time.fixedDeltaTime, ForceMode.Impulse);
if (_currentJumpTime >= jumpMaxTime)
{
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
}
else
{
_currentJumpTime += Time.fixedDeltaTime;
}
}
}
void ProcessCooldowns(float currentTimeStep)
{
if (_heightChangeTick >= heightChangeInterval)
{
_currentHoldHeight = Random.Range(startHeight, startHeight + 5.0f);
_heightChangeTick = 0.0f;
}
else
{
_heightChangeTick += currentTimeStep;
}
}
private void FixedUpdate()
{
if (objectIsActive)
{
DoAIPhysics(Time.fixedDeltaTime);
ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoAI(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
ProcessCooldowns(Time.deltaTime);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c8ec1231712f114fadcaaccd759a307
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d133992f754c96f4c9b6818ce5c6e2d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,365 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the debug console and its commands/cheats
/// </summary>
public class DebugConsoleManager : MonoBehaviour
{
private bool _toggleWindow = false;
private string _commandIn;
// List to hold previously used commands so we can go up and down them.
private List<string> _prevCommands = new List<string>();
private List<string> _commandOutput = new List<string>();
private int _prevCommandIndex = 0;
/// <summary>
/// Method to toggle the debug console
/// </summary>
public void ToggleDebugConsole(bool force = false)
{
if (_toggleWindow && !force)
{
Time.timeScale = 1.0f;
_toggleWindow = false;
}
else
{
Time.timeScale = 0.0f;
_toggleWindow = true;
}
}
private void OnGUI()
{
if (!_toggleWindow)
{
return;
}
// Draw the GUI box for the console box at the top of the screen
GUI.Box(new Rect(0, 0, Screen.width, 30), "");
GUI.backgroundColor = new Color(0, 0, 0, 0);
// This block checks for keypresses by the user whilst the GUI is shown since the actual game time is paused
Event currentEvent = Event.current;
if (currentEvent.type == EventType.KeyDown)
{
switch (currentEvent.keyCode)
{
// just close the menu if the tilde or backquote key is pushed
case KeyCode.Tilde:
case KeyCode.BackQuote:
GUI.FocusControl(null);
ToggleDebugConsole();
return;
// Up gets the last command in the list
case KeyCode.UpArrow:
if (_prevCommands.Count > 0)
{
_commandIn = _prevCommands[_prevCommandIndex];
if (_prevCommandIndex > 0)
{
_prevCommandIndex -= 1;
}
}
break;
// Down gets the next command in the list
case KeyCode.DownArrow:
if (_prevCommands.Count > 0)
{
_commandIn = _prevCommands[_prevCommandIndex];
if (_prevCommandIndex < _prevCommands.Count - 1)
{
_prevCommandIndex += 1;
}
}
break;
// Return parses the command
case KeyCode.Return:
GUI.FocusControl(null);
ToggleDebugConsole();
if (_commandIn.Trim().Length > 0)
{
ParseCommand(_commandIn.Trim());
_prevCommands.Add(_commandIn);
_prevCommandIndex = _prevCommands.Count - 1;
}
_commandIn = "";
return;
}
}
// Wait for user input
GUI.SetNextControlName("DebugConsole");
_commandIn = GUI.TextField(new Rect(10.0f, 5.0f, Screen.width - 20.0f, 20.0f), _commandIn);
GUI.FocusControl("DebugConsole");
}
/// <summary>
/// Method to parse the given command and run it
/// </summary>
/// <param name="currentCommand">Command string to parse</param>
private void ParseCommand(string currentCommand)
{
// Split the command by its space characters, first command part should always be the actual command with parameters following
string[] commandParts = currentCommand.ToLower().Split(' ');
switch(commandParts[0])
{
// Suicide player
case "die":
case "kilme":
KillPlayer();
break;
// Heal the player back to full lives
case "fullheal":
case "pillshere":
HealPlayer();
break;
// God Mode player
case "god":
GodModeToggle();
break;
// Turn off gravity for the player, will probs change to keep the player x height above the blackhole since you cant jump down
case "nosuck":
TogglePlayerGravity();
break;
case "freezeall":
ToggleFreezeAll();
break;
// Adds X amount of cores to the player
case "addcore":
int pickupAmount = 1;
if (commandParts.Length > 1)
{
int.TryParse(commandParts[1], out pickupAmount);
}
AddCore(pickupAmount);
break;
// Next Level
case "levelup":
DoLevelJump(1);
break;
case "setlevel":
int levelJump = 0;
if (commandParts.Length > 1)
{
int.TryParse(commandParts[1], out levelJump);
}
DoLevelJump(levelJump);
break;
case "imreallybadatthisgame":
DoLevelJump(100);
break;
// Pick up all current cores floating in the scene
case "pickupall":
PickupAll();
break;
case "fall":
DoFall();
break;
// Kill all of the current enemies on the scene
case "killall":
KillAllEnemies();
break;
case "spawn":
if (commandParts.Length > 1)
{
string spawnType = commandParts[1];
int amountToSpawn = 1;
if (commandParts.Length > 2)
{
int.TryParse(commandParts[2], out amountToSpawn);
}
int randomSpawnLoc = 0;
if (commandParts.Length > 3)
{
int.TryParse(commandParts[3], out randomSpawnLoc);
}
DoSpawn(spawnType, amountToSpawn, randomSpawnLoc);
}
break;
}
}
private void DoFall()
{
GameObject[] enemiesSpawned = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemiesSpawned)
{
EnemyObjectShared enemyOS = enemy.GetComponent<EnemyObjectShared>();
if (enemyOS != null)
{
enemyOS.DoFailure();
}
}
}
private void DoSpawn(string spawnType, int spawnAmount, int spawnRandomLoc)
{
int spawnPrefabId = -1;
switch (spawnType)
{
case "dumb":
spawnPrefabId = 0;
break;
case "coward":
spawnPrefabId = 1;
break;
case "chase":
spawnPrefabId = 2;
break;
case "drop":
spawnPrefabId = 3;
break;
case "mine":
spawnPrefabId = 4;
break;
case "rock":
spawnPrefabId = 5;
break;
case "core":
spawnPrefabId = 6;
break;
case "health":
spawnPrefabId = 7;
break;
case "shield":
spawnPrefabId = 8;
break;
}
if (spawnPrefabId != -1)
{
DebugSpawning debugSpawner = GameObject.Find("DebugSpawner").GetComponent<DebugSpawning>();
if (debugSpawner != null)
{
bool randomSpawnLocBool = false;
if (spawnRandomLoc == 1)
{
randomSpawnLocBool = true;
}
for (int i = 0; i < spawnAmount; i++)
{
debugSpawner.DoADebugSpawn(spawnPrefabId, randomSpawnLocBool);
}
}
}
}
private void DoLevelJump(int levelsToJump)
{
if (levelsToJump > 0)
{
GameManager.Instance.level = GameManager.Instance.level + levelsToJump;
}
}
private void ToggleFreezeAll()
{
GameObject[] currentEnemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject currentEnemy in currentEnemies)
{
HoverMovement currentEnemyMovement = currentEnemy.GetComponent<HoverMovement>();
if (currentEnemyMovement != null)
{
currentEnemyMovement.freezeMovement = !currentEnemyMovement.freezeMovement;
}
}
}
private void TogglePlayerGravity()
{
PlayerBlackHoleForce currentPlayerBHF = GameObject.Find("Player").GetComponent<PlayerBlackHoleForce>();
if (currentPlayerBHF != null)
{
currentPlayerBHF.blackHolePullImmunue = !currentPlayerBHF.blackHolePullImmunue;
}
}
/// <summary>
/// Method to toggle god mode
/// </summary>
private void GodModeToggle()
{
GameManager.Instance.godMode = !GameManager.Instance.godMode;
}
/// <summary>
/// Method to heal the player to full lives
/// </summary>
private void HealPlayer()
{
GameManager.Instance.lives = 10;
}
/// <summary>
/// Method to kill the player and lose a life
/// </summary>
private void KillPlayer()
{
PlayerColliderManager playerCM = GameObject.Find("Player").GetComponent<PlayerColliderManager>();
if (playerCM != null)
{
playerCM.TriggerDeath();
}
}
/// <summary>
/// Method for adding X amount of cores
/// </summary>
/// <param name="amount">Amount of cores to add</param>
private void AddCore(int amount)
{
for (int i = 0; i < amount; i++)
{
GameManager.Instance.AddCore();
}
}
/// <summary>
/// Method to pick up all of the currently active cores floating on the scene
/// </summary>
private void PickupAll()
{
GameObject[] currentCores = GameObject.FindGameObjectsWithTag("Core");
foreach (GameObject currentCore in currentCores)
{
CoreColliderManager currentCoreCollider = currentCore.GetComponent<CoreColliderManager>();
if (currentCoreCollider != null)
{
currentCoreCollider.PickupCore();
}
}
}
/// <summary>
/// Method to kill all of the current enemies
/// </summary>
private void KillAllEnemies()
{
GameObject[] currentEnemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject currentEnemy in currentEnemies)
{
ColliderManager currentEnemyCollider = currentEnemy.GetComponent<ColliderManager>();
if (currentEnemyCollider != null)
{
currentEnemyCollider.TriggerDeath();
}
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.BackQuote) || Input.GetKeyDown(KeyCode.Tilde))
{
ToggleDebugConsole(true);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ceb6eedfd19fee4f94a3e9cf5dfb44b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DebugSpawning : ObjectSpawning
{
public GameObject[] debugPrefabs;
private void Awake()
{
_spawnedObject = null;
_numberToSpawn = 0;
}
/// <summary>
/// Reduce the spawned counter for this spawner
/// </summary>
public override void ReduceSpawnedCount()
{
objectCount = Mathf.Clamp(objectCount - 1, 0, _numberToSpawn);
base.ReduceSpawnedCount();
}
public void DoADebugSpawn(int prefabIndex, bool randomSpawnLoc)
{
float xPos = Random.Range(-xSpawnRange, xSpawnRange);
float yPos = Random.Range(-ySpawnRange, ySpawnRange);
float zPos = Random.Range(-zSpawnRange, zSpawnRange);
Vector3 spawnLoc = Vector3.zero;
float spawnHeight = 0.0f;
// If debug is checked then try to spawn the object above the player, this is to test collisions
if (!randomSpawnLoc)
{
GameObject currentPlayer = GameObject.Find("Player");
if (currentPlayer != null)
{
PlayerHoverMovement playerHover = currentPlayer.GetComponent<PlayerHoverMovement>();
if (playerHover != null)
{
spawnLoc = currentPlayer.transform.position + (currentPlayer.transform.forward * 10.0f);
spawnHeight = playerHover.GetCurrentHeight() + 2.0f;
}
}
}
else
{
spawnLoc = new Vector3(xPos, yPos, zPos);
spawnHeight = Random.Range(minSpawnHeight, maxSpawnHeight);
}
GameObject newSpawn = Instantiate(debugPrefabs[prefabIndex]);
// Set the start height of the gameObject from the blackhole
HoverMovement newSpawnMovement = newSpawn.GetComponent<HoverMovement>();
if (newSpawnMovement)
{
newSpawnMovement.startPositionVector = spawnLoc;
newSpawnMovement.ForceHeightAdjust(spawnHeight);
}
newSpawn.SetActive(true);
objectCount++;
}
/// <summary>
/// Spawn the gameObject assigned to this spawner
/// </summary>
protected override void DoASpawn()
{
base.DoASpawn();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3a6748c48426d16498548370a153a853
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c595954257860c34688e8c1067a02a9d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CoresMeter : MonoBehaviour
{
public Slider CoreMeterBar;
public void Update()
{
CoreMeterBar.value = GameManager.Instance.getCoreCount();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b3816330663a0944905e7c6c2c19ca2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DeadMenu : MonoBehaviour
{
// Start is called before the first frame update
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
private void Start()
{
Cursor.lockState = CursorLockMode.None;
// If the BGM manager is present, queue up and play the given track index
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(1);
}
}
public void ReStartGame()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
SceneManager.LoadScene("Main Menu");
}
public void Quit()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
Application.Quit();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3de6b36e04a5c3449c7104442440712
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthBar : MonoBehaviour
{
public Slider health;
public void Health(int newHealth)
{
health.value = newHealth;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5933daae7cbc4b841bffbf4413124c75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,146 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class MainMenuEngine : MonoBehaviour
{
public GameObject hudGO;
public GameObject joystickGO;
public GameObject yolkAGO;
public GameObject yolkBGO;
public TMPro.TextMeshProUGUI versionText;
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
public float joystickJiggleSpeed;
public float flashFrequencyTime;
private TimerHelper _flashTimer;
private MeshRenderer _meshRenderer;
private Color _defaultEmissionColor;
private GameObject _lastControlSelected;
// Start is called before the first frame update
void Start()
{
// If the BGM manager is present, queue up and play the given track index
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(0);
}
_flashTimer = new TimerHelper(flashFrequencyTime);
_meshRenderer = hudGO.GetComponent<MeshRenderer>();
_defaultEmissionColor = _meshRenderer.materials[0].GetColor("_EmissionColor");
versionText.text = versionText.text.Replace("{versionNo}", GameManager.Instance.CurrentVersion);
}
public void SetupVolumeOptions()
{
// Gets the volume settings from the player profile and sets it in the game
float currentMasterVol = PlayerPrefs.GetFloat("currentMasterVol");
GameObject masterVolSliderGo = GameObject.Find("MainVolSlider");
float currentMusicVol = PlayerPrefs.GetFloat("currentMusicVol");
GameObject musicVolSliderGo = GameObject.Find("MusicVolSlider");
float currentSFXVol = PlayerPrefs.GetFloat("currentSFXVol");
GameObject SFXVolSliderGo = GameObject.Find("SfxVolSlider");
masterVolSliderGo.GetComponent<Slider>().value = currentMasterVol;
musicVolSliderGo.GetComponent<Slider>().value = currentMusicVol;
SFXVolSliderGo.GetComponent<Slider>().value = currentSFXVol;
}
public void PlayMenuClick()
{
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
}
public void StartGame()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
SceneManager.LoadScene("Rules");
}
public void Quit()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
public void SetMasterVolume(float value)
{
// Converts the master volume into decibels and stores it in the player profile
GameManager.Instance.currentAudioMixer.SetFloat("masterVol", SharedMethods.ConvertToDecibels(value));
PlayerPrefs.SetFloat("currentMasterVol", value);
}
public void SetMusicVolume(float value)
{
// Converts the music volume into decibels and stores it in the player profile
GameManager.Instance.currentAudioMixer.SetFloat("musicVol", SharedMethods.ConvertToDecibels(value));
PlayerPrefs.SetFloat("currentMusicVol", value);
}
public void SetSFXVolume(float value)
{
// Converts the sfx volume into decibels and stores it in the player profile
GameManager.Instance.currentAudioMixer.SetFloat("sfxVol", SharedMethods.ConvertToDecibels(value));
PlayerPrefs.SetFloat("currentSFXVol", value);
}
// Update is called once per frame
void Update()
{
if (_flashTimer.HasTicked(Time.deltaTime))
{
float randomNo = Random.Range(0.0f, 1.0f);
_meshRenderer.materials[0].SetColor("_EmissionColor", Color.Lerp(Color.black, _defaultEmissionColor, randomNo));
}
float horzLRot = -Input.GetAxis("Horizontal") * joystickJiggleSpeed;
float vertLRot = -45.0f + -Input.GetAxis("Vertical") * joystickJiggleSpeed;
joystickGO.transform.eulerAngles = new Vector3(vertLRot, 0.0f, horzLRot);
if (horzLRot != 0)
{
if (EventSystem.current.currentSelectedGameObject == null)
{
EventSystem.current.SetSelectedGameObject(_lastControlSelected);
}
else
{
_lastControlSelected = EventSystem.current.currentSelectedGameObject;
}
}
float horzRRot = -25 + -Input.GetAxis("Mouse X") * joystickJiggleSpeed;
float vertRRot = -25 + -Input.GetAxis("Mouse Y") * joystickJiggleSpeed;
yolkAGO.transform.eulerAngles = new Vector3(vertRRot, 0.0f, 0.0f);
yolkBGO.transform.eulerAngles = new Vector3(horzRRot, 0.0f, 0.0f);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb67e4b8899ac3441995a02948824421
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,64 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
/// <summary>
/// Class to deal with the other collisions for the core
/// </summary>
public class MultiCollider : ColliderManager
{
public AudioClip corePickupSFX;
public GameObject radiusToken;
public GameObject PlayerOne;
public SphereCollider Cores;
private GameObject areaAround;
public int radiusTick;
// Bool checks if the core has been collected, this is because the ships are made of multiple collision boxes and would trigger more than once.
private bool _tokenCollected = false;
public override void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
GameObject collisionGO;
if (wasChild)
{
collisionGO = collision.transform.parent.gameObject;
}
else
{
collisionGO = collision.gameObject;
}
// Check the tag of the collided object, Direction doesnt matter i assume
switch (collisionGO.tag)
{
case "Player":
PickupToken();
break;
}
}
/// <summary>
/// Process the core pick up and destroy the core object.
/// </summary>
public void PickupToken()
{
// If the core has been collected ignore it.
if (!_tokenCollected)
{
Debug.Log("Pick up radius");
_tokenCollected = true;
AudioSource.PlayClipAtPoint(corePickupSFX, transform.position);
Destroy(radiusToken);
while (radiusTick > 0)
{
Cores.radius = 10;
radiusTick -= 1;
}
Destroy(areaAround);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 742ed625e6d4d46439f31a3dd0b6f94c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParticalCleanUp : MonoBehaviour
{
// Start is called before the first frame update
private float tik;
private float end = 2;
void Start()
{
tik = 0;
}
// Update is called once per frame
void Update()
{
if(tik >= end)
{
Destroy(gameObject);
}
else
{
tik += Time.deltaTime;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a6542ac5327d9d49b523dee5bff0ba0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RestartLevel : MonoBehaviour
{
void Update()
{
if (gameObject.name==("Player")) // need to get this to work when the player dies
{
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene.name);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39d57a8aa33863c4dbac39c865492676
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class RuleMenu : MonoBehaviour
{
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
private void Start()
{
// If the BGM manager is present, queue up and play the given track index
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(0);
}
}
public void StartGame()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
SceneManager.LoadScene("Game");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5678218a3034524ca1d3eb11b13ae1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,148 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.Playables;
public class RulesMenuEngine : MonoBehaviour
{
public GameObject playerCameraGO;
public GameObject playerTrailsGO;
public ParticleSystem starParticles;
public PlayableDirector howToTimeline;
private Vector3 _startPosition;
public GameObject startGameCutscene;
public GameObject startButton;
public GameObject replayButton;
public GameObject skipButton;
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
private bool _cutsceneEnded;
private GameObject _lastControlSelected;
// Start is called before the first frame update
void Start()
{
// If the BGM manager is present, queue up and play the given track index
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(0);
}
_startPosition = playerCameraGO.transform.position;
_cutsceneEnded = false;
}
public void StartGame()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
startGameCutscene.GetComponent<PlayableDirector>().time = 0;
startGameCutscene.SetActive(true);
}
public void ChangeScene()
{
SceneManager.LoadScene("Game");
}
public void PlayMenuClick()
{
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
}
public void SlowStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.simulationSpeed = 0.1f;
}
public void NormalStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.simulationSpeed = 1.0f;
CheckIfEndOfTimeline();
}
public void BoostStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.simulationSpeed = 10.0f;
}
public void EscapeStarRate()
{
ParticleSystem.MainModule starsMainPS = starParticles.main;
starsMainPS.maxParticles = 10000;
starsMainPS.simulationSpeed = 100.0f;
starsMainPS.startColor = Color.red;
}
public void DoCutSceneSkip()
{
double fullTime = System.Math.Floor(howToTimeline.time);
int previousSecondMark = (int)fullTime % 10;
howToTimeline.time = (fullTime - previousSecondMark) + 10;
CheckIfEndOfTimeline();
}
public void CheckIfEndOfTimeline()
{
if ((howToTimeline.time + 11) >= howToTimeline.duration)
{
skipButton.SetActive(false);
EventSystem.current.SetSelectedGameObject(startButton);
}
}
public void RestartHowToTimeline()
{
howToTimeline.gameObject.SetActive(true);
skipButton.SetActive(true);
NormalStarRate();
_cutsceneEnded = false;
playerCameraGO.transform.position = _startPosition;
foreach (TrailRenderer currentTrail in playerTrailsGO.GetComponentsInChildren<TrailRenderer>())
{
currentTrail.Clear();
}
howToTimeline.Play();
}
public void EndHowToTimeline()
{
howToTimeline.gameObject.SetActive(false);
skipButton.SetActive(false);
EventSystem.current.SetSelectedGameObject(startButton);
replayButton.SetActive(true);
playerCameraGO.transform.position = _startPosition;
_cutsceneEnded = true;
NormalStarRate();
}
// Update is called once per frame
void Update()
{
if (_cutsceneEnded)
{
//playerTrailsGO.SetActive(true);
playerCameraGO.transform.position = playerCameraGO.transform.forward * 0.05f * Time.deltaTime;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 827a1b0c975d30a42b0da8b646b159a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Spedometer : MonoBehaviour
{
public Slider speed;
// Start is called before the first frame update
public void SpeedSlider(float newSpeed)
{
speed.value = newSpeed;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00d71e82bde684141adba79767a86c48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
public enum TimerDirection
{
TimerIncrement,
TimerDecrement
}
public class TimerHelper
{
private float _timerInterval;
private float _timerMax;
private float _timerTick;
private int _timesRun;
private bool _timerRepeats;
private TimerDirection _timerDirection;
public TimerHelper(float timeMax, bool repeating = true, TimerDirection direction = TimerDirection.TimerIncrement)
{
_timerMax = timeMax;
_timerRepeats = repeating;
_timerDirection = direction;
if (_timerDirection == TimerDirection.TimerDecrement)
{
_timerInterval = 0.0f;
_timerTick = -_timerMax;
}
else
{
_timerInterval = _timerMax;
_timerTick = 0.0f;
}
}
public float CurrentTick
{
get
{
return Math.Abs(_timerTick);
}
}
public int TimesRun
{
get
{
return _timesRun;
}
}
public bool HasTicked(float currentTimestamp)
{
if (_timerTick >= _timerInterval)
{
_timesRun++;
if (_timerRepeats)
{
RestartTimer();
}
return true;
}
else
{
_timerTick += currentTimestamp;
return false;
}
}
public void RestartTimer()
{
if (_timerDirection == TimerDirection.TimerDecrement)
{
_timerTick = -_timerMax;
}
else
{
_timerTick = 0.0f;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2420aeff9a124cd44a9b49c7e59a399a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
/// <summary>
/// Class to deal with the other collisions for the core
/// </summary>
public class laserCollider : ColliderManager
{
public AudioClip corePickupSFX;
public GameObject laserToken;
public int laserTick;
public GameObject LaserStick1;
public GameObject LaserStick2;
// Bool checks if the core has been collected, this is because the ships are made of multiple collision boxes and would trigger more than once.
private bool _tokenCollected = false;
public override void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
GameObject collisionGO;
if (wasChild)
{
collisionGO = collision.transform.parent.gameObject;
}
else
{
collisionGO = collision.gameObject;
}
// Check the tag of the collided object, Direction doesnt matter i assume
switch (collisionGO.tag)
{
case "Player":
PickupToken();
break;
}
}
/// <summary>
/// Process the core pick up and destroy the core object.
/// </summary>
public void PickupToken()
{
// If the core has been collected ignore it.
if (!_tokenCollected)
{
Debug.Log("Pick up laser");
_tokenCollected = true;
AudioSource.PlayClipAtPoint(corePickupSFX, transform.position);
Destroy(laserToken);
while (laserTick != 0)
{
LaserStick1.transform.localScale = new Vector3(0.07000001f, 1.2f, 0.07000001f);
LaserStick1.transform.position = new Vector3(LaserStick1.transform.position.x - 5.27541f,
LaserStick1.transform.position.y - 1.240699f, LaserStick1.transform.position.z + 3.87f);
LaserStick2.transform.localScale = new Vector3(0.07000001f, 1.2f, 0.07000001f);
LaserStick2.transform.position = new Vector3(LaserStick2.transform.position.x - 0.2f,
LaserStick2.transform.position.y - 1.3f, LaserStick2.transform.position.z + 3.62f);
laserTick -= 1;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7e2c85678107d943bcdd2c894626dba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 58c4711082fe17740af03add9209232c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class to handle the Asteroids Blackhole forces
/// </summary>
public class AsteroidBlackHoleForce : BlackHoleForce
{
public float gravityForceOffsetPercent;
private BlackHoleManager _currentBlackHoleManager;
protected override void DoAwakeTasks()
{
// Get the current blackhole
_currentBlackHoleManager = GameObject.Find("BlackHole").GetComponent<BlackHoleManager>();
base.DoAwakeTasks();
}
public override void ApplyBlackHoleForce(float appliedForce)
{
if (!blackHolePullImmunue)
{
_objectRigidBody.AddForce((-_objectRigidBody.transform.up * appliedForce) * gravityForceOffsetPercent);
}
}
/// <summary>
/// Method for dealing with what happens when this object hits the blackhole
/// </summary>
public override void HitBlackHole()
{
// Call a special function for growing the black hole, this is because it takes multiple asteroids to grow it
_currentBlackHoleManager.AsteroidGrow();
ObjectSpawning attachedShared = gameObject.GetComponent<AsteroidObjectShared>().Spawner;
if (attachedShared)
{
attachedShared.ReduceSpawnedCount();
}
Destroy(gameObject);
base.HitBlackHole();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67e02f55d78e13f4e9444230203dc464
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for keeping the asteroids inside of the boundary
/// </summary>
public class AsteroidBoundaryCheck : BoundaryCheck
{
private Rigidbody _coreObjectRigidBody;
// Start is called before the first frame update
void Awake()
{
_coreObjectRigidBody = gameObject.GetComponent<Rigidbody>();
}
/// <summary>
/// Method for bouncing this object back when hitting the boundary
/// </summary>
/// <param name="contactPoint">The point of the boundary hit.</param>
/// <param name="pushbackForce">How much force to apply to this object</param>
public override void DoBoundaryPushback(Vector3 contactPoint, float pushbackForce)
{
_coreObjectRigidBody.velocity = Vector3.zero;
_coreObjectRigidBody.AddForceAtPosition(contactPoint * pushbackForce, contactPoint, ForceMode.Impulse);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3a1028118190f524dba5afaef145ee9f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,96 @@
using UnityEngine;
public class AsteroidColliderManager : ColliderManager
{
public AudioClip asteroidDestroyedSFX;
public float bounceForce;
private AudioSource _audioSource;
// Is the asteroid destroyed when it collides.
public bool destroyOnHit;
private bool _exploding = false;
public override void DoAwakeTasks()
{
_audioSource = gameObject.GetComponent<AudioSource>();
base.DoAwakeTasks();
}
/// <summary>
/// Process the asteroids collision.
/// </summary>
/// <param name="direction">Direction the collision happened, typically checking if hit from above or below.</param>
/// <param name="collision">Collision object holding the details on the collided object.</param>
/// <param name="wasChild">Was the hit collider a child of this game object.</param>
public override void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
GameObject collisionGO;
if (wasChild)
{
// if the collision was a child, get the parent game object.
collisionGO = collision.transform.parent.gameObject;
}
else
{
collisionGO = collision.gameObject;
}
// Check the tag of the collided object, Collision direction doesnt matter i assume.
switch (collisionGO.tag)
{
case "Mine":
MineColliderManager mineColliderManager = collisionGO.GetComponent<MineColliderManager>();
if (mineColliderManager)
{
mineColliderManager.HitMine();
}
break;
case "Enemy":
case "Player":
BounceAway(collisionGO, -collision.contacts[0].normal);
ExplodeAsteroid();
break;
}
}
/// <summary>
/// Repel the collided object and the asteroid in opposing directions.
/// </summary>
/// <param name="bouncedObject">Game object of the collided object</param>
/// <param name="collisionPos">Position the collision happened</param>
public void BounceAway(GameObject bouncedObject, Vector3 collisionPos)
{
bouncedObject.GetComponent<Rigidbody>().AddForce(collisionPos * bounceForce, ForceMode.Impulse);
gameObject.GetComponent<Rigidbody>().AddForce(-collisionPos * bounceForce, ForceMode.Impulse);
}
/// <summary>
/// Destroy the asteroid game object, it should deal with the destruction, animations and sounds related to an asteroid being removed from play.
/// </summary>
public void ExplodeAsteroid()
{
if (_audioSource != null)
{
_audioSource.PlayOneShot(asteroidDestroyedSFX);
}
if (destroyOnHit)
{
if (!_exploding)
{
if (transform.childCount > 0)
{
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
}
Destroy(gameObject, 2.0f);
_exploding = true;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e39771c0beae2924c8ab7611c607a980
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,158 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the androids movement
/// </summary>
public class AsteroidHoverMovement : 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;
public float spinMin = 0.05f;
public float spinMax = 0.1f;
public Vector3 spinDirection = Vector3.forward + Vector3.up;
private float _currentSpin;
// Start is called before the first frame update
void Start()
{
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_rngHorz = 0.0f;
_rngVert = 0.0f;
_currentSpin = Random.Range(spinMin, spinMax);
BaseOnStart();
// Custom start stuff can go here
}
/// <summary>
/// Calculates some RNG movement for the attached asteroid.
/// </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 = 0;
objectModel.transform.Rotate(spinDirection, _currentSpin);
}
/// <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)
{
float horzInput = _rngHorz;
float vertInput = _rngVert;
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
_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 (objectIsActive)
{
//ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoRNG(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
//ProcessPostMovement();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e59fd71c0855ea4789414be452876ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AsteroidObjectShared : ObjectShared
{
// Tracking the spawner this gameObject was created by so we can reduce the counter for it later
private ObjectSpawning _spawner;
public ObjectSpawning Spawner
{
get
{
return _spawner;
}
set
{
_spawner = value;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d21f3d45eb01684aa8951507f7700cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the spawning of Asteroids
/// </summary>
public class AsteroidSpawning : ObjectSpawning
{
public GameObject asteroidPrefab;
public float minWidthScaleRange;
public float minHeightScaleRange;
public float maxWidthScaleRange;
public float maxHeightScaleRange;
public int numberToSpawn;
private void Awake()
{
_spawnedObject = asteroidPrefab;
_numberToSpawn = numberToSpawn;
}
/// <summary>
/// Reduce the spawned counter for this spawner
/// </summary>
public override void ReduceSpawnedCount()
{
objectCount = Mathf.Clamp(objectCount - 1, 0, _numberToSpawn);
base.ReduceSpawnedCount();
}
/// <summary>
/// Spawn the gameObject assigned to this spawner
/// </summary>
protected override void DoASpawn()
{
float xPos = Random.Range(-xSpawnRange, xSpawnRange);
float yPos = Random.Range(-ySpawnRange, ySpawnRange);
float zPos = Random.Range(-zSpawnRange, zSpawnRange);
float widthScale = Random.Range(minWidthScaleRange, maxWidthScaleRange);
float heightScale = Random.Range(minHeightScaleRange, maxHeightScaleRange);
// If debug is checked then try to spawn the object above the player, this is to test collisions
if (debugSpawn)
{
GameObject currentPlayer = GameObject.Find("Player");
xPos = currentPlayer.transform.position.x;
zPos = currentPlayer.transform.position.z;
yPos = currentPlayer.transform.position.y + 10;
}
GameObject newSpawn = Instantiate(_spawnedObject);
// Set the start height of the gameObject from the blackhole
HoverMovement newSpawnMovement = newSpawn.GetComponent<HoverMovement>();
if (newSpawnMovement)
{
newSpawnMovement.startPositionVector = new Vector3(xPos, yPos, zPos);
newSpawnMovement.ForceHeightAdjust(Random.Range(minSpawnHeight, maxSpawnHeight));
}
newSpawn.transform.localScale = new Vector3(widthScale, heightScale, widthScale);
// Set the spawned to this on the gameObject
AsteroidObjectShared newSpawnShared = newSpawn.GetComponent<AsteroidObjectShared>();
if (newSpawnShared)
{
newSpawnShared.Spawner = this;
}
newSpawn.SetActive(true);
objectCount++;
base.DoASpawn();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f1fb5f353413b7e4a8a2632540e717a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,99 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
/// <summary>
/// Class for dealing with the background music and queuing looping tracks so they hopefully play smoothly
/// </summary>
[RequireComponent(typeof(AudioSource))]
public class BackgroundMusicManager : MonoBehaviour
{
// List of Audio clips for the background music
public List<AudioClip> musicLibrary = new List<AudioClip>();
private AudioSource _audioSource;
private AudioClip _currentAudioClip;
private bool _pauseAudio = true;
// Start is called before the first frame update
void Awake()
{
// Get the current audio source on this GO
_audioSource = gameObject.GetComponent<AudioSource>();
}
/// <summary>
/// Line up the next audio clip to play from the music library list, this should play after the current music track ends
/// </summary>
/// <param name="initialSong">Index of the Audio track in the music library</param>
/// <param name="playOnStart">Play the audio on load or not</param>
public void StartAudioQueue(int initialSong, bool playOnStart = true)
{
QueueNextAudio(initialSong);
_pauseAudio = !playOnStart;
PlayCurrentAudio();
}
public void StartAudioQueueAndPlay(int initialSong)
{
StartAudioQueue(initialSong, true);
}
// Set/Change the next audio to play
public void QueueNextAudio(int songIndex)
{
if (musicLibrary[songIndex] != null)
{
_currentAudioClip = musicLibrary[songIndex];
}
}
// Stop the audio but keep scanning for changes
public void StopAudioNow()
{
_audioSource.Stop();
_pauseAudio = true;
CancelInvoke("PlayCurrentAudio");
Invoke("PlayCurrentAudio", 0.1f);
}
// Stop the audio and instantly play the next track
public void StopCurrentAudioAndPlay(int songIndex)
{
_audioSource.Stop();
CancelInvoke("PlayCurrentAudio");
StartAudioQueueAndPlay(songIndex);
}
// Stop the audio and the cancel the invoke
public void StopCurrentAudioForGood()
{
_audioSource.Stop();
CancelInvoke("PlayCurrentAudio");
}
public void PlayCurrentAudio()
{
if (!_pauseAudio)
{
_audioSource.clip = _currentAudioClip;
_audioSource.Play();
Invoke("PlayCurrentAudio", _audioSource.clip.length);
}
else
{
_audioSource.Stop();
Invoke("PlayCurrentAudio", 0.1f);
}
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b83b0b77103fa64db92527e33226cd3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the spawning of basic enemies
/// </summary>
public class BasicEnemySpawning : ObjectSpawning
{
public GameObject enemyPrefab;
public EnemyType spawnersEnemyType;
private void Awake()
{
_spawnedObject = enemyPrefab;
}
/// <summary>
/// Reduce the spawned counter for this spawner
/// </summary>
public override void ReduceSpawnedCount()
{
objectCount = Mathf.Clamp(objectCount - 1, 0, _numberToSpawn);
base.ReduceSpawnedCount();
}
/// <summary>
/// Spawn the gameObject assigned to this spawner
/// </summary>
protected override void DoASpawn()
{
int spawnLevel = GameManager.Instance.level;
float xPos = Random.Range(-xSpawnRange, xSpawnRange);
float yPos = Random.Range(-ySpawnRange, ySpawnRange);
float zPos = Random.Range(-zSpawnRange, zSpawnRange);
// If debug is checked then try to spawn the object above the player, this is to test collisions
if (debugSpawn)
{
GameObject currentPlayer = GameObject.Find("Player");
xPos = currentPlayer.transform.position.x;
zPos = currentPlayer.transform.position.z;
yPos = currentPlayer.transform.position.y + 10;
}
GameObject newSpawn = Instantiate(_spawnedObject);
// Set the start height of the gameObject from the blackhole
HoverMovement newSpawnMovement = newSpawn.GetComponent<HoverMovement>();
if (newSpawnMovement)
{
newSpawnMovement.startPositionVector = new Vector3(xPos, yPos, zPos);
newSpawnMovement.ForceHeightAdjust(Random.Range(minSpawnHeight, maxSpawnHeight));
}
// Set the spawned to this on the gameObject
EnemyObjectShared newSpawnShared = newSpawn.GetComponent<EnemyObjectShared>();
if (newSpawnShared)
{
newSpawnShared.Spawner = this;
}
newSpawn.SetActive(true);
objectCount++;
base.DoASpawn();
}
protected override void GetCurrentCount()
{
_numberToSpawn = GameManager.Instance.GetCurrentLevelEnemyTypeCount(spawnersEnemyType);
base.GetCurrentCount();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 19f2ca9f4b0e97f45976ef9ef78a46d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,327 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with a basic follow enemy AI
/// </summary>
public class BasicFollowEnemyHoverMovement : HoverMovement
{
// Game object to track the player GO
private GameObject _player;
private GameObject _blackHole;
// 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;
public float jumpForce;
public float jumpMaxTime;
private float _residualThrust;
private float _residualThrustCurrentTime;
private float _currentJumpTime;
private bool _isJumping;
// Variables for RNG movement
private float _aiVert;
private float _aiHorz;
private bool _aiJump;
public float chargeRadius;
public float chargePower;
public float chargeCooldown;
private bool _charged;
private float _currentChargeCooldownTick;
private RaycastHit _rayHitPosition;
public override void DoAwakeTasks()
{
base.DoAwakeTasks();
}
// Start is called before the first frame update
void Start()
{
// We have to find the player since setting it in the editor doesnt work correctly
_player = GameObject.Find("Player");
_blackHole = GameObject.Find("BlackHole");
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
_aiHorz = 0.0f;
_aiVert = 0.0f;
_charged = false;
_currentChargeCooldownTick = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
void DoAIPhysics(float currentTimeStep)
{
if (_rayHitPosition.rigidbody != null)
{
if (_rayHitPosition.rigidbody.CompareTag("Player") && _rayHitPosition.distance <= 5.0f)
{
if (!_charged)
{
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
if (playerHeight < GetCurrentHeight())
{
_objectRigidbody.AddRelativeForce((Vector3.forward + Vector3.down) * chargePower);
_charged = true;
}
}
}
}
}
/// <summary>
/// Calculates some RNG movement for the attached Enemy.
/// </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 DoAI(float currentTimeStep)
{
// Get the Up vector of each gameObject so we can compare its X values rather than the Y
Vector3 playerDirection = _player.transform.position - transform.position;
Vector3 playerLocation = Vector3.ProjectOnPlane(_player.transform.position, Vector3.up);
Vector3 myLocation = Vector3.ProjectOnPlane(transform.position, Vector3.forward);
Vector3 direction = playerLocation - myLocation;
float angleDiff = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
float facingPlayer = Vector3.Dot(playerDirection.normalized, transform.forward);
// Added a check to see if the difference is big enough to warrant a turn otherwise they just get stuck turning forever
float playerHeight = _player.GetComponent<PlayerHoverMovement>().GetCurrentHeight();
Physics.SphereCast(transform.position, chargeRadius, transform.forward, out _rayHitPosition);
_aiVert = 1;
if (facingPlayer > 0.8f)
{
_aiHorz = 0.0f;
if (_rayHitPosition.rigidbody != null)
{
if (_rayHitPosition.rigidbody.CompareTag("Player") && _rayHitPosition.distance <= 15.0f)
{
if (!_charged)
{
if (playerHeight > GetCurrentHeight())
{
_objectRigidbody.velocity = Vector3.zero;
_aiJump = false;
}
else
{
_aiVert = 0.5f;
_aiJump = true;
}
}
}
else
{
if (playerHeight > GetCurrentHeight())
{
_aiJump = true;
}
}
}
}
else
{
_aiHorz = angleDiff;
if (((playerHeight - 0.5f) >= GetCurrentHeight()))
{
if (_rayHitPosition.rigidbody != null)
{
if (_rayHitPosition.rigidbody.CompareTag("Player") && (GetCurrentHeight() < playerHeight))
{
Debug.LogError("PLAYER ABOVE DONT JUMP (plz)");
_objectRigidbody.velocity = Vector3.zero;
_aiJump = false;
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = true;
}
}
else
{
_aiJump = false;
}
}
}
/// <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.
/// Anything in this method can be removed, as long as the _turnDirection and _thrustDirection are set then the parent script with handle the orbit and positioning.
/// </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 movement has been frozen
if (!freezeMovement)
{
// Get the Horz and Vert axis from the RNG (or whatever vars you want)
float horzInput = _aiHorz;
float vertInput = _aiVert;
// Check horz direction value, pos = Right, neg = Left
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Check if the vert is pushed forwards or back, pos = forward, neg = back
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
// If the Enemy is holding backwards
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the residual thrust so we cant fall below 0 or greater than the max value set
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Check if the jump button
if (_aiJump && !_isJumping)
{
_isJumping = true;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
/// <summary>
/// Method for dealing with the jump physics, this should be in the fixed update since it uses rigidbody physics
/// </summary>
void ProcessJump()
{
// If the enemy is jumping add the jump force
if (_isJumping)
{
_objectRigidbody.AddRelativeForce(Vector3.up * jumpForce * Time.fixedDeltaTime, ForceMode.Impulse);
if (_currentJumpTime >= jumpMaxTime)
{
_currentJumpTime = 0.0f;
_isJumping = false;
_aiJump = false;
}
else
{
_currentJumpTime += Time.fixedDeltaTime;
}
}
}
void ProcessCooldowns(float currentTimeStep)
{
if (_charged)
{
if (_currentChargeCooldownTick >= chargeCooldown)
{
_charged = false;
_currentChargeCooldownTick = 0.0f;
}
else
{
_currentChargeCooldownTick += currentTimeStep;
}
}
}
private void FixedUpdate()
{
if (objectIsActive)
{
DoAIPhysics(Time.fixedDeltaTime);
ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoAI(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
ProcessCooldowns(Time.deltaTime);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 962bf34ea2b31b94682a4eccd5952a68
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Abstract class to handle the blackhole forces of the game
/// </summary>
public class BlackHoleForce : MonoBehaviour
{
// Bool to set the GO to ignore the blackholes pull
public bool blackHolePullImmunue;
protected Rigidbody _objectRigidBody;
protected Transform _currentTransform;
protected HoverMovement _movement;
private void Awake()
{
// Get the rigidbody and movement script attached to the GO for use
_objectRigidBody = gameObject.GetComponent<Rigidbody>();
_movement = gameObject.GetComponent<HoverMovement>();
DoAwakeTasks();
}
/// <summary>
/// Virtual method to allow a child script to do tasks during the Awake call
/// </summary>
protected virtual void DoAwakeTasks()
{
}
// Start is called before the first frame update
void Start()
{
// Stop using the rigidbody default rotation and gravity settings
_objectRigidBody.constraints = RigidbodyConstraints.FreezeRotation;
_objectRigidBody.useGravity = false;
_currentTransform = transform;
// Add the BHF to the black holes list of GO's with blackhole physics
BlackHoleManager.blackHoleForceObjects.Add(this);
DoStartTasks();
}
/// <summary>
/// Method for letting a child script do start tasks during the start call
/// </summary>
protected virtual void DoStartTasks()
{
}
private void OnDestroy()
{
// Remove us from the blackhole force list on the blackhole
BlackHoleManager.blackHoleForceObjects.Remove(this);
}
/// <summary>
/// Virtual method to Apply the actual blackhole force to the attached gameobject, this allows for each GO type to react differently
/// </summary>
/// <param name="appliedForce">Amount of force applied to the object from the blackhole</param>
public virtual void ApplyBlackHoleForce(float appliedForce)
{
}
/// <summary>
/// Virtual method to call when an object has hit the blackhole
/// </summary>
public virtual void HitBlackHole()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec836b072ad135a43ad7f77ec10d724a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,150 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the blackhole
/// </summary>
public class BlackHoleManager : MonoBehaviour
{
// List of blackhole force scripts currently in play
public static List<BlackHoleForce> blackHoleForceObjects = new List<BlackHoleForce>();
// the GO of the blackhole
public GameObject blackHoleModel;
// Bools to lock the size and to time grow it
public bool sizeLocked;
public bool timedGrow;
// Vars for the blackhole size
public float initialBlackHoleRadius;
public float blackHoleSizeIncrement;
public float blackHoleSizeTime;
public float gravityPullFoce;
public float currentBlackHoleRadius;
private float _currentBlackHoleTimePassed;
// Vars for dealing with the blackhole SFX
private AudioSource _currentAudioSource;
public AudioClip blackHoleAmbiantSFX;
public int maxAudioSize = 70;
public bool playBlackHoleAmbiantNoise;
/// <summary>
/// Method to get the current size of the blackhole
/// </summary>
/// <returns>Size of the blackhole</returns>
public float GetCurrentBlackHoleSize()
{
return currentBlackHoleRadius;
}
// Start is called before the first frame update
void Awake()
{
// set the initial blackhole vars and size
_currentBlackHoleTimePassed = 0.0f;
blackHoleModel.transform.localScale = Vector3.one * initialBlackHoleRadius;
currentBlackHoleRadius = initialBlackHoleRadius;
// Set the audio source and SFX
_currentAudioSource = gameObject.GetComponent<AudioSource>();
if (_currentAudioSource)
{
if (playBlackHoleAmbiantNoise)
{
_currentAudioSource.clip = blackHoleAmbiantSFX;
_currentAudioSource.loop = true;
_currentAudioSource.Play();
}
else
{
_currentAudioSource.clip = null;
_currentAudioSource.Stop();
}
}
}
private void Update()
{
// fort nite
BlackHoleAudio();
if (timedGrow)
{
TimedGrow();
}
}
/// <summary>
/// Method for dealing with increasing the sound catchment area when the blackhole grows
/// </summary>
public void BlackHoleAudio()
{
GetComponent<AudioSource>().maxDistance = currentBlackHoleRadius + maxAudioSize;
}
/// <summary>
/// Method for dealing with a timed blackhole grow, if the size is not locked and the timed option is checked, a given amount of mass is given to the blackhole every X seconds
/// </summary>
private void TimedGrow()
{
if (!sizeLocked)
{
if (_currentBlackHoleTimePassed >= blackHoleSizeTime)
{
blackHoleModel.transform.localScale += Vector3.one * blackHoleSizeIncrement;
currentBlackHoleRadius += blackHoleSizeIncrement;
_currentBlackHoleTimePassed = 0.0f;
}
else
{
_currentBlackHoleTimePassed += Time.deltaTime;
}
}
}
private void OnCollisionEnter(Collision collision)
{
// If we collide with an object trigger is blackhole hit method
BlackHoleForce bhfHit = collision.gameObject.GetComponent<BlackHoleForce>();
if (bhfHit)
{
bhfHit.HitBlackHole();
}
}
private void FixedUpdate()
{
// Apply force to every blackhole force object in the list
foreach (BlackHoleForce bhfObject in blackHoleForceObjects)
{
bhfObject.ApplyBlackHoleForce(gravityPullFoce * Time.fixedDeltaTime);
}
}
/// <summary>
/// Method for dealing with asteroids growing the blackhole since they increase it every X hits
/// </summary>
public void AsteroidGrow()
{
return;
}
/// <summary>
/// Method for growing the blackhole if the size has not been locked
/// </summary>
public void Grow()
{
if (!sizeLocked)
{
blackHoleModel.transform.localScale += Vector3.one * blackHoleSizeIncrement;
currentBlackHoleRadius += blackHoleSizeIncrement;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 468c1aa5359c5114c90ef41818483136
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoundaryCheck : MonoBehaviour
{
public virtual void DoBoundaryPushback(Vector3 contactPoint, float pushbackForce)
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a75ec0113caff734785dfb3e19704e8f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoundaryLightManager : MonoBehaviour
{
public Light currentLight;
public float startIntensity;
public float lightLifeTime;
private float _currentTick;
private void Awake()
{
currentLight.intensity = startIntensity;
_currentTick = 0.0f;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
currentLight.intensity = Mathf.Lerp(startIntensity, 0, _currentTick / lightLifeTime);
if (_currentTick >= lightLifeTime)
{
Destroy(gameObject);
}
else
{
_currentTick = Mathf.Clamp(_currentTick + Time.deltaTime, 0, lightLifeTime);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ef1c36c6131a964f8f4a44c08708eb1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with the outer boundary
/// </summary>
public class BoundaryManager : MonoBehaviour
{
// The amout of force that the object is pushed back
public float pushbackForce;
public GameObject hitLight;
private MeshCollider _meshCollier;
// Start is called before the first frame update
void Awake()
{
_meshCollier = gameObject.GetComponent<MeshCollider>();
}
void OnCollisionStay(Collision collision)
{
DoCollision(collision.gameObject, collision);
}
void OnCollisionEnter(Collision collision)
{
DoCollision(collision.gameObject, collision);
}
private void DoCollision(GameObject collidedObject, Collision collisionPoint)
{
BoundaryCheck collidedBoundaryCheck = collidedObject.GetComponent<BoundaryCheck>();
if (collidedBoundaryCheck)
{
GameObject newLight = Instantiate(hitLight);
newLight.transform.position = collisionPoint.GetContact(0).point;
newLight.SetActive(true);
collidedBoundaryCheck.DoBoundaryPushback(collisionPoint.GetContact(0).normal, pushbackForce);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee1bd184c8f73174a94428f563c3846f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraManager : MonoBehaviour
{
public GameObject followedGO;
private Vector3 _followOffset;
// Start is called before the first frame update
void Start()
{
_followOffset = transform.position - followedGO.transform.position;
}
// Update is called once per frame
void LateUpdate()
{
transform.position = followedGO.transform.position + _followOffset;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95ba65163489276488aedc20d397a709
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChildColliderHelper : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
GameObject parentGO = gameObject.transform.parent.gameObject;
if (parentGO)
{
parentGO.GetComponent<ColliderManager>().OnCollisionEnterChild(collision);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a0b46b4052f9e048bf87607c6b897e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,104 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Base class used for the collision interactions between anything that isnt the blackhole, which has its own special class.
/// </summary>
public class ColliderManager : MonoBehaviour
{
protected AudioSource _attachedAudioSource;
/// <summary>
/// An enum to pass which direction the collision happened.
/// </summary>
public enum CollisionDirection
{
None,
Top,
Bottom
}
private void Awake()
{
// Get the objects audio source, if one is present
_attachedAudioSource = gameObject.GetComponent<AudioSource>();
// Do any tasks the child has to process
DoAwakeTasks();
}
// Start is called before the first frame update
void Start()
{
}
/// <summary>
/// Method to deal with Awake tasks that a child script needs since you can only have 1 awake between the parent and child.
/// </summary>
public virtual void DoAwakeTasks()
{
}
/// <summary>
/// Method to trigger the attached objects death without a collision but should simulate a collision
/// </summary>
public virtual void TriggerDeath()
{
}
/// <summary>
/// Process the game objects collision.
/// </summary>
/// <param name="direction">Direction the collision happened, typically checking if hit from above or below.</param>
/// <param name="collision">Collision object holding the details on the collided object.</param>
/// <param name="wasChild">Was the hit collider a child of this game object.</param>
public virtual void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
}
/// <summary>
/// Custom method to deal with child collisions on the game object, this was a test really and most likely wont be used in the final.
/// </summary>
/// <param name="collision"></param>
public void OnCollisionEnterChild(Collision collision)
{
DoCollisionEnter(collision, true);
}
private void OnCollisionEnter(Collision collision)
{
DoCollisionEnter(collision);
}
/// <summary>
/// Helper method to process the collision since when testing we needed to different collision detections.
/// </summary>
/// <param name="collision">Collider that we hit.</param>
/// <param name="wasChild">Check if it was a child that was hit.</param>
private void DoCollisionEnter(Collision collision, bool wasChild = false)
{
// Get the collided objects collision manager, if they dont have one then we ignore it since we only want objects to interact when they have to.
ColliderManager hitCM = collision.gameObject.GetComponent<ColliderManager>();
if (hitCM != null)
{
// Get the vector where the collision happened, and check if it happened above or below.
//Vector3 collisionHitCheckPosition = collision.gameObject.transform.position - gameObject.transform.position;
float collisionHitDirection = Vector3.Dot(collision.GetContact(0).normal, collision.transform.up);
CollisionDirection direction = CollisionDirection.None;
if (collisionHitDirection < -0.1f)
{
direction = CollisionDirection.Top;
}
else if (collisionHitDirection > 0.1f)
{
direction = CollisionDirection.Bottom;
}
// Once we know process the collision.
ProcessCollision(direction, collision, wasChild);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 575cf425afdb6844c820989815095436
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for the interaction between a shits core and the blackhole
/// </summary>
public class CoreBlackHoleForce : BlackHoleForce
{
// Gravity force offset % is used so we can either slow down or increase the default pull from the black hole.
public float gravityForceOffsetPercent;
private BlackHoleManager _currentBlackHoleManager;
protected override void DoStartTasks()
{
// Get the current black hole.
_currentBlackHoleManager = GameObject.Find("BlackHole").GetComponent<BlackHoleManager>();
base.DoStartTasks();
}
public override void ApplyBlackHoleForce(float appliedForce)
{
// Check if we're blackhole immune before trying to pull the core in.
if (!blackHolePullImmunue)
{
_objectRigidBody.AddForce((-_objectRigidBody.transform.up * appliedForce) * gravityForceOffsetPercent);
}
}
public override void HitBlackHole()
{
// CORE HIT THE BLACK HOLE
// Grow the blackhole.
_currentBlackHoleManager.Grow();
// Destroy the Core.
Destroy(gameObject);
base.HitBlackHole();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b63cdec26d3082b4e847fe387e5a3683
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoreBoundryCheck : BoundaryCheck
{
private Rigidbody _coreObjectRigidBody;
// Start is called before the first frame update
void Awake()
{
_coreObjectRigidBody = gameObject.GetComponent<Rigidbody>();
}
public override void DoBoundaryPushback(Vector3 contactPoint, float pushbackForce)
{
_coreObjectRigidBody.velocity = Vector3.zero;
_coreObjectRigidBody.AddForceAtPosition(contactPoint * pushbackForce, contactPoint, ForceMode.Impulse);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fe41ef45cc1b8f44fabf4e6dc2dc97ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
/// <summary>
/// Class to deal with the other collisions for the core
/// </summary>
public class CoreColliderManager : ColliderManager
{
public AudioClip corePickupSFX;
private AudioSource _audioSource;
public override void DoAwakeTasks()
{
GameObject playerGO = GameObject.Find("Player");
_audioSource = playerGO.GetComponent<AudioSource>();
base.DoAwakeTasks();
}
// Bool checks if the core has been collected, this is because the ships are made of multiple collision boxes and would trigger more than once.
private bool _coreCollected = false;
public override void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
GameObject collisionGO;
if (wasChild)
{
collisionGO = collision.transform.parent.gameObject;
}
else
{
collisionGO = collision.gameObject;
}
// Check the tag of the collided object, Direction doesnt matter i assume
switch (collisionGO.tag)
{
case "Player":
PickupCore();
break;
}
}
/// <summary>
/// Process the core pick up and destroy the core object.
/// </summary>
public void PickupCore()
{
// If the core has been collected ignore it.
if (!_coreCollected)
{
_coreCollected = true;
if (_audioSource != null)
{
_audioSource.PlayOneShot(corePickupSFX);
}
GameManager.Instance.AddCore();
if (transform.childCount > 0)
{
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
}
Destroy(gameObject, 2.0f);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fac4bf9e59bf5a74ab32b0f6c844163d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,158 @@
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 = 0;
}
/// <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 (objectIsActive)
{
//ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoRNG(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b914d7863af4b6f459842442bc0d054e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoreObjectShared : ObjectShared
{
// Helper class incase we need to track a variable over multiple scripts
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e82512b3b1e7ea54fa2589232f218502
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBlackHoleForce : BlackHoleForce
{
public override void ApplyBlackHoleForce(float appliedForce)
{
if (!blackHolePullImmunue)
{
if (_movement)
{
if (!_movement.IsGravityImmune())
{
_objectRigidBody.AddForce(-_objectRigidBody.transform.up * appliedForce);
}
}
else
{
_objectRigidBody.AddForce(-_objectRigidBody.transform.up * appliedForce);
}
}
}
public override void HitBlackHole()
{
ObjectSpawning attachedShared = gameObject.GetComponent<EnemyObjectShared>().Spawner;
if (attachedShared)
{
attachedShared.ReduceSpawnedCount();
}
Destroy(gameObject);
base.HitBlackHole();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 37b64cee1602fc949bd30e84a93576dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBoundaryCheck : BoundaryCheck
{
private Rigidbody _objectRigidBody;
// Start is called before the first frame update
void Awake()
{
_objectRigidBody = gameObject.GetComponent<Rigidbody>();
}
public override void DoBoundaryPushback(Vector3 contactPoint, float pushbackForce)
{
_objectRigidBody.velocity = Vector3.zero;
_objectRigidBody.AddForceAtPosition(contactPoint * pushbackForce, contactPoint, ForceMode.Impulse);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6dbe118f7a92cfc41a02a3c322b7c780
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,215 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyColliderManager : ColliderManager
{
public GameObject shipCore;
public GameObject shipModel;
public float bounceForce;
public float coreSpawnDelayTime;
public ParticleSystem effectA;
public ParticleSystem effectB;
public AudioClip shipDeathSFX;
public AudioClip coreSpawnedSFX;
private bool _enemyDestroyed = false;
// The position the enemy died
private Vector3 _deathPos;
private float _deathHeight;
/// <summary>
/// Trigger the enemy death without a collision, this is mostly for the debug menu and testing but could be called in a case where you need it to die.
/// </summary>
public override void TriggerDeath()
{
DestoryEnemy();
base.TriggerDeath();
}
/// <summary>
/// Process the Enemy collision.
/// </summary>
/// <param name="direction">Direction the collision happened, typically checking if hit from above or below.</param>
/// <param name="collision">Collision object holding the details on the collided object.</param>
/// <param name="wasChild">Was the hit collider a child of this game object.</param>
public override void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
GameObject collisionGO;
if (wasChild)
{
collisionGO = collision.transform.parent.gameObject;
}
else
{
collisionGO = collision.gameObject;
}
switch (direction)
{
// We were hit from the top
case CollisionDirection.Top:
switch (collisionGO.tag)
{
case "Player":
// We were killed by the player above
DestoryEnemy();
break;
case "Enemy":
// Bounce other enemies back
BounceAway(collision.contacts[0].normal);
break;
case "Core":
case "Dead":
// Now handled by the layer NoCollide
// Ignore the physics between this and the core or dead players
//Physics.IgnoreCollision(collision.collider, gameObject.GetComponent<Collider>());
break;
}
break;
// We were hit from the bottom
case CollisionDirection.Bottom:
switch (collisionGO.tag)
{
case "Player":
// Kill the player because we were on top
PlayerColliderManager playerColliderManager = collisionGO.GetComponent<PlayerColliderManager>();
if (playerColliderManager)
{
playerColliderManager.PlayerHit();
}
break;
case "Enemy":
// Bounce the enemy away
EnemyColliderManager enemyColliderManager = collisionGO.GetComponent<EnemyColliderManager>();
if (enemyColliderManager)
{
enemyColliderManager.BounceAway(-collision.contacts[0].normal);
}
break;
case "Core":
case "Dead":
// Now handled by the layer NoCollide
//Physics.IgnoreCollision(collision.collider, gameObject.GetComponent<Collider>());
break;
}
break;
// Hits coming from any direction
default:
switch (collisionGO.tag)
{
case "Mine":
MineColliderManager mineColliderManager = collisionGO.GetComponent<MineColliderManager>();
if (mineColliderManager)
{
mineColliderManager.HitMine();
}
break;
case "Asteroid":
AsteroidColliderManager asteroidColliderManager = collisionGO.GetComponent<AsteroidColliderManager>();
if (asteroidColliderManager)
{
asteroidColliderManager.BounceAway(gameObject, -collision.contacts[0].normal);
}
break;
case "Enemy":
EnemyColliderManager enemyColliderManager = collisionGO.GetComponent<EnemyColliderManager>();
if (enemyColliderManager)
{
enemyColliderManager.BounceAway(-collision.contacts[0].normal);
}
break;
case "Core":
case "Dead":
// Handled by the layers now
//Physics.IgnoreCollision(collision.collider, gameObject.GetComponent<Collider>());
break;
}
break;
}
}
/// <summary>
/// Bounce away from the given position.
/// </summary>
/// <param name="collisionPos">Vector position the collision happened at.</param>
public void BounceAway(Vector3 collisionPos)
{
gameObject.GetComponent<Rigidbody>().AddForce(collisionPos * bounceForce, ForceMode.Impulse);
}
/// <summary>
/// Delayed core spawning method, this allows the ship to "die" and play its animation and then for the spawn to appear.
/// </summary>
/// <returns></returns>
public IEnumerator DelayedCoreSpawn()
{
bool timeWaited = false;
bool waitEnded = false;
while (!waitEnded)
{
if (timeWaited)
{
// Spawn a new core at the death location
GameObject newCore = Instantiate(shipCore);
CoreHoverMovement coreMovement = newCore.GetComponent<CoreHoverMovement>();
if (coreMovement)
{
coreMovement.startPositionVector = _deathPos;
coreMovement.startHeight = _deathHeight;
}
newCore.SetActive(true);
AudioSource newCoreAS = newCore.GetComponent<AudioSource>();
newCoreAS.PlayOneShot(coreSpawnedSFX);
StopCoroutine("DelayedCoreSpawn");
ObjectSpawning attachedShared = gameObject.GetComponent<EnemyObjectShared>().Spawner;
if (attachedShared)
{
// Reduce the spawner objects count
attachedShared.ReduceSpawnedCount();
}
Destroy(gameObject);
waitEnded = true;
}
else
{
timeWaited = true;
}
yield return new WaitForSeconds(coreSpawnDelayTime);
}
}
/// <summary>
/// Method for destroying the enemy game object, it starts a coroutine to allow for an animation to be played.
/// </summary>
public void DestoryEnemy()
{
if (!_enemyDestroyed)
{
// Store the position of death since the AI still moves after the models been deactivated.
_deathPos = transform.position;
_deathHeight = gameObject.GetComponent<HoverMovement>().GetCurrentHeight();
if (_attachedAudioSource)
{
_attachedAudioSource.PlayOneShot(shipDeathSFX);
}
// Start the delayed core spawn coroutine, this can probs be replaced once the death animations are in to spawn once that has ended.
StartCoroutine("DelayedCoreSpawn");
ParticleSystem boomboom = Instantiate(effectA);
ParticleSystem boomboom2 = Instantiate(effectB);
boomboom.transform.position = _deathPos;
boomboom2.transform.position = _deathPos;
shipModel.SetActive(false);
gameObject.tag = "Dead";
gameObject.layer = LayerMask.NameToLayer("NoCollide");
_enemyDestroyed = true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 78e23ebcb41b7534081ed5e4065244d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,236 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with generic "Dumb" enemy movement AI
/// </summary>
public class EnemyHoverMovement : 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;
public float jumpForce;
public float jumpMaxTime;
private float _residualThrust;
private float _residualThrustCurrentTime;
private float _currentJumpTime;
private bool _isJumping;
// Variables for RNG movement
private float _rngVert;
private float _rngHorz;
private bool _rngJump;
public float maxRNGThrust;
public float movementDecayRate;
public float movementTickMax;
private float _movementCurrentTick;
// Start is called before the first frame update
void Start()
{
_residualThrust = 0.0f;
_residualThrustCurrentTime = 0.0f;
_currentJumpTime = 0.0f;
_isJumping = false;
_rngJump = false;
_rngHorz = 0.0f;
_rngVert = 0.0f;
BaseOnStart();
// Custom start stuff can go here
}
/// <summary>
/// Calculates some RNG movement for the attached Enemy.
/// </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)
{
// Check if the movement tick has passed
if (_movementCurrentTick >= movementTickMax)
{
// Pick a random horz value
if (_rngHorz == 0)
{
_rngHorz = Random.Range(0, maxRNGThrust);
}
// Pick a random vert value
if (_rngVert == 0)
{
_rngVert = Random.Range(0, maxRNGThrust);
}
// Do an RNG check to see if the enemy jumps
int jumpNow = Random.Range(0, 10);
if (jumpNow > 3 || _immuneMinHit)
{
_rngJump = true;
}
else
{
_rngJump = false;
}
_movementCurrentTick = 0.0f;
}
else
{
// Reset the variables to stop it turning/moving
if (_rngHorz > 0)
{
_rngHorz = Mathf.Clamp(_rngHorz - movementDecayRate, 0, maxRNGThrust); ;
}
if (_rngVert > 0)
{
_rngVert = Mathf.Clamp(_rngVert - movementDecayRate, 0, maxRNGThrust);
}
_movementCurrentTick += currentTimeStep;
}
}
/// <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.
/// Anything in this method can be removed, as long as the _turnDirection and _thrustDirection are set then the parent script with handle the orbit and positioning.
/// </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 axis from the RNG (or whatever vars you want)
float horzInput = _rngHorz;
float vertInput = _rngVert;
// Check horz direction value, pos = Right, neg = Left
if (horzInput > 0)
{
_turnDirection = 1;
}
else if (horzInput < 0)
{
_turnDirection = -1;
}
else
{
_turnDirection = 0;
}
// Check if the vert is pushed forwards or back, pos = forward, neg = back
if (vertInput > 0)
{
_thrusting = true;
_thrustDirection = 1;
if (_residualThrust < residualThrustMax)
{
_residualThrust += residualThrustStep * currentTimeStep;
}
}
else if (vertInput < 0)
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = true;
_thrustDirection = -1;
}
}
else
{
if (_residualThrust > 0.0f)
{
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrust -= residualThrustIdleDecayRate;
}
_thrustDirection = _residualThrust / residualThrustMax;
}
else
{
_thrusting = false;
_thrustDirection = 0;
}
}
// Clamp the residual thrust so we cant fall below 0 or greater than the max value set
_residualThrust = Mathf.Clamp(_residualThrust, 0, residualThrustMax);
if (_residualThrustCurrentTime >= residualThrustTimeTickMax)
{
_residualThrustCurrentTime = 0.0f;
}
else
{
_residualThrustCurrentTime += currentTimeStep;
}
// Check if the jump button
if (_rngJump && !_isJumping)
{
_isJumping = true;
}
// Run any base class stuff
base.ProcessPreMovement(currentTimeStep);
}
}
/// <summary>
/// Method for dealing with the jump physics, this should be in the fixed update since it uses rigidbody physics
/// </summary>
void ProcessJump()
{
if (_isJumping)
{
_objectRigidbody.AddRelativeForce(Vector3.up * jumpForce * Time.fixedDeltaTime, ForceMode.Impulse);
if (_currentJumpTime >= jumpMaxTime)
{
_currentJumpTime = 0.0f;
_isJumping = false;
_rngJump = false;
}
else
{
_currentJumpTime += Time.fixedDeltaTime;
}
}
}
private void FixedUpdate()
{
if (objectIsActive)
{
ProcessJump();
}
}
// Update is called once per frame
void Update()
{
if (objectIsActive)
{
DoRNG(Time.deltaTime);
ProcessPreMovement(Time.deltaTime);
ProcessCurrentMovement(Time.deltaTime);
ProcessPostMovement();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ccc03e36ad319641aaa5ed3b5e4f1e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,108 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyObjectShared : ObjectShared
{
// Tracking the spawner this gameObject was created by so we can reduce the counter for it later
private ObjectSpawning _spawner;
public AudioClip spawnInSFX;
public GameObject spawnInVFX;
private AudioSource _currentAudioSource;
private bool _didSpawnInVFX = false;
public int deadEngineChance;
public float deadEngineInitialCheckTime;
public float deadEngineRecheckTime;
private float _deadEngineCheckTick;
private bool _engineFailing;
private bool _engineDead;
public ObjectSpawning Spawner
{
get
{
return _spawner;
}
set
{
_spawner = value;
}
}
private void Start()
{
_currentAudioSource = gameObject.GetComponent<AudioSource>();
}
public void DoFailure()
{
HoverMovement currentHoverMovement = gameObject.GetComponent<HoverMovement>();
if (currentHoverMovement != null)
{
currentHoverMovement.freezeMovement = true;
currentHoverMovement.blackHoleImmune = false;
TrailRenderer[] currentTrails = gameObject.GetComponentsInChildren<TrailRenderer>();
foreach (TrailRenderer trail in currentTrails)
{
trail.enabled = false;
}
}
_engineFailing = true;
_engineDead = true;
}
private void Update()
{
if (!_didSpawnInVFX)
{
if (spawnInVFX != null)
{
Instantiate(spawnInVFX, gameObject.transform);
}
if (spawnInSFX != null)
{
if (_currentAudioSource != null)
{
_currentAudioSource.PlayOneShot(spawnInSFX);
}
}
_didSpawnInVFX = true;
}
if (_engineFailing)
{
if (!_engineDead)
{
if (_deadEngineCheckTick >= deadEngineRecheckTime)
{
int rngRoll = Random.Range(0, 100);
if (rngRoll <= deadEngineChance)
{
DoFailure();
}
_deadEngineCheckTick = 0.0f;
}
else
{
_deadEngineCheckTick += Time.deltaTime;
}
}
}
else
{
if (_deadEngineCheckTick >= deadEngineInitialCheckTime)
{
_engineFailing = true;
_deadEngineCheckTick = 0.0f;
}
else
{
_deadEngineCheckTick += Time.deltaTime;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71299cd9f865e424aa252b67e86c9b86
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameEngine : MonoBehaviour
{
public GameObject currentBlackHole;
public GameObject currentPlayer;
public BackgroundMusicManager currentBGMManager;
//public TMPro.TextMeshProUGUI coreCountText;
// might need it for core bar
// public coresmeter corebar;
public HealthBar livesBar;
public float arenaSize;
private BlackHoleManager _currentBlackHoleManager;
// Start is called before the first frame update
void Awake()
{
// Get the current blackhole so we have easy access to its variables
_currentBlackHoleManager = currentBlackHole.GetComponent<BlackHoleManager>();
}
private void Start()
{
// Make sure godmode is off when starting.
GameManager.Instance.godMode = false;
GameManager.Instance.SetupLevel();
// Start the game, make sure the play GO is active
currentPlayer.SetActive(true);
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(0);
}
}
/// <summary>
/// Gets the current blackhole radius
/// </summary>
/// <returns>Current Blackhole size as a float</returns>
public float GetCurrentBlackHoleRadius()
{
return _currentBlackHoleManager.currentBlackHoleRadius;
}
// Update is called once per frame
void Update()
{
// Keep the core counter upto date with the current number of cores in the gamemanager
//coreCountText.text = GameManager.Instance.getCoreCount().ToString();
livesBar.Health(GameManager.Instance.GetLives());
//corebar.pickupcore(GameManager.Instance.getCoreCount());
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 19749c0a365e21341b18d997644d62b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthPowerUpColliderManager : ColliderManager
{
public AudioClip tokenPickupSFX;
private AudioSource _audioSource;
// Bool checks if the core has been collected, this is because the ships are made of multiple collision boxes and would trigger more than once.
private bool _tokenCollected = false;
public override void DoAwakeTasks()
{
GameObject playerGO = GameObject.Find("Player");
_audioSource = playerGO.GetComponent<AudioSource>();
base.DoAwakeTasks();
}
public override void ProcessCollision(CollisionDirection direction, Collision collision, bool wasChild)
{
GameObject collisionGO;
if (wasChild)
{
collisionGO = collision.transform.parent.gameObject;
}
else
{
collisionGO = collision.gameObject;
}
// Check the tag of the collided object, Direction doesnt matter i assume
switch (collisionGO.tag)
{
case "Player":
PickupToken();
break;
}
}
/// <summary>
/// Process the core pick up and destroy the core object.
/// </summary>
public void PickupToken()
{
// If the core has been collected ignore it.
if (!_tokenCollected)
{
_tokenCollected = true;
if (_audioSource != null)
{
_audioSource.PlayOneShot(tokenPickupSFX);
}
GameManager.Instance.AddLife();
if (transform.childCount > 0)
{
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
}
Destroy(gameObject, 2.0f);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70fcf396118a0b94d89673a208f6ac2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,199 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Class for dealing with all of the movement calculations around the blackhole, this should be inherited by another script and extended to meet its purpose
/// </summary>
public class HoverMovement : MonoBehaviour
{
// Freezes all movement for the attached gameobject
public bool freezeMovement;
public bool objectIsActive = true;
public float testBaseHeight;
public GameObject objectModel;
public float startHeight;
public Vector3 startPositionVector = Vector3.zero;
public float turnSpeed;
public float smoothRollTime;
public float smoothThrusting;
public float rollAngle;
public float turnSmoothTime;
public float maxThrust;
protected int _turnDirection;
protected float _smoothedTurnSpeed;
protected float _smoothTurnV;
protected float _smoothRollV;
protected float _currentThrust;
protected float _currentHeight;
protected float _currentRollAngle;
protected bool _thrusting;
protected float _thrustDirection;
public bool blackHoleImmune;
public float immuneMinHeight;
protected bool _immuneMinHit;
protected GameEngine _currentGameEngine;
protected Rigidbody _objectRigidbody;
private void Awake()
{
_currentGameEngine = FindObjectOfType<GameEngine>();
_objectRigidbody = GetComponent<Rigidbody>();
DoAwakeTasks();
}
/// <summary>
/// Method for allowing a child script to execute code during the awake call
/// </summary>
public virtual void DoAwakeTasks()
{
}
/// <summary>
/// Method for forcing a gameObject to a specific height given
/// </summary>
/// <param name="newHeight">Height distance from the blackhole</param>
public void ForceHeightAdjust(float newHeight)
{
startHeight = newHeight;
_currentHeight = newHeight;
}
/// <summary>
/// Method to force the current GO back to its start location
/// </summary>
public void ForceStartLocationReset()
{
float blackHoleSize = _currentGameEngine.GetCurrentBlackHoleRadius();
_currentHeight = startHeight; // 1 + (transform.position.y - blackHoleInitialSize) / blackHoleInitialSize;
_thrusting = false;
Vector3 startPos = startPositionVector + transform.forward;
Vector3 testPos = startPos.normalized * (blackHoleSize * _currentHeight);
float heightDistance = (testPos - _currentGameEngine.currentBlackHole.transform.position).magnitude;
if (heightDistance >= _currentGameEngine.arenaSize)
{
_currentHeight = (_currentGameEngine.arenaSize - 5.0f) / blackHoleSize;
}
startPos = startPos.normalized * (blackHoleSize * _currentHeight);
transform.position = startPos;
}
/// <summary>
/// Method for run start call jobs once the child has
/// </summary>
public void BaseOnStart()
{
if (!_currentGameEngine)
{
objectIsActive = false;
}
else
{
ForceStartLocationReset();
}
}
/// <summary>
/// Method to get the current height of this object
/// </summary>
/// <returns>Current height as a float</returns>
public float GetCurrentHeight()
{
return _currentHeight;
}
/// <summary>
/// Method for the child scripts to setup the variables needed for movement
/// </summary>
/// <param name="currentTimeStep">Time scale used, depends if this is in fixedUpdate or update.</param>
public virtual void ProcessPreMovement(float currentTimeStep)
{
}
/// <summary>
/// Method that processes the actual movement around the blackhole using some wizard math
/// </summary>
/// <param name="currentTimeStep">Time step currently used</param>
public virtual void ProcessCurrentMovement(float currentTimeStep)
{
float heightDistance = (transform.position - _currentGameEngine.currentBlackHole.transform.position).magnitude;
if (heightDistance >= _currentGameEngine.arenaSize)
{
heightDistance = _currentGameEngine.arenaSize;
}
float currentBlackHoleSize = _currentGameEngine.GetCurrentBlackHoleRadius();
_currentHeight = heightDistance / currentBlackHoleSize;
testBaseHeight = heightDistance;
if (blackHoleImmune)
{
float relImmuneHeight = immuneMinHeight / currentBlackHoleSize;
if (_currentHeight < relImmuneHeight)
{
_currentHeight = relImmuneHeight;
_immuneMinHit = true;
}
else
{
_immuneMinHit = false;
}
}
_smoothedTurnSpeed = Mathf.SmoothDamp(_smoothedTurnSpeed, _turnDirection * turnSpeed, ref _smoothTurnV, turnSmoothTime);
float turnAmount = _smoothedTurnSpeed * currentTimeStep;
transform.RotateAround(transform.position, transform.up, turnAmount);
_currentThrust = Mathf.Lerp(_currentThrust, maxThrust, 1 - Mathf.Pow(smoothThrusting, currentTimeStep));
float thrustSpeed = (Mathf.Cos(1 * Mathf.Deg2Rad) * _currentThrust) * _thrustDirection;
Vector3 movePos = transform.position + transform.forward * thrustSpeed * currentTimeStep;
movePos = movePos.normalized * (_currentGameEngine.GetCurrentBlackHoleRadius() * _currentHeight);
transform.position = movePos;
ProcessRotation();
float targetRoll = _turnDirection * rollAngle;
_currentRollAngle = Mathf.SmoothDampAngle(_currentRollAngle, targetRoll, ref _smoothRollV, smoothRollTime);
}
/// <summary>
/// Method to check if the gameobject has hit the min height and become gravity immune
/// </summary>
/// <returns>True if the min height hit</returns>
public bool IsGravityImmune()
{
return _immuneMinHit;
}
/// <summary>
/// Method for processing the rotation of the model
/// </summary>
public virtual void ProcessRotation()
{
Vector3 gravityUp = transform.position.normalized;
transform.rotation = Quaternion.FromToRotation(transform.up, gravityUp) * transform.rotation;
transform.LookAt((transform.position + transform.forward * 10).normalized * (_currentGameEngine.GetCurrentBlackHoleRadius() * _currentHeight), gravityUp);
}
public virtual void ProcessPostMovement()
{
if (objectModel != null)
{
objectModel.transform.localEulerAngles = new Vector3(1, 0, _currentRollAngle);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb69462eb3922254980da6204a1dad2a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More