Final touches

This commit is contained in:
2025-09-22 14:15:16 +02:00
parent 46950aa877
commit ec1a0e70aa

View File

@@ -293,13 +293,13 @@ namespace Minigames.DivingForPictures
if (isGameOver) return;
isGameOver = true;
Debug.Log("[DivingGameManager] Game Over! All ropes broken.");
Debug.Log("[DivingGameManager] Game Over! All ropes broken. Starting surfacing sequence...");
// Fire game over event
OnGameOver?.Invoke();
// Call the existing end game method
EndGame();
// Start surfacing instead of directly ending the game
StartSurfacing();
}
/// <summary>
@@ -378,6 +378,50 @@ namespace Minigames.DivingForPictures
tileSpawner.OnVelocityFactorChanged(_currentVelocityFactor);
}
// Handle the Rock object - disable components and animate it falling offscreen
GameObject rockObject = GameObject.FindGameObjectWithTag("Rock");
if (rockObject != null)
{
// Disable all components except Transform on the rock object (not its children)
foreach (Component component in rockObject.GetComponents<Component>())
{
if (!(component is Transform))
{
if (component is Behaviour behaviour)
{
behaviour.enabled = false;
}
}
}
// Start coroutine to animate the rock falling offscreen
StartCoroutine(MoveRockOffscreen(rockObject.transform));
Debug.Log("[DivingGameManager] Disabled rock components and animating it offscreen");
}
// Handle the Player object - disable components and reset X position
GameObject playerObject = GameObject.FindGameObjectWithTag("Player");
if (playerObject != null)
{
// Disable all components except Transform and Animator on the player object (not its children)
foreach (Component component in playerObject.GetComponents<Component>())
{
if (!(component is Transform) && !(component is Animator))
{
if (component is Behaviour behaviour)
{
behaviour.enabled = false;
}
}
}
// Start coroutine to reset X position to 0 over 1 second
StartCoroutine(ResetPlayerPosition(playerObject.transform));
Debug.Log("[DivingGameManager] Disabled player components (keeping Animator) and resetting position");
}
// 3. Find bubble spawner and slow down existing bubbles (no velocity management needed)
BubbleSpawner bubbleSpawner = FindFirstObjectByType<BubbleSpawner>();
if (bubbleSpawner != null)
@@ -410,6 +454,71 @@ namespace Minigames.DivingForPictures
Debug.Log($"[DivingGameManager] Started surfacing with target velocity factor: {targetVelocityFactor}");
}
/// <summary>
/// Coroutine to animate the rock falling below the screen
/// </summary>
private IEnumerator MoveRockOffscreen(Transform rockTransform)
{
Vector3 startPosition = rockTransform.position;
// Calculate position below the screen
Camera mainCamera = Camera.main;
if (mainCamera == null)
{
Debug.LogWarning("[DivingGameManager] Cannot find main camera to calculate offscreen position");
yield break;
}
// Get a position below the bottom of the screen
Vector3 offscreenPosition = mainCamera.ViewportToWorldPoint(new Vector3(0.5f, -0.2f, mainCamera.nearClipPlane));
Vector3 targetPosition = new Vector3(startPosition.x, offscreenPosition.y, startPosition.z);
float duration = 2.0f; // Animation duration in seconds
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = Mathf.Clamp01(elapsed / duration);
// Use an easing function that accelerates to simulate falling
float easedT = t * t; // Quadratic easing
rockTransform.position = Vector3.Lerp(startPosition, targetPosition, easedT);
yield return null;
}
// Ensure final position is exactly at target
rockTransform.position = targetPosition;
}
/// <summary>
/// Coroutine to reset the player's X position to 0 over time
/// </summary>
private IEnumerator ResetPlayerPosition(Transform playerTransform)
{
Vector3 startPosition = playerTransform.position;
Vector3 targetPosition = new Vector3(0f, startPosition.y, startPosition.z);
float duration = 1.0f; // Reset duration in seconds (as requested)
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = Mathf.Clamp01(elapsed / duration);
// Use smooth step for more natural movement
float smoothT = Mathf.SmoothStep(0f, 1f, t);
playerTransform.position = Vector3.Lerp(startPosition, targetPosition, smoothT);
yield return null;
}
// Ensure final position is exactly at target
playerTransform.position = targetPosition;
}
/// <summary>
/// Coroutine to handle the surfacing sequence timing
/// </summary>