Version: 0.0.1

First major release, refined the creator, added stats to the main game, added a menu to view stats.
This commit is contained in:
Patrick_Pluto 2024-06-15 20:33:37 +02:00
parent 8f78f8e5cb
commit e5911fd155
11 changed files with 264 additions and 42 deletions

View file

@ -1,8 +1,8 @@
extends Node
var save_path = "user://player_data.json"
func saveJSON():
var save_path = str("user://player_data"+$input_id.text+".json")
var data := {
"name": $input_name.text,
"hp": $input_hp.text,
@ -19,27 +19,9 @@ func saveJSON():
file_access.store_line(json_string)
file_access.close()
func loadJSON():
if not FileAccess.file_exists(save_path):
return
var file_access = FileAccess.open(save_path, FileAccess.READ)
var json_string = file_access.get_line()
file_access.close()
var json = JSON.new()
var error = json.parse(json_string)
if error:
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
return
var data:Dictionary = json.data
var charName = data.get("name")
var charHP = data.get("hp")
var charLevel = data.get("level")
print(charName)
print(charHP)
print(charLevel)
func _on_button_pressed():
saveJSON()
loadJSON()
func _process(delta):
if Input.is_action_pressed("escape"):
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")

29
scripts/getStats.gd Normal file
View file

@ -0,0 +1,29 @@
extends Node
func loadJSON():
var save_path = str("user://player_data"+$input_id.text+".json")
print(save_path)
if not FileAccess.file_exists(save_path):
return
var file_access = FileAccess.open(save_path, FileAccess.READ)
var json_string = file_access.get_line()
file_access.close()
var json = JSON.new()
var error = json.parse(json_string)
if error:
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
return
var data:Dictionary = json.data
$output_name.text = str("Name: "+data.get("name"))
$output_hp.text = str("HP: "+data.get("hp"))
$output_level.text = str("Level: "+data.get("level"))
func _on_button_pressed():
loadJSON()
func _process(delta):
if Input.is_action_pressed("escape"):
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")

View file

@ -13,5 +13,6 @@ func next():
objectName= "player%d" % playerIndex
print(objectName)
get_node(objectName).start()
get_node(objectName).loadJSON(playerIndex)
playerIndex += 1

View file

@ -7,4 +7,8 @@ func _on_button_pressed():
func _on_button_2_pressed():
get_tree().change_scene_to_file("res://scenes/menu/view.tscn")
func _on_button_3_pressed():
get_tree().change_scene_to_file("res://scenes/menu/create.tscn")

View file

@ -6,6 +6,8 @@ var distanceTo = 0
var active = false
func get_input():
if Input.is_action_pressed("escape"):
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
var input_direction = Input.get_vector("left", "right", "up", "down")
velocity = input_direction * speed
@ -15,6 +17,9 @@ func _physics_process(delta):
move_and_slide()
distanceTo = position.distance_to(toCalculate)
if distanceTo > 500 and active:
$Label1.visible = false
$Label2.visible = false
$Label3.visible = false
active = false
$camera.enabled = false
get_parent().next()
@ -24,4 +29,27 @@ func start():
$camera.enabled = true
active = true
toCalculate = position
$Label1.visible = true
$Label2.visible = true
$Label3.visible = true
func loadJSON(id):
var save_path = str("user://player_data"+str(id)+".json")
print(save_path)
if not FileAccess.file_exists(save_path):
return
var file_access = FileAccess.open(save_path, FileAccess.READ)
var json_string = file_access.get_line()
file_access.close()
var json = JSON.new()
var error = json.parse(json_string)
if error:
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
return
var data:Dictionary = json.data
$Label1.text = str("Name: "+data.get("name"))
$Label2.text = str("HP: "+data.get("hp"))
$Label3.text = str("Level: "+data.get("level"))