ADd booster pack reward sequence to bird pooper

This commit is contained in:
Michal Pikulski
2025-12-19 16:41:05 +01:00
parent 2483603803
commit f19f87ce95
4 changed files with 103 additions and 14 deletions

View File

@@ -186,7 +186,7 @@ namespace Minigames.BirdPooper
/// <summary>
/// Called when player takes damage/dies.
/// Shows game over screen.
/// Pauses all game entities and starts end game sequence.
/// </summary>
private void HandlePlayerDamaged()
{
@@ -210,7 +210,65 @@ namespace Minigames.BirdPooper
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)
{
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>
/// Spawns a poop projectile at the player's current position.
/// Called by UI button OnClick event.