2024-06-13 13:29:05 +02:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
|
|
|
@export var speed = 200
|
2024-06-13 14:25:37 +02:00
|
|
|
var toCalculate = position
|
|
|
|
var distanceTo = 0
|
|
|
|
var active = false
|
2024-06-13 13:29:05 +02:00
|
|
|
|
|
|
|
func get_input():
|
2024-06-15 20:33:37 +02:00
|
|
|
if Input.is_action_pressed("escape"):
|
|
|
|
get_tree().change_scene_to_file("res://scenes/menu/main.tscn")
|
2024-06-13 13:29:05 +02:00
|
|
|
var input_direction = Input.get_vector("left", "right", "up", "down")
|
|
|
|
velocity = input_direction * speed
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
2024-06-13 14:25:37 +02:00
|
|
|
if active:
|
|
|
|
get_input()
|
|
|
|
move_and_slide()
|
|
|
|
distanceTo = position.distance_to(toCalculate)
|
|
|
|
if distanceTo > 500 and active:
|
2024-06-15 20:33:37 +02:00
|
|
|
$Label1.visible = false
|
|
|
|
$Label2.visible = false
|
|
|
|
$Label3.visible = false
|
2024-06-13 14:25:37 +02:00
|
|
|
active = false
|
|
|
|
$camera.enabled = false
|
|
|
|
get_parent().next()
|
|
|
|
|
|
|
|
|
|
|
|
func start():
|
|
|
|
$camera.enabled = true
|
|
|
|
active = true
|
|
|
|
toCalculate = position
|
2024-06-15 20:33:37 +02:00
|
|
|
$Label1.visible = true
|
|
|
|
$Label2.visible = true
|
|
|
|
$Label3.visible = true
|
2024-06-14 09:42:54 +02:00
|
|
|
|
2024-06-15 20:33:37 +02:00
|
|
|
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"))
|
|
|
|
|