persistence

This commit is contained in:
Page Asgardius 2023-11-01 09:35:54 -07:00
parent 05393d901e
commit 20b08a8334
5 changed files with 61 additions and 3 deletions

View file

@ -2,11 +2,15 @@ extends Node
var title = preload("res://title.tscn").instantiate() var title = preload("res://title.tscn").instantiate()
var boot = preload("res://bootclick.tscn").instantiate() var boot = preload("res://bootclick.tscn").instantiate()
const loadgame = preload("res://load.gd")
const savegame = preload("res://save.gd")
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. loadgame.new()
print(Global.level1max)
#pass # Replace with function body.
#add_child(title) #add_child(title)

View file

@ -6,6 +6,14 @@ var origmpos
var mousepos var mousepos
var timelimit = 15000 var timelimit = 15000
var wait var wait
var hiscoresfile = "user://hiscores.save"
var level1max
var level2max
var level3max
var level4max
var level5max
var level6max
var level7max
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. pass # Replace with function body.

View file

@ -43,7 +43,7 @@ Astroboy
Zencifer Zencifer
Natasha Natasha
Sakura Nakayama Sakura Nakayama
Bicycle Man BMX Man
Godot version testing Godot version testing
@ -455,7 +455,11 @@ Source code hosted at https://git.asgardius.company/asgardius/r3-next
You can listen the oficial radio station at https://asteroid.asgardius.company/public/r3 You can listen the oficial radio station at https://asteroid.asgardius.company/public/r3
Special Thanks for Unity Technologies for make me choosing Godot" Special Thanks for Unity Technologies for make me choosing Godot
Godot does what Unitydnt
I'm looking for developers, artists and japanese voice actors who want to help on my next videogame from Asgardius Virtualx series"
horizontal_alignment = 1 horizontal_alignment = 1
script = ExtResource("6_3q8sp") script = ExtResource("6_3q8sp")

36
load.gd Normal file
View file

@ -0,0 +1,36 @@
extends Node
var file
func _init():
if FileAccess.file_exists(Global.hiscoresfile):
file = FileAccess.open(Global.hiscoresfile, FileAccess.READ)
var checkpoint = file.get_as_text().rsplit(",", true, 7)
Global.level1max = checkpoint[0]
Global.level2max = checkpoint[1]
Global.level3max = checkpoint[2]
Global.level4max = checkpoint[3]
Global.level5max = checkpoint[4]
Global.level6max = checkpoint[5]
Global.level7max = checkpoint[6]
# We need to revert the game state so we're not cloning objects
# during loading. This will vary wildly depending on the needs of a
# project, so take care with this step.
# For our example, we will accomplish this by deleting saveable objects.
#var save_nodes = get_tree().get_nodes_in_group("Persist")
#for i in save_nodes:
# i.queue_free()
# Load the file line by line and process that dictionary to restore
# the object it represents.
else:
var saveinit = "9999999,9999999,9999999,9999999,9999999,9999999,9999999"
var file = FileAccess.open(Global.hiscoresfile, FileAccess.WRITE)
file.store_string(saveinit)
var checkpoint = saveinit.rsplit(",", true, 7)
Global.level1max = checkpoint[0]
Global.level2max = checkpoint[1]
Global.level3max = checkpoint[2]
Global.level4max = checkpoint[3]
Global.level5max = checkpoint[4]
Global.level6max = checkpoint[5]
Global.level7max = checkpoint[6]

6
save.gd Normal file
View file

@ -0,0 +1,6 @@
extends Node
func _init():
var saveinit = str(Global.level1max)+","+str(Global.level2max)+","+str(Global.level3max)+","+str(Global.level4max)+","+str(Global.level5max)+","+str(Global.level6max)+","+str(Global.level7max)
var file = FileAccess.open(Global.hiscoresfile, FileAccess.WRITE)
file.store_string(saveinit)
file.close()