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:
1 parent
1b52cae9c5
commit
330258f987
6 files changed
+50
-12
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://q3n4b6d6e7x0
|
||||
@@ -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;
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://crsloi4abxhqh
|
||||
Reference in new issue
Block a user