ADd booster pack reward sequence to bird pooper
This commit is contained in:
@@ -1691,7 +1691,7 @@ GameObject:
|
|||||||
- component: {fileID: 1536057437}
|
- component: {fileID: 1536057437}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: MainCanvas
|
m_Name: MainCanvas
|
||||||
m_TagString: Untagged
|
m_TagString: MainCanvas
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace Minigames.BirdPooper
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when player takes damage/dies.
|
/// Called when player takes damage/dies.
|
||||||
/// Shows game over screen.
|
/// Pauses all game entities and starts end game sequence.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void HandlePlayerDamaged()
|
private void HandlePlayerDamaged()
|
||||||
{
|
{
|
||||||
@@ -210,7 +210,65 @@ namespace Minigames.BirdPooper
|
|||||||
targetSpawner.StopSpawning();
|
targetSpawner.StopSpawning();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show game over screen
|
// Pause all existing scrolling entities (obstacles and targets)
|
||||||
|
PauseAllScrollingEntities();
|
||||||
|
|
||||||
|
// Start the end game sequence (show boosters, then game over screen)
|
||||||
|
StartCoroutine(EndGameSequence());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pause all existing scrolling entities in the scene.
|
||||||
|
/// </summary>
|
||||||
|
private void PauseAllScrollingEntities()
|
||||||
|
{
|
||||||
|
ScrollingEntity[] entities = FindObjectsByType<ScrollingEntity>(FindObjectsSortMode.None);
|
||||||
|
foreach (ScrollingEntity entity in entities)
|
||||||
|
{
|
||||||
|
entity.Pause();
|
||||||
|
}
|
||||||
|
Debug.Log($"[BirdPooperGameManager] Paused {entities.Length} scrolling entities");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// End game sequence: award boosters, wait for completion, then show game over screen.
|
||||||
|
/// </summary>
|
||||||
|
private System.Collections.IEnumerator EndGameSequence()
|
||||||
|
{
|
||||||
|
// Calculate booster reward
|
||||||
|
int boosterReward = CalculateBoosterReward(_targetsHit);
|
||||||
|
|
||||||
|
Debug.Log($"[BirdPooperGameManager] Targets hit: {_targetsHit}, awarding {boosterReward} booster pack(s)");
|
||||||
|
|
||||||
|
// Show booster pack reward UI and wait for completion
|
||||||
|
if (boosterReward > 0)
|
||||||
|
{
|
||||||
|
Debug.Log("[BirdPooperGameManager] Starting booster giver sequence via GameManager");
|
||||||
|
|
||||||
|
var task = Core.GameManager.Instance.GiveBoosterPacksAsync(boosterReward);
|
||||||
|
|
||||||
|
// Wait for the task to complete
|
||||||
|
while (!task.IsCompleted)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for exceptions
|
||||||
|
if (task.IsFaulted)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"[BirdPooperGameManager] Booster pack reward failed: {task.Exception?.GetBaseException().Message}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("[BirdPooperGameManager] Booster giver sequence finished, proceeding to game over screen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("[BirdPooperGameManager] No boosters to award, proceeding directly to game over screen");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now show game over screen
|
||||||
if (gameOverScreen != null)
|
if (gameOverScreen != null)
|
||||||
{
|
{
|
||||||
gameOverScreen.Show();
|
gameOverScreen.Show();
|
||||||
@@ -221,6 +279,23 @@ namespace Minigames.BirdPooper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate booster pack reward based on targets hit.
|
||||||
|
/// Rules:
|
||||||
|
/// - First booster pack is given for simply playing the game (participation reward)
|
||||||
|
/// - Every 3 hit targets gives 1 additional booster pack
|
||||||
|
/// </summary>
|
||||||
|
private int CalculateBoosterReward(int targetsHit)
|
||||||
|
{
|
||||||
|
// Base reward: 1 booster for participation
|
||||||
|
int reward = 1;
|
||||||
|
|
||||||
|
// Additional reward: 1 booster per 3 targets hit
|
||||||
|
reward += targetsHit / 3;
|
||||||
|
|
||||||
|
return reward;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Spawns a poop projectile at the player's current position.
|
/// Spawns a poop projectile at the player's current position.
|
||||||
/// Called by UI button OnClick event.
|
/// Called by UI button OnClick event.
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Core;
|
using Core;
|
||||||
using UI;
|
|
||||||
|
|
||||||
namespace Minigames.BirdPooper
|
namespace Minigames.BirdPooper
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Game over screen for Bird Pooper minigame.
|
/// Game over screen for Bird Pooper minigame.
|
||||||
/// Displays when the player dies and allows restarting the level.
|
/// Displays when the player dies and allows restarting the level.
|
||||||
/// Uses unscaled time for UI updates (works when Time.timeScale = 0).
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GameOverScreen : MonoBehaviour
|
public class GameOverScreen : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -53,7 +51,7 @@ namespace Minigames.BirdPooper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show the game over screen and pause the game.
|
/// Show the game over screen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Show()
|
public void Show()
|
||||||
{
|
{
|
||||||
@@ -67,11 +65,7 @@ namespace Minigames.BirdPooper
|
|||||||
canvasGroup.blocksRaycasts = true;
|
canvasGroup.blocksRaycasts = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause the game (set timescale to 0)
|
Debug.Log("[GameOverScreen] Game Over screen shown");
|
||||||
// PauseMenu uses unscaled time for tweens, so it will still work
|
|
||||||
Time.timeScale = 0f;
|
|
||||||
|
|
||||||
Debug.Log("[GameOverScreen] Game Over - Time.timeScale set to 0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -89,8 +83,6 @@ namespace Minigames.BirdPooper
|
|||||||
}
|
}
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
|
|
||||||
// Reset time scale BEFORE reloading
|
|
||||||
Time.timeScale = 1f;
|
|
||||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||||
await SceneManagerService.Instance.ReloadCurrentScene(progress);
|
await SceneManagerService.Instance.ReloadCurrentScene(progress);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace Minigames.BirdPooper
|
|||||||
protected IBirdPooperSettings settings;
|
protected IBirdPooperSettings settings;
|
||||||
protected float despawnXPosition;
|
protected float despawnXPosition;
|
||||||
protected bool isInitialized;
|
protected bool isInitialized;
|
||||||
|
protected bool isPaused;
|
||||||
protected EdgeAnchor edgeAnchor;
|
protected EdgeAnchor edgeAnchor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -191,12 +192,33 @@ namespace Minigames.BirdPooper
|
|||||||
|
|
||||||
protected virtual void Update()
|
protected virtual void Update()
|
||||||
{
|
{
|
||||||
if (!isInitialized || settings == null) return;
|
if (!isInitialized || settings == null || isPaused) return;
|
||||||
|
|
||||||
MoveLeft();
|
MoveLeft();
|
||||||
CheckBounds();
|
CheckBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pause the scrolling movement of this entity.
|
||||||
|
/// </summary>
|
||||||
|
public void Pause()
|
||||||
|
{
|
||||||
|
isPaused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resume the scrolling movement of this entity.
|
||||||
|
/// </summary>
|
||||||
|
public void Resume()
|
||||||
|
{
|
||||||
|
isPaused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if this entity is currently paused.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPaused => isPaused;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Move entity left at constant speed (manual movement, no physics).
|
/// Move entity left at constant speed (manual movement, no physics).
|
||||||
/// Override GetMoveSpeed() to customize speed per entity type.
|
/// Override GetMoveSpeed() to customize speed per entity type.
|
||||||
|
|||||||
Reference in New Issue
Block a user