2024-02-17 12:42:08 +01:00
|
|
|
extends CharacterBody2D
|
|
|
|
class_name Player
|
2024-02-15 19:32:16 +01:00
|
|
|
|
2024-02-17 12:42:08 +01:00
|
|
|
@onready var gridcontrol: TileMap = $"../NavigationMap"
|
2024-02-15 19:32:16 +01:00
|
|
|
|
2024-02-17 12:42:08 +01:00
|
|
|
var current_path : Array[Vector2i]
|
2024-02-15 19:32:16 +01:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
|
|
|
pass
|
2024-02-17 12:42:08 +01:00
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
if current_path.is_empty():
|
|
|
|
return
|
|
|
|
var target_position = gridcontrol.map_to_local(current_path.front())
|
|
|
|
global_position = global_position.move_toward(target_position, 5)
|
|
|
|
|
|
|
|
if global_position == target_position:
|
|
|
|
current_path.pop_front()
|
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
var click_position = get_global_mouse_position()
|
|
|
|
if event.is_action_pressed("move_to"):
|
|
|
|
if gridcontrol.is_spot_walkable(click_position):
|
|
|
|
current_path = gridcontrol.astar.get_id_path(
|
|
|
|
gridcontrol.local_to_map(global_position),
|
|
|
|
gridcontrol.local_to_map(click_position)
|
|
|
|
).slice(1)
|
|
|
|
|
|
|
|
signal can_interact(object : String)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_can_interact(Interact_Type: String, object : Interactible):
|
|
|
|
prints("yippie", Interact_Type)
|