freettrpg/scripts/player.gd
Patrick_Pluto 21bcce37fa Version: 0.0.3
Slight code fixups and changed some map stuff, Also added a stat viewer for the current player in the game itself.
2024-06-16 19:32:19 +02:00

39 lines
825 B
GDScript

extends CharacterBody2D
@export var speed = 200
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
func _physics_process(delta):
var toCalculate = position
if active:
get_input()
move_and_slide()
distanceTo += position.distance_to(toCalculate)
print(distanceTo)
if distanceTo > 500 and active:
stop()
distanceTo = 0
get_parent().next()
func start():
$camera.enabled = true
active = true
$stats.disabled = false
$stats.visible = true
func stop():
$camera.enabled = false
active = false
$stats.disabled = true
$stats.visible = false
func _on_stats_pressed():
get_parent().stats()