57 lines
1.2 KiB
GDScript
57 lines
1.2 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)
|
|
|
|
|
|
func reset_game():
|
|
speed = 100
|
|
score = 0
|
|
active_biom = "n"
|
|
gamerunning = false
|
|
_ready()
|
|
$/root/Game/Fade/FadeAnimation.play("fade")
|
|
get_tree().reload_current_scene()
|