Add attempts and total attempts

This commit is contained in:
2025-06-10 19:23:05 -07:00
parent 4d5e653572
commit b8efbe7e88
2 changed files with 26 additions and 19 deletions

View File

@@ -634,7 +634,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 290}
m_SizeDelta: {x: 1280, y: 50}
m_SizeDelta: {x: 1280, y: 90}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &432923591
MonoBehaviour:
@@ -656,7 +656,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'Score: 0'
m_text: 'Score: 0 \u2022 Attempts: 0'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 4fd546dd0900395408d2de20f5025882, type: 2}
m_sharedMaterial: {fileID: -1476194838487357290, guid: 4fd546dd0900395408d2de20f5025882, type: 2}
@@ -686,7 +686,7 @@ MonoBehaviour:
m_fontSize: 72
m_fontSizeBase: 72
m_fontWeight: 400
m_enableAutoSizing: 0
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
@@ -1258,6 +1258,7 @@ MonoBehaviour:
jumpArrow: {fileID: 0}
restartButton: {fileID: 0}
backButton: {fileID: 0}
lastMoveTime: 0
--- !u!1 &527090675
GameObject:
m_ObjectHideFlags: 0
@@ -2638,7 +2639,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 219.99997}
m_SizeDelta: {x: 1280, y: 50}
m_SizeDelta: {x: 1280, y: 45}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1606868532
MonoBehaviour:
@@ -2660,7 +2661,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'High Score: 0'
m_text: 'High Score: 0 \u2022 Total Attempts: 0'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 4fd546dd0900395408d2de20f5025882, type: 2}
m_sharedMaterial: {fileID: -1476194838487357290, guid: 4fd546dd0900395408d2de20f5025882, type: 2}
@@ -2690,9 +2691,9 @@ MonoBehaviour:
m_fontSize: 36
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 0
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontSizeMax: 36
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512

View File

@@ -9,12 +9,14 @@ public class GamePlayer : MonoBehaviour
private readonly float spawnRate = 1f;
private float nextSpawnTime;
private BigInteger score;
private BigInteger attempts;
private BigInteger highscore;
private BigInteger totalNormalBerries;
private BigInteger totalPoisonBerries;
private BigInteger totalSlowBerries;
private BigInteger totalUltraBerries;
private BigInteger totalSpeedyBerries;
private BigInteger totalAttempts;
private float boostLeft;
private float slownessLeft;
private float speedyLeft;
@@ -49,6 +51,7 @@ public class GamePlayer : MonoBehaviour
totalSlowBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalSlowBerries", "0"));
totalUltraBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalUltraBerries", "0"));
totalSpeedyBerries = BigInteger.Parse(PlayerPrefs.GetString("TotalSpeedyBerries", "0"));
totalAttempts = BigInteger.Parse(PlayerPrefs.GetString("TotalAttempts", "0"));
}
void Start()
@@ -144,7 +147,7 @@ public class GamePlayer : MonoBehaviour
restartButton.transform.localScale = new UnityEngine.Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
backButton.transform.localScale = new UnityEngine.Vector3(screenWidth / 14f, screenWidth / 14f, 1f);
}
UpdateStats(0);
UpdateStats(0, 1);
}
void MoveBird()
@@ -453,7 +456,7 @@ public class GamePlayer : MonoBehaviour
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Eat"), Camera.main.transform.position, 1.2f * PlayerPrefs.GetFloat("sfxVolume", 1f));
Destroy(berry);
totalNormalBerries++;
UpdateStats(1);
UpdateStats(1, 0);
}
if (speedyLeft > 0)
{
@@ -476,7 +479,7 @@ public class GamePlayer : MonoBehaviour
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Death"), Camera.main.transform.position, 1.2f * PlayerPrefs.GetFloat("sfxVolume", 1f));
Respawn();
totalPoisonBerries++;
UpdateStats(0);
UpdateStats(0, 0);
}
if (speedyLeft > 0)
{
@@ -503,12 +506,12 @@ public class GamePlayer : MonoBehaviour
if (slownessLeft > 0f)
{
slownessLeft = 0f;
UpdateStats(1);
UpdateStats(1, 0);
}
else
{
boostLeft += 10f;
UpdateStats(5);
UpdateStats(5, 0);
}
}
if (speedyLeft > 0)
@@ -537,7 +540,7 @@ public class GamePlayer : MonoBehaviour
totalSlowBerries++;
if (score > 0)
{
UpdateStats(-1);
UpdateStats(-1, 0);
}
}
if (speedyLeft > 0)
@@ -564,7 +567,7 @@ public class GamePlayer : MonoBehaviour
slownessLeft = 0f;
speedyLeft = 10f;
totalSpeedyBerries++;
UpdateStats(10);
UpdateStats(10, 0);
}
if (speedyLeft > 0)
{
@@ -622,7 +625,7 @@ public class GamePlayer : MonoBehaviour
boostLeft = 0f;
slownessLeft = 0f;
speedyLeft = 0f;
UpdateStats(0);
UpdateStats(0, 1);
GameObject[] berries = GameObject.FindGameObjectsWithTag("Berry");
GameObject[] poisonberries = GameObject.FindGameObjectsWithTag("PoisonBerry");
GameObject[] ultraberries = GameObject.FindGameObjectsWithTag("UltraBerry");
@@ -651,9 +654,11 @@ public class GamePlayer : MonoBehaviour
}
}
void UpdateStats(BigInteger toAdd)
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount)
{
score += toAdd;
score += scoreAddAmount;
totalAttempts += attemptAddAmount;
attempts += attemptAddAmount;
if (score > highscore)
{
highscore = score;
@@ -664,9 +669,10 @@ public class GamePlayer : MonoBehaviour
PlayerPrefs.SetString("TotalSlowBerries", totalSlowBerries.ToString());
PlayerPrefs.SetString("TotalUltraBerries", totalUltraBerries.ToString());
PlayerPrefs.SetString("TotalSpeedyBerries", totalSpeedyBerries.ToString());
PlayerPrefs.SetString("TotalAttempts", totalAttempts.ToString());
PlayerPrefs.Save();
scoreText.text = "Score: " + Tools.FormatWithCommas(score);
highScoreText.text = "High Score: " + Tools.FormatWithCommas(highscore);
scoreText.text = $"Score: {Tools.FormatWithCommas(score)} \u2022 Attempts: {attempts}";
highScoreText.text = $"High Score: {Tools.FormatWithCommas(highscore)} \u2022 Total Attempts: {totalAttempts}";
if (restartButton != null) restartButton.GetComponent<Renderer>().material.color = score == 0 ? Color.gray : Color.white;
}