DuckRun/code/global.gd
megamichi 21e927966d - fixing hindernis speed
- Biom implementation
- Better Graphics
- again icon fix
2024-10-21 21:22:40 +02:00

47 lines
1.1 KiB
GDScript

extends Node
signal levelup
signal start
var maxspeed = 260
var speed = 100
var score = 0
var active_biom
var gamerunning = false
var hiscore
func _ready() -> void:
load_save()
#write_save()
func load_save():
var data : FileAccess
if (not FileAccess.file_exists("user://save.json")) or (FileAccess.open("user://save.json", FileAccess.READ_WRITE).get_as_text() == ""):
data = FileAccess.open("user://save.json", FileAccess.WRITE)
data.store_string(FileAccess.open("res://code/first_save.json", FileAccess.READ).get_as_text())
data.close()
data = FileAccess.open("user://save.json", FileAccess.READ)
var content_text = JSON.parse_string(data.get_as_text())
if content_text:
print("loaded: ",content_text)
hiscore = content_text.get("hiscore", 0)
else:
print("Failed to parse JSON")
data.close()
func write_save():
var data : FileAccess
data = FileAccess.open("user://save.json",FileAccess.WRITE)
var content = JSON.stringify(
{
"hiscore":$/root/Game/Gui/ScoreContainer.get_score()
}
)
print("saved: ",content)
data.store_string(content)