MVP of the plane throwing game (#77)
Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #77
This commit is contained in:
104
Assets/Scripts/Minigames/Airplane/Abilities/JetAbility.cs
Normal file
104
Assets/Scripts/Minigames/Airplane/Abilities/JetAbility.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.Airplane.Abilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Jet Plane Ability: Hold to fly straight without gravity.
|
||||
/// Sustained ability - active while button held, deactivates on release.
|
||||
/// </summary>
|
||||
public class JetAbility : BaseAirplaneAbility
|
||||
{
|
||||
#region Configuration
|
||||
|
||||
private readonly float jetSpeed;
|
||||
private readonly float jetAngle;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Create jet ability with configuration from settings.
|
||||
/// </summary>
|
||||
public JetAbility(string name, Sprite icon, float cooldown, float speed, float angle)
|
||||
: base(name, icon, cooldown)
|
||||
{
|
||||
jetSpeed = speed;
|
||||
jetAngle = angle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region State
|
||||
|
||||
private float originalGravityScale;
|
||||
private bool originalRotateToVelocity;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override Methods
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
if (!ValidateAirplane()) return;
|
||||
if (!CanActivate) return;
|
||||
|
||||
StartActivation();
|
||||
|
||||
// Store original physics values
|
||||
var rb = currentAirplane.GetComponent<Rigidbody2D>();
|
||||
if (rb != null)
|
||||
{
|
||||
originalGravityScale = rb.gravityScale;
|
||||
|
||||
// Disable gravity
|
||||
rb.gravityScale = 0f;
|
||||
|
||||
// Set constant velocity in forward direction
|
||||
Vector2 direction = Quaternion.Euler(0, 0, jetAngle) * Vector2.right;
|
||||
rb.linearVelocity = direction.normalized * jetSpeed;
|
||||
}
|
||||
|
||||
// Disable rotation to velocity (maintain straight angle)
|
||||
originalRotateToVelocity = currentAirplane.RotateToVelocity;
|
||||
currentAirplane.RotateToVelocity = false;
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug($"[JetAbility] Activated - Speed: {jetSpeed}, Angle: {jetAngle}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
// Restore original physics
|
||||
if (currentAirplane != null)
|
||||
{
|
||||
var rb = currentAirplane.GetComponent<Rigidbody2D>();
|
||||
if (rb != null)
|
||||
{
|
||||
rb.gravityScale = originalGravityScale;
|
||||
}
|
||||
|
||||
// Restore rotation behavior
|
||||
currentAirplane.RotateToVelocity = originalRotateToVelocity;
|
||||
}
|
||||
|
||||
base.Deactivate();
|
||||
|
||||
// Start cooldown after deactivation
|
||||
StartCooldown();
|
||||
|
||||
if (showDebugLogs)
|
||||
{
|
||||
Logging.Debug("[JetAbility] Deactivated, cooldown started");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user