Skip to content
Snippets Groups Projects
Commit 72caf628 authored by Matthewit Dechatech's avatar Matthewit Dechatech
Browse files

More comments, a few variable renames, code cleanup

parent cae49fba
No related branches found
No related tags found
No related merge requests found
Showing
with 207 additions and 177 deletions
Loading
Loading
@@ -3,7 +3,7 @@
namespace SonicRealms.Core.Actors
{
/// <summary>
/// Health system for badniks... which is a one hit kill.
/// Health system for badniks... which is just set to die in one hit.
/// </summary>
public class BadnikHealth : HealthSystem
{
Loading
Loading
Loading
Loading
@@ -5,9 +5,16 @@
 
namespace SonicRealms.Core.Actors
{
/// <summary>
/// The part of the badnik that makes it go 'poof' and bounces up the player when hit.
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class BadnikWeakSpot : ReactiveArea
{
/// <summary>
/// The badnik's health system. It will sustain damage under the appropriate conditions.
/// </summary>
[Tooltip("The badnik's health system. It will sustain damage under the appropriate conditions.")]
public HealthSystem Badnik;
 
[HideInInspector]
Loading
Loading
@@ -50,6 +57,7 @@ public override void OnAreaStay(Hitbox hitbox)
var sonicHitbox = hitbox as SonicHitbox;
if (sonicHitbox == null) return;
 
// The weak spot can hurt the player back, too!
if (sonicHitbox.Vulnerable && !sonicHitbox.Harmful)
{
sonicHitbox.Health.TakeDamage(transform);
Loading
Loading
Loading
Loading
@@ -36,6 +36,9 @@ public class BreathMeter : MonoBehaviour
[Tooltip("How quickly the controller gets air back, in seconds per second (lol).")]
public float ReplenishRate;
 
/// <summary>
/// Gravity after drowning.
/// </summary>
[Space]
[Tooltip("Gravity after drowning.")]
public float DrownGravity;
Loading
Loading
@@ -237,6 +240,7 @@ public virtual void Update()
if (AirPercentFloatHash != 0) MeterAnimator.SetFloat(AirPercentFloatHash, RemainingAir/TotalAir);
}
 
// Replenish air when the player can breathe
if (CanBreathe)
{
RemainingAir += ReplenishRate*Time.deltaTime;
Loading
Loading
@@ -246,6 +250,7 @@ public virtual void Update()
return;
}
 
// Otherwise deplete air - if it's below zero, then drown
RemainingAir -= Time.deltaTime;
if (RemainingAir < 0.0f)
{
Loading
Loading
Loading
Loading
@@ -89,12 +89,17 @@ public void Start()
_waterChecker = StartCoroutine(CheckWater());
}
 
/// <summary>
/// Coroutine that runs while the bubble is underwater.
/// </summary>
/// <returns></returns>
protected IEnumerator CheckWater()
{
yield return new WaitForSeconds(WaterCheckInterval);
 
while (true)
{
// If we left water, pop
if (!Physics2D.OverlapPoint(transform.position, WaterLayer)) Pop();
yield return new WaitForSeconds(WaterCheckInterval);
}
Loading
Loading
@@ -130,11 +135,13 @@ public void FixedUpdate()
{
float x = transform.position.x, y = transform.position.y;
 
// A little horizontal wiggle
WiggleTimer += Time.deltaTime;
WiggleTimer %= WiggleTime;
 
x += (WiggleTimer/WiggleTime < 0.5f ? WiggleLength : -WiggleLength)*Time.deltaTime/WiggleTime;
 
// Float upwards
y += Buoyancy*Time.deltaTime;
 
transform.position = new Vector3(x, y);
Loading
Loading
Loading
Loading
@@ -355,6 +355,7 @@ public void Start()
Rigidbody2D = GetComponent<Rigidbody2D>();
Rigidbody2D.velocity = MoveSpeed;
 
// Add callbacks so we know when our child colliders (like line of sight) find something
if (PlayerSearchArea)
{
var fov = PlayerSearchArea.gameObject.AddComponent<TriggerCallback2D>();
Loading
Loading
@@ -374,6 +375,7 @@ public void Update()
{
if (!CanShoot)
{
// Update the shot cooldown timer
TimeBetweenShotsTimer -= Time.deltaTime;
if (TimeBetweenShotsTimer < 0f)
{
Loading
Loading
@@ -385,9 +387,10 @@ public void Update()
{
if(EnemySighted) Shoot(false);
}
if (CurrentState == State.Shooting)
{
// Stay in the shooting state for the duration of the shot timer
ShotTimer -= Time.deltaTime;
if (ShotTimer < 0f)
{
Loading
Loading
@@ -397,6 +400,7 @@ public void Update()
}
else if (CurrentState == State.Turning)
{
// Stay in the turning state for the duration of the turn timer
TurnTimer -= Time.deltaTime;
if (TurnTimer < 0f)
{
Loading
Loading
@@ -408,6 +412,7 @@ public void Update()
 
public void OnPlayerEnter(Collider2D other)
{
// Keeps track of players currently in the line of sight
if (!other.CompareTag(PlayerTag)) return;
 
EnemySighted = true;
Loading
Loading
@@ -416,6 +421,7 @@ public void OnPlayerEnter(Collider2D other)
 
public void OnPlayerExit(Collider2D other)
{
// Removes players from its internal list once they have left the line of sight
if (!other.CompareTag(PlayerTag)) return;
 
EnemiesSighted.Remove(other);
Loading
Loading
@@ -424,6 +430,7 @@ public void OnPlayerExit(Collider2D other)
 
public void OnSignalEnter(Collider2D other)
{
// Interpret the signal based on the collider's tag
if (other.CompareTag(TurnLeftTag)) Turn(false);
else if (other.CompareTag(TurnRightTag)) Turn(true);
else if (other.CompareTag(ShootTag)) Shoot(false);
Loading
Loading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assets.Scripts.SonicRealms.Core.Actors
{
class CharacterBubbleGenerator
{
}
}
fileFormatVersion: 2
guid: 958c8377f3d9a734fb1ef3e807798965
timeCreated: 1456992559
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading
Loading
@@ -87,6 +87,7 @@ public void OnCollide(TerrainCastHit hit)
if (HitGroundTriggerHash != 0) Animator.SetTrigger(HitGroundTriggerHash);
}
 
// When we hit the ground, ignore it and jump right back up
Controller.IgnoreThisCollision();
Controller.FacingForward = FacingRight;
Controller.RelativeVelocity = new Vector2(RunSpeed * (FacingRight ? 1f : -1f), JumpSpeed);
Loading
Loading
Loading
Loading
@@ -3,6 +3,9 @@
 
namespace SonicRealms.Core.Actors
{
/// <summary>
/// Used for all health-related events.
/// </summary>
[Serializable]
public class HealthEvent : UnityEvent<HealthEventArgs>
{
Loading
Loading
Loading
Loading
@@ -3,6 +3,9 @@
 
namespace SonicRealms.Core.Actors
{
/// <summary>
/// Some data to pass in when a health-related event occurs.
/// </summary>
[Serializable]
public class HealthEventArgs
{
Loading
Loading
Loading
Loading
@@ -117,21 +117,37 @@ public virtual void Update()
}
}
 
/// <summary>
/// Take one damage from an unspecified source.
/// </summary>
public void TakeDamage()
{
TakeDamage(1f, null);
}
 
/// <summary>
/// Takes the given amount of damage from an unspecified source.
/// </summary>
/// <param name="damage">The amount of damage to take.</param>
public void TakeDamage(float damage)
{
TakeDamage(damage, null);
}
 
/// <summary>
/// Takes one damage from the given source.
/// </summary>
/// <param name="source">The source that caused the damage.</param>
public void TakeDamage(Transform source)
{
TakeDamage(1f, source);
}
 
/// <summary>
/// Takes the given amount of damage from the specified source.
/// </summary>
/// <param name="damage">The amount of damage to take.</param>
/// <param name="source">The source that caused the damage.</param>
public virtual void TakeDamage(float damage, Transform source)
{
if (Invincible || IsDead) return;
Loading
Loading
Loading
Loading
@@ -198,24 +198,30 @@ public override void TakeDamage(float damage, Transform source)
{
if (Invincible) return;
 
// Check if the damage source is a spike (to play different sounds in response)
var spikes = source.CompareTag(SpikeTag);
 
// Perform the rebound
HurtReboundMove.ThreatPosition = source ? (Vector2)source.position : default(Vector2);
HurtReboundMove.OnEnd.AddListener(OnHurtReboundEnd);
HurtReboundMove.Perform();
// Start our invincibility frames
HurtInvincibilityTimer = HurtInvinciblilityTime;
HurtInvincible = Invincible = true;
 
// See if the player had a shield
var shield = Controller.GetPowerup<Shield>();
if (shield == null)
{
// If not, and we're out of rings, we're dead
if (RingCounter.Rings <= 0)
{
Kill();
return;
}
 
// Otherwise just spill the beans
RingCounter.Spill(RingsLost);
 
if (RingLossSound != null)
Loading
Loading
@@ -223,6 +229,7 @@ public override void TakeDamage(float damage, Transform source)
}
else
{
// Special spike sound
if (spikes)
{
if (SpikeSound != null)
Loading
Loading
@@ -235,10 +242,13 @@ public override void TakeDamage(float damage, Transform source)
}
}
 
Controller.EndMove<Roll>();
OnHurt.Invoke(null);
}
 
/// <summary>
/// Lets the player know that he killed an enemy
/// </summary>
/// <param name="enemy"></param>
public void NotifyEnemyKilled(HealthSystem enemy)
{
OnEnemyKilled.Invoke(enemy);
Loading
Loading
Loading
Loading
@@ -99,6 +99,7 @@ public void Update()
{
if (Controller.Grounded)
{
// A whole bunch of conditions to see if we should or shouldn't rotate
var rotateToSensors = true;
rotateToSensors &= RotateDuringStand || !DMath.Equalsf(Controller.GroundVelocity);
rotateToSensors &= Roll == null || RotateDuringRoll || !Roll.Active;
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ namespace SonicRealms.Core.Actors
public class HitboxEvent : UnityEvent<AreaTrigger> { }
 
/// <summary>
/// Hitbox that can decide when it wants to let an area trigger know it's been collided with.
/// A hitbox that triggers areas. Widely used for player attacks and stuff.
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class Hitbox : MonoBehaviour
Loading
Loading
Loading
Loading
@@ -236,40 +236,38 @@ public override void OnActiveUpdate()
public override void OnActiveFixedUpdate()
{
UpdateControlLockTimer();
if (!ControlLockTimerOn)
{
Controller.ApplyGroundFriction = !Accelerate(_axis);
}
 
if (Mathf.Abs(Controller.GroundVelocity) < Controller.DetachSpeed)
{
if (DMath.AngleInRange_d(Controller.RelativeSurfaceAngle, 50.0f, 310.0f))
{
Lock();
}
}
// Accelerate as long as the control lock isn't on
if (!ControlLockTimerOn) Accelerate(_axis);
// If we're on a wall and aren't going quickly enough, start the control lock
if (Mathf.Abs(Controller.GroundVelocity) < Controller.DetachSpeed &&
DMath.AngleInRange_d(Controller.RelativeSurfaceAngle, 50.0f, 310.0f))
Lock();
// Disable slope gravity when we're not moving, so that Sonic can stand on slopes
Controller.DisableSlopeGravity = !(Accelerating || ControlLockTimerOn ||
Mathf.Abs(Controller.GroundVelocity) > MinSlopeGravitySpeed);
 
Controller.ApplySlopeGravity = Accelerating || ControlLockTimerOn ||
Mathf.Abs(Controller.GroundVelocity) > MinSlopeGravitySpeed;
Controller.ApplyGroundFriction = !Accelerating && !Braking;
// Disable ground friction while we have player input
Controller.DisableGroundFriction = Accelerating || Braking;
 
// Orient the player in the direction we're moving (not graphics-wise, just internally!)
if (!ControlLockTimerOn && !DMath.Equalsf(_axis))
Controller.FacingForward = Controller.GroundVelocity >= 0.0f;
}
 
public override void OnActiveExit()
{
// Set everything back to normal
Controller.OnSteepDetach.RemoveListener(OnSteepDetach);
Controller.ApplySlopeGravity = true;
Controller.ApplyGroundFriction = true;
Controller.DisableSlopeGravity = false;
Controller.DisableGroundFriction = false;
 
if (Animator == null)
return;
if (!string.IsNullOrEmpty(AcceleratingBool))
Animator.SetBool(AcceleratingBool, false);
if (Animator == null) return;
 
if (!string.IsNullOrEmpty(BrakingBool))
Animator.SetBool(BrakingBool, false);
if (AcceleratingBoolHash != 0) Animator.SetBool(AcceleratingBoolHash, false);
if (BrakingBoolHash != 0) Animator.SetBool(BrakingBoolHash, false);
}
 
public override void SetAnimatorParameters()
Loading
Loading
Loading
Loading
@@ -60,6 +60,8 @@ public void OnPerformAirControl()
 
public override void OnActiveEnter(State previousState)
{
Manager.End<Roll>();
Controller.OnAttach.AddListener(OnAttach);
 
// Set speed based on underwater and position of the threat
Loading
Loading
Loading
Loading
@@ -8,6 +8,7 @@ Sonic Physics Guide by Mercury.
Sound rips by Techokami.
 
Sprite Rips by...
Mercury
1001
Flare
SupaChao
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment