Skip to content

Commit

Permalink
0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
XVNexus committed Oct 3, 2021
1 parent e231707 commit 2d4a21d
Show file tree
Hide file tree
Showing 18 changed files with 764 additions and 367 deletions.
24 changes: 20 additions & 4 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -11038,6 +11038,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
gameManager: {fileID: 1063200708}
inputManager: {fileID: 1063200710}
rigidbody: {fileID: 436660936}
healthBar: {fileID: 1833567298}
healthRing: {fileID: 953429185}
Expand Down Expand Up @@ -26547,7 +26548,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: 67746999d6b2a3643b2f2bc788129d3c, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: 933198a710d552c479d220044a42669b, type: 3}
sourceAsset: {fileID: 9197481963319205126, guid: eaf38cbe673cab7468f801b5f21e9d4a, type: 3}
m_SortingOrder: 0
--- !u!4 &713000144
Transform:
Expand Down Expand Up @@ -36506,6 +36507,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
gameManager: {fileID: 1063200708}
inputManager: {fileID: 1063200710}
rigidbody: {fileID: 829604303}
healthBar: {fileID: 966392961}
healthRing: {fileID: 1317734951}
Expand Down Expand Up @@ -42333,8 +42335,9 @@ GameObject:
m_Component:
- component: {fileID: 1063200709}
- component: {fileID: 1063200708}
- component: {fileID: 1063200710}
m_Layer: 0
m_Name: Game Manager
m_Name: Manager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand All @@ -42356,7 +42359,7 @@ MonoBehaviour:
players:
- {fileID: 829604307}
- {fileID: 436660935}
gameResetDelay: 3
gameResetDelay: 2
--- !u!4 &1063200709
Transform:
m_ObjectHideFlags: 0
Expand All @@ -42365,12 +42368,25 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1063200707}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1063200710
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1063200707}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe3a1b5ae39a5814dad032325e81fd84, type: 3}
m_Name:
m_EditorClassIdentifier:
uiController: {fileID: 713000145}
--- !u!1 &1067489402
GameObject:
m_ObjectHideFlags: 0
Expand Down
22 changes: 0 additions & 22 deletions Assets/Scripts/Controllers/InputController.cs

This file was deleted.

98 changes: 50 additions & 48 deletions Assets/Scripts/Controllers/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ public AbilitySettings(float chargeTime, float activeTime, float cooldownTime, V

public abstract class Ability
{
public AbilitySettings settings;
public AbilityState state { get; private set; } = AbilityState.IDLE;
public float chargeTimer { get; private set; } = 0f;
public float activeTimer { get; private set; } = 0f;
public float cooldownTimer { get; private set; } = 0f;
public float ChargeCompletePercent { get => chargeTimer / settings.chargeTime; }
public float ActiveCompletePercent { get => (settings.activeTime - activeTimer) / settings.activeTime; }
public float CooldownCompletePercent { get => (settings.cooldownTime - cooldownTimer) / settings.cooldownTime; }
public AbilitySettings Settings { get; set; }
public AbilityState State { get; private set; } = AbilityState.IDLE;
public float ChargeTimer { get; private set; } = 0f;
public float ActiveTimer { get; private set; } = 0f;
public float CooldownTimer { get; private set; } = 0f;
public float ChargeCompletePercent { get => ChargeTimer / Settings.chargeTime; }
public float ActiveCompletePercent { get => (Settings.activeTime - ActiveTimer) / Settings.activeTime; }
public float CooldownCompletePercent { get => (Settings.cooldownTime - CooldownTimer) / Settings.cooldownTime; }

private bool activationQueued = false;

public Ability(AbilitySettings settings)
{
this.settings = settings;
Settings = settings;
}

/// <summary>
Expand All @@ -50,9 +51,9 @@ public Ability(AbilitySettings settings)
/// <param name="player"></param>
public void Initiate(PlayerController player)
{
if (state == AbilityState.IDLE)
if (State == AbilityState.IDLE)
{
state = AbilityState.CHARGING;
State = AbilityState.CHARGING;
OnInitiate(player);
}
}
Expand All @@ -64,12 +65,12 @@ public void Initiate(PlayerController player)
public void Activate(PlayerController player)
{
var isPlayerSpeedInRange = IsSpeedInRange(player.rigidbody.velocity.magnitude);
if (state == AbilityState.CHARGING && isPlayerSpeedInRange)
if (State == AbilityState.CHARGING && isPlayerSpeedInRange)
{
state = AbilityState.ACTIVE;
activeTimer = settings.activeTime;
State = AbilityState.ACTIVE;
ActiveTimer = Settings.activeTime;
OnActivate(player, ChargeCompletePercent);
chargeTimer = 0f;
ChargeTimer = 0f;
}
else if (!isPlayerSpeedInRange)
{
Expand All @@ -83,23 +84,23 @@ public void Activate(PlayerController player)
/// <param name="player"></param>
public void Deactivate(PlayerController player)
{
if (state == AbilityState.ACTIVE)
if (State == AbilityState.ACTIVE)
{
state = AbilityState.COOLDOWN;
cooldownTimer = settings.cooldownTime;
State = AbilityState.COOLDOWN;
CooldownTimer = Settings.cooldownTime;
OnDeactivate(player, ActiveCompletePercent);
activeTimer = 0f;
ActiveTimer = 0f;
}
}

public bool IsActivatable(float speed)
{
return state == AbilityState.IDLE && IsSpeedInRange(speed);
return State == AbilityState.IDLE && IsSpeedInRange(speed);
}

public bool IsSpeedInRange(float speed)
{
return speed >= settings.minMaxSpeed.x && speed <= settings.minMaxSpeed.y;
return speed >= Settings.minMaxSpeed.x && speed <= Settings.minMaxSpeed.y;
}

/// <summary>
Expand Down Expand Up @@ -151,7 +152,7 @@ public virtual void OnReady(PlayerController player) { }
/// <param name="player"></param>
public virtual void UpdateTimers(float deltaTime, PlayerController player)
{
switch (state)
switch (State)
{
case AbilityState.IDLE:
break;
Expand All @@ -161,9 +162,9 @@ public virtual void UpdateTimers(float deltaTime, PlayerController player)
Activate(player);
activationQueued = false;
}
if (chargeTimer < settings.chargeTime)
if (ChargeTimer < Settings.chargeTime)
{
chargeTimer = Mathf.Min(chargeTimer + deltaTime, settings.chargeTime);
ChargeTimer = Mathf.Min(ChargeTimer + deltaTime, Settings.chargeTime);
OnCharging(player, ChargeCompletePercent);
}
else
Expand All @@ -172,9 +173,9 @@ public virtual void UpdateTimers(float deltaTime, PlayerController player)
}
break;
case AbilityState.ACTIVE:
if (activeTimer > 0f)
if (ActiveTimer > 0f)
{
activeTimer = Mathf.Max(activeTimer - deltaTime, 0f);
ActiveTimer = Mathf.Max(ActiveTimer - deltaTime, 0f);
OnActive(player, ActiveCompletePercent);
}
else
Expand All @@ -183,15 +184,15 @@ public virtual void UpdateTimers(float deltaTime, PlayerController player)
}
break;
case AbilityState.COOLDOWN:
if (cooldownTimer > 0f)
if (CooldownTimer > 0f)
{
cooldownTimer = Mathf.Max(cooldownTimer - deltaTime, 0f);
CooldownTimer = Mathf.Max(CooldownTimer - deltaTime, 0f);
OnCooldown(player, CooldownCompletePercent);

}
else
{
state = AbilityState.IDLE;
State = AbilityState.IDLE;
OnReady(player);
}
break;
Expand Down Expand Up @@ -245,6 +246,7 @@ public class PlayerController : MonoBehaviour
{
[Header("Object References")]
public GameManager gameManager;
public InputManager inputManager;
public new Rigidbody2D rigidbody;
public Transform healthBar;
public SpriteRenderer healthRing;
Expand Down Expand Up @@ -273,7 +275,6 @@ public class PlayerController : MonoBehaviour
private float healthSmoothed = 100f;
// Used when adding/subtracting fractional values from health to store the non-integer part of the delta for later
private float healthFractionalBuffer = 0f;
private bool abilityKeyDown = false;

[HideInInspector]
public Vector2 velocityThisFrame = new Vector2();
Expand All @@ -294,11 +295,21 @@ public void Heal(float amount)
ChangeHealth(amount);
}

public void Revive()
{
Heal(100);
}

public void Damage(float amount)
{
ChangeHealth(-amount);
}

public void Kill()
{
Damage(100);
}

public void ChangeHealth(float delta, float healthMin = 0f, float healthMax = 100f)
{
if (health >= healthMin && health <= healthMax)
Expand Down Expand Up @@ -347,7 +358,7 @@ public void OnDie()
void Update()
{
UpdateUI();
if (Input.GetAxis($"P{playerNum} Ability") > 0f && !abilityKeyDown)
if (inputManager.GetKeyDown($"player_{playerNum}.ability"))
{
for (var i = 0; i < abilities.Length && activeAbility == null; i++)
{
Expand All @@ -358,34 +369,25 @@ void Update()
activeAbility = ability;
}
}
abilityKeyDown = true;
}
else if (Input.GetAxis($"P{playerNum} Ability") == 0f && abilityKeyDown)
else if (inputManager.GetKeyUp($"player_{playerNum}.ability"))
{
if (activeAbility != null)
{
activeAbility.Activate(this);
}
abilityKeyDown = false;
}
/*if (Input.GetAxis($"P{playerNum} Ability") > 0f && speed > attackMinMaxSpeed.x && speed < attackMinMaxSpeed.y && attackCooldownTimer == 0f)
{
rigidbody.AddForce(rigidbody.velocity.normalized * attackPower, ForceMode2D.Impulse);
attackCooldownTimer = attackCooldown;
// Play charge trail effect if it's not already playing
if (trailEffect.isStopped)
{
trailEffect.Play();
}
}*/
}

void FixedUpdate()
{
UpdateCooldowns();

// Update movement
var moveVector = new Vector2(Input.GetAxis($"P{playerNum} Horizontal"), Input.GetAxis($"P{playerNum} Vertical")).normalized;
var moveVector = new Vector2(
inputManager.GetAxisValue($"player_{playerNum}.move.horizontal"),
inputManager.GetAxisValue($"player_{playerNum}.move.vertical")
).normalized;
rigidbody.AddForce(moveVector * movePower);

// Update stored velocity
Expand Down Expand Up @@ -428,7 +430,7 @@ void OnCollisionEnter2D(Collision2D collision)
// Stop charge ability if it's active
if (activeAbility is AbilityAttack)
{
if (activeAbility.state == AbilityState.ACTIVE)
if (activeAbility.State == AbilityState.ACTIVE)
{
activeAbility.Deactivate(this);
}
Expand Down Expand Up @@ -464,7 +466,7 @@ private void UpdateUI()
{
if (ability.IsActivatable(rigidbody.velocity.magnitude) && activeAbility == null)
{
targetColor = ability.settings.color;
targetColor = ability.Settings.color;
}
}
var currentColor = powerRing.color;
Expand All @@ -483,7 +485,7 @@ private void UpdateCooldowns()
}
if (activeAbility != null)
{
if (activeAbility.state == AbilityState.COOLDOWN)
if (activeAbility.State == AbilityState.COOLDOWN)
{
activeAbility = null;
}
Expand Down
Loading

0 comments on commit 2d4a21d

Please sign in to comment.