Made it save your high score whenever you hit a poison berry

I'm gonna add a pause menu later and whenever you go back the main menu
with that it will save your high score there too.
This commit is contained in:
Puppet committed 2025-10-12 17:08:59 -07:00
1 parent 1b52cae9c5
commit 330258f987
6 files changed
+50 -12

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
using Godot;
public partial class BazookaManager : Node {
public static string HighScore = "0";
public static string Read(string saveKey, string defaultValue) {
string path = "user://" + saveKey + ".txt";
if (!FileAccess.FileExists(path)) {
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreString(defaultValue);
return defaultValue;
} else {
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
return file.GetAsText();
}
}
public static void Write(string saveKey, string value) {
string path = "user://" + saveKey + ".txt";
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreString(value);
file.Flush();
}
}
+1
View File
@@ -0,0 +1 @@
uid://q3n4b6d6e7x0
+2
View File
@@ -29,6 +29,8 @@ public partial class BerryLogic : Node2D {
if (BerryType == "poison") {
Globals.EffectTimer = 0f;
Globals.Score = 0;
BazookaManager.Write(BazookaManager.HighScore, Globals.HighScore.ToString());
} else if (BerryType == "slow") {
if (Globals.ActiveEffect == "slow") {
Globals.EffectTimer += 10f;
+8
View File
@@ -0,0 +1,8 @@
using Godot;
using System;
public partial class LoadSaveFIle : Control {
public override void _Ready() {
Globals.HighScore = int.Parse(BazookaManager.Read(BazookaManager.HighScore, "0"));
}
}
+1
View File
@@ -0,0 +1 @@
uid://crsloi4abxhqh