Skip to content

Commit

Permalink
Add Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JaydeeAlkema committed Jun 3, 2020
1 parent f0b53e1 commit 1142e6a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
39 changes: 33 additions & 6 deletions Assets/Scripts/Enemy AI/EnemyBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private void OnEnable()
#endregion

#region Functions
/// <summary>
/// Searches for the nearest target.
/// As of now it just gets the player from the Game Manager.
/// </summary>
/// <returns></returns>
private IEnumerator SearchForTarget()
{
while(true)
Expand All @@ -81,6 +86,10 @@ private IEnumerator SearchForTarget()
}
}

/// <summary>
/// Moves the enemy to the target at a set interval.
/// </summary>
/// <returns></returns>
private IEnumerator MoveToTarget()
{
while(true)
Expand All @@ -98,6 +107,10 @@ private IEnumerator MoveToTarget()
}
}

/// <summary>
/// Attacks the target at a set interval
/// </summary>
/// <returns></returns>
private IEnumerator AttackTarget()
{
while(true)
Expand All @@ -115,6 +128,11 @@ private IEnumerator AttackTarget()
}
}

/// <summary>
/// IDamageable Damage Implementation
/// Decreases the health and handles what needs to happen when health falls bellow 0.
/// </summary>
/// <param name="damage"></param>
void IDamageable.Damage(float damage)
{
health -= damage;
Expand All @@ -127,6 +145,21 @@ void IDamageable.Damage(float damage)
}
}

/// <summary>
/// IDamageable Impact Movement Speed Implementation.
/// This slows the enemy down to a crawl.
/// </summary>
/// <param name="value"></param>
void IDamageable.ImpactMovementSpeed(float value)
{
moveSpeed = value;
agent.speed = moveSpeed;
}

/// <summary>
/// Removes all the active components once the Enemy is considered Dead.
/// This is done so the enemy carcass can still exist in the world without having all the code still run on the background.
/// </summary>
private void RemoveAllActiveComponents()
{
target = null;
Expand All @@ -136,12 +169,6 @@ private void RemoveAllActiveComponents()
Destroy(GetComponent<NavMeshAgent>());
Destroy(this);
}

void IDamageable.ImpactMovementSpeed(float value)
{
moveSpeed = value;
agent.speed = moveSpeed;
}
#endregion

#region Debugging
Expand Down
51 changes: 50 additions & 1 deletion Assets/Scripts/Player/PlayerBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PlayerBehaviour : MonoBehaviour, IDamageable
[SerializeField] private float manaRegenInterval = default; // How much time in between regen ticks.
[Space]
[SerializeField] private GameObject currentTarget = default; // Current Target of the player.
[SerializeField] private GameObject previousTarget = default; // Next Target of the player.
[SerializeField] private GameObject previousTarget = default; // Next Target of the player.
[Space]
[Header("Attack Spells")]
[SerializeField] private GameObject primaryAttackPrefab = default; // Primary Attack Prefab.
Expand Down Expand Up @@ -46,6 +46,8 @@ public class PlayerBehaviour : MonoBehaviour, IDamageable
public float MaxMana { get => maxMana; set => maxMana = value; }
#endregion


#region Monobehaviour Callbacks
private void Awake()
{
charController = GetComponent<CharacterController>();
Expand All @@ -70,7 +72,12 @@ private void Update()
if(currentTarget.GetComponent<EnemyBehaviour>() != null)
if(currentTarget.GetComponent<EnemyBehaviour>().State == EnemyState.Dead) currentTarget = null;
}
#endregion

#region Functions
/// <summary>
/// Handles the player movement.
/// </summary>
private void PlayerMovement()
{
float horInput = Input.GetAxisRaw(horizontalInputName);
Expand All @@ -88,6 +95,9 @@ private void PlayerMovement()
JumpInput();
}

/// <summary>
/// Sets the movementspeed
/// </summary>
private void SetMovementSpeed()
{
if(Input.GetKey(runKey))
Expand All @@ -96,6 +106,9 @@ private void SetMovementSpeed()
movementSpeed = Mathf.Lerp(movementSpeed, walkSpeed, Time.deltaTime * runBuildUpSpeed);
}

/// <summary>
/// Handles jump input.
/// </summary>
private void JumpInput()
{
if(Input.GetKeyDown(jumpKey) && !isJumping)
Expand All @@ -105,6 +118,9 @@ private void JumpInput()
}
}

/// <summary>
/// Checks for Attack Input.
/// </summary>
private void AttackInput()
{
if(currentTarget)
Expand All @@ -123,6 +139,10 @@ private void AttackInput()
}
}

/// <summary>
/// Attack Event.
/// </summary>
/// <param name="attackSpellToSpawns"></param>
private void AttackEvent(GameObject attackSpellToSpawns)
{
if(mana - attackSpellToSpawns.GetComponent<Spell>().ManaCost > 0)
Expand Down Expand Up @@ -157,6 +177,10 @@ private void AttackEvent(GameObject attackSpellToSpawns)
}
}

/// <summary>
/// Jump Event.
/// </summary>
/// <returns></returns>
private IEnumerator JumpEvent()
{
charController.slopeLimit = 90f;
Expand All @@ -172,6 +196,10 @@ private IEnumerator JumpEvent()
isJumping = false;
}

/// <summary>
/// Handles everything that should be done when walking over a slope.
/// </summary>
/// <returns></returns>
private bool OnSlope()
{
if(isJumping)
Expand All @@ -183,6 +211,9 @@ private bool OnSlope()
return false;
}

/// <summary>
/// Checks for a cell underneath the player.
/// </summary>
private void CheckForCellUnderneathPlayer()
{
if(Physics.Raycast(transform.position, Vector3.down, out RaycastHit hit, charController.height / 2f * slopeForceRayLength))
Expand All @@ -192,6 +223,9 @@ private void CheckForCellUnderneathPlayer()
}
}

/// <summary>
/// Gets a target from the target layermask underneath the crosshair.
/// </summary>
private void GetTargetUnderCrosshair()
{
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward * 1000f);
Expand All @@ -218,16 +252,30 @@ private void GetTargetUnderCrosshair()
if(previousTarget.GetComponent<Outline>() != null) previousTarget.GetComponent<Outline>().enabled = false;
}

/// <summary>
/// IDamageable Damage Implementation
/// Removes health from the health pool.
/// </summary>
/// <param name="damage"></param>
void IDamageable.Damage(float damage)
{
health -= damage;
}

/// <summary>
/// Changes the movement speed.
/// Only used when stepping on de Poisoned Ground Spell.
/// </summary>
/// <param name="value"></param>
void IDamageable.ImpactMovementSpeed(float value)
{
movementSpeed = value;
}

/// <summary>
/// Actively Regenerates the players Mana.
/// </summary>
/// <returns></returns>
private IEnumerator ManaRegen()
{
while(true)
Expand All @@ -237,4 +285,5 @@ private IEnumerator ManaRegen()
if(mana > maxMana) mana = maxMana;
}
}
#endregion
}
9 changes: 9 additions & 0 deletions Assets/Scripts/Spells/Spell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ private void Update()
#endregion

#region Functions
/// <summary>
/// Gets all the enemies withing a certain radius.
/// This gets send to the targets in radius list. This list is cleared each time we check for targets.
/// </summary>
/// <returns></returns>
private IEnumerator GetAllEnemiesWithinSpellRadius()
{
while(timeLeftToTick > 0)
Expand All @@ -99,6 +104,10 @@ private IEnumerator GetAllEnemiesWithinSpellRadius()
yield return null;
}

/// <summary>
/// Damages all the enemies in the Targets in radius list.
/// </summary>
/// <returns></returns>
private IEnumerator DamageEnemiesWithinSpellRadius()
{
while(timeLeftToTick > 0)
Expand Down

0 comments on commit 1142e6a

Please sign in to comment.