Add Golden Berry

This commit is contained in:
2026-02-11 13:08:56 -07:00
parent 14f665b917
commit 1912822e63
7 changed files with 693 additions and 30 deletions

View File

@@ -22,12 +22,14 @@ public class GamePlayer : MonoBehaviour
private BigInteger totalCoinBerries;
private BigInteger totalRandomBerries;
private BigInteger totalAntiBerries;
private BigInteger totalGoldenBerries;
private BigInteger totalAttempts;
private BigInteger totalCoins;
private float boostLeft;
private float slownessLeft;
private float speedyLeft;
private float antiLeft;
private float goldenLeft;
private float screenWidth;
internal bool isGrounded;
[SerializeField] private TMP_Text scoreText;
@@ -138,6 +140,7 @@ public class GamePlayer : MonoBehaviour
totalCoinBerries = BazookaManager.Instance.GetGameStoreTotalCoinBerries();
totalRandomBerries = BazookaManager.Instance.GetGameStoreTotalRandomBerries();
totalAntiBerries = BazookaManager.Instance.GetGameStoreTotalAntiBerries();
totalGoldenBerries = BazookaManager.Instance.GetGameStoreTotalGoldenBerries();
totalAttempts = BazookaManager.Instance.GetGameStoreTotalAttepts();
totalCoins = BazookaManager.Instance.GetCustomBirdIconData().Balance;
@@ -244,17 +247,18 @@ public class GamePlayer : MonoBehaviour
{
if (score != 0) Respawn();
}
if (antiLeft > 0f)
if (antiLeft > 0f || goldenLeft > 0f)
{
string[] berryTags = { "NormalBerry", "PoisonBerry", "SlowBerry", "UltraBerry", "SpeedyBerry", "CoinBerry", "RandomBerry", "AntiBerry" };
string[] berryTags = { "NormalBerry", "SlowBerry", "UltraBerry", "SpeedyBerry", "CoinBerry", "RandomBerry", "AntiBerry", "GoldenBerry" };
if (antiLeft > 0f) berryTags.Append("PoisonBerry");
foreach (string tag in berryTags)
{
foreach (var berry in GameObject.FindGameObjectsWithTag(tag))
{
UnityEngine.Vector3 dir = berry.transform.position - bird.transform.position;
if (dir.magnitude < 3f)
if (dir.magnitude < (antiLeft > 0 ? 3f : 4.5f))
{
berry.GetComponent<Rigidbody2D>().linearVelocity = dir.normalized * 5f;
berry.GetComponent<Rigidbody2D>().linearVelocity = dir.normalized * (antiLeft > 0 ? 5f : -5f);
ClampPosition(berry, false);
}
}
@@ -305,6 +309,11 @@ public class GamePlayer : MonoBehaviour
antiLeft -= Time.deltaTime;
boostText.text = "Berry repellent expires in " + string.Format("{0:0.0}", antiLeft) + "s";
}
else if (goldenLeft > 0f)
{
goldenLeft -= Time.deltaTime;
boostText.text = "Berry magnet expires in " + string.Format("{0:0.0}", goldenLeft) + "s";
}
else
{
boostText.text = "";
@@ -332,48 +341,53 @@ public class GamePlayer : MonoBehaviour
GameObject newBerry = new("Berry");
newBerry.transform.SetParent(berryParent.transform);
SpriteRenderer spriteRenderer = newBerry.AddComponent<SpriteRenderer>();
if (spawnProbability <= 0.425f)
if (spawnProbability <= 0.375f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/Berry");
newBerry.tag = "NormalBerry";
}
else if (spawnProbability <= 0.55f)
else if (spawnProbability <= 0.550)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/PoisonBerry");
newBerry.tag = "PoisonBerry";
}
else if (spawnProbability <= 0.65f)
else if (spawnProbability <= 0.60f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SlowBerry");
newBerry.tag = "SlowBerry";
}
else if (spawnProbability <= 0.75f)
else if (spawnProbability <= 0.70f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/UltraBerry");
newBerry.tag = "UltraBerry";
}
else if (spawnProbability <= 0.85f)
else if (spawnProbability <= 0.80f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/SpeedyBerry");
newBerry.tag = "SpeedyBerry";
}
else if (spawnProbability <= 0.90f)
else if (spawnProbability <= 0.85f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/CoinBerry");
newBerry.tag = "CoinBerry";
}
else if (spawnProbability <= 0.95f)
else if (spawnProbability <= 0.90f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/BerryNoColor");
newBerry.tag = "RandomBerry";
RainbowSpriteRender randomBerryRainbowImage = newBerry.AddComponent<RainbowSpriteRender>();
randomBerryRainbowImage.frequency = 5f;
}
else
else if (spawnProbability <= 0.95f)
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/AntiBerry");
newBerry.tag = "AntiBerry";
}
else
{
spriteRenderer.sprite = Resources.Load<Sprite>("Berries/GoldenBerry");
newBerry.tag = "GoldenBerry";
}
spriteRenderer.sortingOrder = -5;
float screenWidth = Camera.main.orthographicSize * 2 * Camera.main.aspect;
@@ -404,6 +418,7 @@ public class GamePlayer : MonoBehaviour
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
foreach (GameObject berry in allberries)
{
@@ -418,6 +433,7 @@ public class GamePlayer : MonoBehaviour
GameObject[] coinBerries = GameObject.FindGameObjectsWithTag("CoinBerry");
GameObject[] randomBerries = GameObject.FindGameObjectsWithTag("RandomBerry");
GameObject[] antiBerries = GameObject.FindGameObjectsWithTag("AntiBerry");
GameObject[] goldenBerries = GameObject.FindGameObjectsWithTag("GoldenBerry");
if (!pausePanel.activeSelf)
{
@@ -556,12 +572,13 @@ public class GamePlayer : MonoBehaviour
else if (UnityEngine.Vector3.Distance(bird.transform.position, randomBerry.transform.position) < 1.5f)
{
totalRandomBerries++;
System.Action[] funcs = {
Action[] funcs = {
() => DoNormalBerry(randomBerry),
() => DoSlowBerry(randomBerry),
() => DoUltraBerry(randomBerry),
() => DoSpeedyBerry(randomBerry),
() => DoAntiBerry(randomBerry)
() => DoAntiBerry(randomBerry),
() => DoGoldenBerry(randomBerry)
};
funcs[UnityEngine.Random.Range(0, funcs.Length)]();
}
@@ -594,6 +611,26 @@ public class GamePlayer : MonoBehaviour
antiBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
}
}
foreach (GameObject goldenBerry in goldenBerries)
{
if (goldenBerry.transform.position.y < 0f - Camera.main.orthographicSize - 1f)
{
Destroy(goldenBerry);
}
else if (UnityEngine.Vector3.Distance(bird.transform.position, goldenBerry.transform.position) < 1.5f)
{
totalGoldenBerries++;
DoGoldenBerry(goldenBerry);
}
if (speedyLeft > 0)
{
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -7.5f);
}
else
{
goldenBerry.GetComponent<Rigidbody2D>().linearVelocity = new UnityEngine.Vector2(0f, -4f);
}
}
}
else
{
@@ -607,6 +644,7 @@ public class GamePlayer : MonoBehaviour
.Concat(coinBerries)
.Concat(randomBerries)
.Concat(antiBerries)
.Concat(goldenBerries)
.ToArray();
foreach (GameObject berry in allberries)
{
@@ -637,6 +675,7 @@ public class GamePlayer : MonoBehaviour
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
foreach (GameObject berry in allberries)
{
@@ -667,6 +706,7 @@ public class GamePlayer : MonoBehaviour
BazookaManager.Instance.SetGameStoreTotalCoinBerries(totalCoinBerries);
BazookaManager.Instance.SetGameStoreTotalRandomBerries(totalRandomBerries);
BazookaManager.Instance.SetGameStoreTotalAntiBerries(totalAntiBerries);
BazookaManager.Instance.SetGameStoreTotalGoldenBerries(totalGoldenBerries);
BazookaManager.Instance.SetGameStoreTotalAttepts(totalAttempts);
var customBirdIconData = BazookaManager.Instance.GetCustomBirdIconData();
customBirdIconData.Balance = totalCoins;
@@ -763,6 +803,7 @@ public class GamePlayer : MonoBehaviour
slownessLeft = 10f;
speedyLeft = 0f;
antiLeft = 0f;
goldenLeft = 0f;
if (score > 0)
{
UpdateStats(-1, 0);
@@ -775,6 +816,7 @@ public class GamePlayer : MonoBehaviour
Destroy(berry);
speedyLeft = 0f;
antiLeft = 0f;
goldenLeft = 0f;
if (slownessLeft > 0f)
{
slownessLeft = 0f;
@@ -795,6 +837,7 @@ public class GamePlayer : MonoBehaviour
slownessLeft = 0f;
speedyLeft = 10f;
antiLeft = 0f;
goldenLeft = 0f;
UpdateStats(10, 0);
}
@@ -814,6 +857,19 @@ public class GamePlayer : MonoBehaviour
slownessLeft = 0f;
speedyLeft = 0f;
antiLeft = 10f;
goldenLeft = 0f;
UpdateStats(0, 0);
}
void DoGoldenBerry(GameObject berry)
{
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Powerup"), Camera.main.transform.position, 0.35f * BazookaManager.Instance.GetSettingSFXVolume());
Destroy(berry);
boostLeft = 0f;
slownessLeft = 0f;
speedyLeft = 0f;
antiLeft = 0f;
goldenLeft = 10f;
UpdateStats(0, 0);
}
}