Working MVP
This commit is contained in:
@@ -5,17 +5,59 @@ using UnityEngine;
|
||||
namespace Minigames.FortFight.Projectiles
|
||||
{
|
||||
/// <summary>
|
||||
/// Ceiling Fan projectile - drops straight down when ability is activated.
|
||||
/// Player taps screen mid-flight to activate drop.
|
||||
/// Ceiling Fan projectile - drops straight down when player taps screen.
|
||||
/// Implements ITouchInputConsumer to capture tap input mid-flight.
|
||||
/// </summary>
|
||||
public class CeilingFanProjectile : ProjectileBase
|
||||
public class CeilingFanProjectile : ProjectileBase, ITouchInputConsumer
|
||||
{
|
||||
[Header("Ceiling Fan Specific")]
|
||||
[Tooltip("Speed of downward drop")]
|
||||
[SerializeField] private float dropSpeed = 20f;
|
||||
[Tooltip("Visual indicator showing drop is available (arrow down)")]
|
||||
[SerializeField] private GameObject indicator;
|
||||
|
||||
[Tooltip("Delay before dropping")]
|
||||
[SerializeField] private float dropDelay = 0.2f;
|
||||
private bool isDropping = false;
|
||||
private bool inputEnabled = false;
|
||||
|
||||
public override void Launch(Vector2 direction, float force)
|
||||
{
|
||||
base.Launch(direction, force);
|
||||
|
||||
// Hide indicator initially
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(false);
|
||||
}
|
||||
|
||||
// Start activation delay coroutine
|
||||
StartCoroutine(ActivationDelayCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator ActivationDelayCoroutine()
|
||||
{
|
||||
// Get activation delay from settings
|
||||
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
|
||||
float activationDelay = settings?.CeilingFanActivationDelay ?? 0.5f;
|
||||
|
||||
// Wait for delay
|
||||
yield return new WaitForSeconds(activationDelay);
|
||||
|
||||
// Enable input and show indicator (if not already dropped)
|
||||
if (!isDropping && !AbilityActivated)
|
||||
{
|
||||
inputEnabled = true;
|
||||
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(true);
|
||||
}
|
||||
|
||||
// Register with InputManager to capture tap-to-drop
|
||||
if (Input.InputManager.Instance != null)
|
||||
{
|
||||
Input.InputManager.Instance.RegisterOverrideConsumer(this);
|
||||
Logging.Debug("[CeilingFanProjectile] Tap-to-drop now available");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void ActivateAbility()
|
||||
{
|
||||
@@ -30,6 +72,8 @@ namespace Minigames.FortFight.Projectiles
|
||||
|
||||
private IEnumerator DropCoroutine()
|
||||
{
|
||||
isDropping = true;
|
||||
|
||||
// Stop all velocity
|
||||
if (rb2D != null)
|
||||
{
|
||||
@@ -37,6 +81,11 @@ namespace Minigames.FortFight.Projectiles
|
||||
rb2D.angularVelocity = 0f;
|
||||
}
|
||||
|
||||
// Get drop configuration from settings
|
||||
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
|
||||
float dropDelay = settings?.CeilingFanDropDelay ?? 0.2f;
|
||||
float dropSpeed = settings?.CeilingFanDropSpeed ?? 20f;
|
||||
|
||||
// Wait brief moment
|
||||
yield return new WaitForSeconds(dropDelay);
|
||||
|
||||
@@ -47,6 +96,88 @@ namespace Minigames.FortFight.Projectiles
|
||||
Logging.Debug($"[CeilingFanProjectile] Dropping with velocity: {rb2D.linearVelocity}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHit(Collision2D collision)
|
||||
{
|
||||
// Spawn impact effect only if dropped (not on normal arc hit)
|
||||
if (isDropping)
|
||||
{
|
||||
SpawnImpactEffect(collision.contacts[0].point);
|
||||
}
|
||||
|
||||
// Deal damage to blocks
|
||||
var block = collision.gameObject.GetComponent<Fort.FortBlock>();
|
||||
if (block != null)
|
||||
{
|
||||
block.TakeDamage(Damage);
|
||||
Logging.Debug($"[CeilingFanProjectile] Dealt {Damage} damage to {block.gameObject.name}");
|
||||
}
|
||||
|
||||
// Destroy projectile
|
||||
DestroyProjectile();
|
||||
}
|
||||
|
||||
#region ITouchInputConsumer Implementation
|
||||
|
||||
public void OnTap(Vector2 worldPosition)
|
||||
{
|
||||
// Only respond if input is enabled
|
||||
if (inputEnabled && !AbilityActivated && !isDropping)
|
||||
{
|
||||
Logging.Debug("[CeilingFanProjectile] Tap detected - activating drop");
|
||||
|
||||
// Hide indicator
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(false);
|
||||
}
|
||||
|
||||
ActivateAbility();
|
||||
|
||||
// Unregister immediately after tap
|
||||
UnregisterFromInput();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnHoldStart(Vector2 worldPosition)
|
||||
{
|
||||
// Not used for ceiling fan
|
||||
}
|
||||
|
||||
public void OnHoldMove(Vector2 worldPosition)
|
||||
{
|
||||
// Not used for ceiling fan
|
||||
}
|
||||
|
||||
public void OnHoldEnd(Vector2 worldPosition)
|
||||
{
|
||||
// Not used for ceiling fan
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void UnregisterFromInput()
|
||||
{
|
||||
inputEnabled = false;
|
||||
|
||||
if (indicator != null)
|
||||
{
|
||||
indicator.SetActive(false);
|
||||
}
|
||||
|
||||
if (Input.InputManager.Instance != null)
|
||||
{
|
||||
Input.InputManager.Instance.UnregisterOverrideConsumer(this);
|
||||
Logging.Debug("[CeilingFanProjectile] Unregistered from input");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DestroyProjectile()
|
||||
{
|
||||
// Make sure we unregister when destroyed
|
||||
UnregisterFromInput();
|
||||
base.DestroyProjectile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user