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
+14
-12
@@ -1,5 +1,6 @@
|
|||||||
[gd_scene load_steps=9 format=3 uid="uid://bg4fa11htun38"]
|
[gd_scene load_steps=10 format=3 uid="uid://bg4fa11htun38"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://crsloi4abxhqh" path="res://Scripts/LoadSaveFIle.cs" id="1_df05h"]
|
||||||
[ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="1_tt5f1"]
|
[ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="1_tt5f1"]
|
||||||
[ext_resource type="Script" uid="uid://bc4miccifwrk0" path="res://Scripts/SceneSwitcher.cs" id="2_8saeu"]
|
[ext_resource type="Script" uid="uid://bc4miccifwrk0" path="res://Scripts/SceneSwitcher.cs" id="2_8saeu"]
|
||||||
[ext_resource type="AudioStream" uid="uid://6v4630hrkeg6" path="res://Audio/Music/Menu.mp3" id="2_853f1"]
|
[ext_resource type="AudioStream" uid="uid://6v4630hrkeg6" path="res://Audio/Music/Menu.mp3" id="2_853f1"]
|
||||||
@@ -9,12 +10,6 @@
|
|||||||
font = ExtResource("1_tt5f1")
|
font = ExtResource("1_tt5f1")
|
||||||
font_size = 486
|
font_size = 486
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_853f1"]
|
|
||||||
bg_color = Color(0.95158, 0.95158, 0.95158, 1)
|
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8saeu"]
|
|
||||||
bg_color = Color(0.830335, 0.830335, 0.830335, 1)
|
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tt5f1"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tt5f1"]
|
||||||
bg_color = Color(1, 1, 1, 1)
|
bg_color = Color(1, 1, 1, 1)
|
||||||
corner_radius_top_left = 5
|
corner_radius_top_left = 5
|
||||||
@@ -22,6 +17,12 @@ corner_radius_top_right = 5
|
|||||||
corner_radius_bottom_right = 5
|
corner_radius_bottom_right = 5
|
||||||
corner_radius_bottom_left = 5
|
corner_radius_bottom_left = 5
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8saeu"]
|
||||||
|
bg_color = Color(0.830335, 0.830335, 0.830335, 1)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_853f1"]
|
||||||
|
bg_color = Color(0.95158, 0.95158, 0.95158, 1)
|
||||||
|
|
||||||
[node name="MainMenu" type="Control"]
|
[node name="MainMenu" type="Control"]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
@@ -29,6 +30,7 @@ anchor_right = 1.0
|
|||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
script = ExtResource("1_df05h")
|
||||||
|
|
||||||
[node name="Center" type="Control" parent="."]
|
[node name="Center" type="Control" parent="."]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@@ -127,17 +129,17 @@ offset_right = 250.0
|
|||||||
offset_bottom = 118.0
|
offset_bottom = 118.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
theme_override_colors/font_disabled_color = Color(0, 0, 0, 1)
|
|
||||||
theme_override_colors/font_hover_pressed_color = Color(0, 0, 0, 1)
|
|
||||||
theme_override_colors/font_hover_color = Color(0, 0, 0, 1)
|
|
||||||
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
theme_override_colors/font_focus_color = Color(0, 0, 0, 1)
|
theme_override_colors/font_focus_color = Color(0, 0, 0, 1)
|
||||||
theme_override_colors/font_pressed_color = Color(0, 0, 0, 1)
|
theme_override_colors/font_pressed_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_hover_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_hover_pressed_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_disabled_color = Color(0, 0, 0, 1)
|
||||||
theme_override_fonts/font = ExtResource("1_tt5f1")
|
theme_override_fonts/font = ExtResource("1_tt5f1")
|
||||||
theme_override_font_sizes/font_size = 56
|
theme_override_font_sizes/font_size = 56
|
||||||
theme_override_styles/hover = SubResource("StyleBoxFlat_853f1")
|
|
||||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_8saeu")
|
|
||||||
theme_override_styles/normal = SubResource("StyleBoxFlat_tt5f1")
|
theme_override_styles/normal = SubResource("StyleBoxFlat_tt5f1")
|
||||||
|
theme_override_styles/pressed = SubResource("StyleBoxFlat_8saeu")
|
||||||
|
theme_override_styles/hover = SubResource("StyleBoxFlat_853f1")
|
||||||
text = "Play"
|
text = "Play"
|
||||||
script = ExtResource("2_8saeu")
|
script = ExtResource("2_8saeu")
|
||||||
ScenePath = "res://Scenes/Game.tscn"
|
ScenePath = "res://Scenes/Game.tscn"
|
||||||
|
|||||||
@@ -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") {
|
if (BerryType == "poison") {
|
||||||
Globals.EffectTimer = 0f;
|
Globals.EffectTimer = 0f;
|
||||||
Globals.Score = 0;
|
Globals.Score = 0;
|
||||||
|
|
||||||
|
BazookaManager.Write(BazookaManager.HighScore, Globals.HighScore.ToString());
|
||||||
} else if (BerryType == "slow") {
|
} else if (BerryType == "slow") {
|
||||||
if (Globals.ActiveEffect == "slow") {
|
if (Globals.ActiveEffect == "slow") {
|
||||||
Globals.EffectTimer += 10f;
|
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