Working MVP

This commit is contained in:
Michal Pikulski
2025-12-03 22:17:12 +01:00
parent d5ab69d944
commit 0b8d2a279f
58 changed files with 11037 additions and 1299 deletions

View File

@@ -1,40 +1,59 @@
using System.Collections;
using Core;
using Core;
using UnityEngine;
namespace Minigames.FortFight.Projectiles
{
/// <summary>
/// Vacuum projectile - high mass, slides along ground after landing.
/// On ground impact: disables gravity, moves horizontally for 2 seconds.
/// On floor/block impact: applies constant force to the right and destroys blocks.
/// </summary>
public class VacuumProjectile : ProjectileBase
{
[Header("Vacuum Specific")]
[Tooltip("Speed when sliding on ground")]
[SerializeField] private float slideSpeed = 10f;
[Tooltip("How long to slide before destroying")]
[SerializeField] private float slideDuration = 2f;
[Tooltip("Layer mask for ground detection")]
[SerializeField] private LayerMask groundLayer = 1; // Default layer
private bool isSliding = false;
private int blocksDestroyed = 0;
private int maxBlocksToDestroy = 3;
private Vector2 slideDirection;
protected override void OnHit(Collider2D hit)
protected override void OnHit(Collision2D collision)
{
// Check if hit ground
if (((1 << hit.gameObject.layer) & groundLayer) != 0)
// If already sliding, count block destruction
if (isSliding)
{
Logging.Debug("[VacuumProjectile] Hit ground - starting slide");
StartSliding();
var block = collision.gameObject.GetComponent<Fort.FortBlock>();
if (block != null)
{
// Spawn impact effect on each block hit
SpawnImpactEffect(collision.contacts[0].point);
// Get damage from settings
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
float blockDamage = settings?.VacuumBlockDamage ?? 999f;
// Deal high damage to destroy block instantly
block.TakeDamage(blockDamage);
blocksDestroyed++;
Logging.Debug($"[VacuumProjectile] Destroyed block {blocksDestroyed}/{maxBlocksToDestroy}");
if (blocksDestroyed >= maxBlocksToDestroy)
{
Logging.Debug("[VacuumProjectile] Destroyed max blocks - stopping");
DestroyProjectile();
}
}
// Don't destroy - keep sliding
return;
}
// If hit wall or fort block, destroy immediately (handled by base class)
// First hit - spawn impact effect and start sliding
SpawnImpactEffect(collision.contacts[0].point);
Logging.Debug("[VacuumProjectile] Hit surface - starting slide");
StartSliding();
// Don't destroy - keep sliding!
}
/// <summary>
/// Start sliding behavior after hitting ground
/// Start sliding behavior after hitting surface
/// </summary>
private void StartSliding()
{
@@ -42,40 +61,44 @@ namespace Minigames.FortFight.Projectiles
isSliding = true;
// Disable gravity
if (rb2D != null)
// Get settings
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
if (settings != null)
{
rb2D.gravityScale = 0f;
// Set velocity to horizontal only (preserve direction)
Vector2 horizontalVelocity = new Vector2(rb2D.linearVelocity.x, 0f).normalized * slideSpeed;
rb2D.linearVelocity = horizontalVelocity;
Logging.Debug($"[VacuumProjectile] Sliding with velocity: {horizontalVelocity}");
maxBlocksToDestroy = settings.VacuumDestroyBlockCount;
}
// Destroy after slide duration
StartCoroutine(SlideCoroutine());
// Determine slide direction based on horizontal velocity (preserve launch direction)
if (rb2D != null)
{
slideDirection = rb2D.linearVelocity.x >= 0 ? Vector2.right : Vector2.left;
rb2D.gravityScale = 0f;
rb2D.linearVelocity = Vector2.zero; // Stop all momentum
Logging.Debug($"[VacuumProjectile] Started sliding in direction: {slideDirection}");
}
}
private IEnumerator SlideCoroutine()
private void FixedUpdate()
{
yield return new WaitForSeconds(slideDuration);
Logging.Debug("[VacuumProjectile] Slide duration ended - destroying");
DestroyProjectile();
if (isSliding && rb2D != null)
{
// Set constant velocity in slide direction
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IFortFightSettings>();
float slideSpeed = settings?.VacuumSlideSpeed ?? 10f;
rb2D.linearVelocity = slideDirection * slideSpeed;
}
}
/// <summary>
/// Override to NOT destroy immediately on ground hit
/// Clean up when destroyed
/// </summary>
protected override void DestroyProjectile()
{
// Only destroy if we're done sliding or hit a wall
if (!isSliding || rb2D.linearVelocity.magnitude < 1f)
{
base.DestroyProjectile();
}
isSliding = false;
base.DestroyProjectile();
}
}
}