DuckRun/code/global.gd
megamichi dd5b4bcae5 - improving textures
- adding coins (no shop jet)
- adding skin changing [no gui jet
- fixing loops for deleting stuff]
2024-11-10 19:51:00 +01:00

64 lines
1.3 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:int
var coins:int
func _ready() -> void:
var save = load_save()
hiscore = save["hiscore"]
coins = save["hiscore"]
func reset_game():
speed = 100
score = 0
active_biom = "n"
gamerunning = false
_ready()
get_tree().reload_current_scene()
var data : FileAccess
func load_save() -> Dictionary:
# wenn kein save vorhanden ist, erstelle eins
if (not FileAccess.file_exists("user://save.json")) or (FileAccess.open("user://save.json", FileAccess.READ_WRITE).get_as_text() == ""):
init_save()
data = FileAccess.open("user://save.json", FileAccess.READ)
var content_text: Dictionary = JSON.parse_string(data.get_as_text())
if content_text:
print("loaded: ",content_text)
return content_text
else:
print("Failed to parse JSON")
return {}
func write_save():
var sdata : FileAccess
sdata = FileAccess.open("user://save.json",FileAccess.WRITE)
var content = JSON.stringify(
{
"hiscore":$/root/Game/Gui/ScoreContainer.get_score()
}
)
print("saved: ",content)
sdata.store_string(content)
func init_save():
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()