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 16:31:03 +01:00
|
|
|
signal can_interact(object : Interactible)
|
|
|
|
signal remove_interact()
|
|
|
|
|
2024-02-17 12:42:08 +01:00
|
|
|
var current_path : Array[Vector2i]
|
2024-02-17 16:31:03 +01:00
|
|
|
|
|
|
|
var object_near : Interactible
|
|
|
|
var can_interact_flag : bool
|
|
|
|
|
|
|
|
var held_item : Item
|
|
|
|
|
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):
|
2024-02-19 12:16:42 +01:00
|
|
|
print("yay")
|
2024-02-17 12:42:08 +01:00
|
|
|
current_path = gridcontrol.astar.get_id_path(
|
|
|
|
gridcontrol.local_to_map(global_position),
|
|
|
|
gridcontrol.local_to_map(click_position)
|
|
|
|
).slice(1)
|
|
|
|
|
2024-02-17 16:31:03 +01:00
|
|
|
func _shortcut_input(event):
|
|
|
|
if event.is_action_pressed("interact") && can_interact_flag:
|
|
|
|
if object_near is ItemContainer :
|
|
|
|
if not object_near.items.is_empty() && held_item == null:
|
|
|
|
held_item = object_near.items[0]
|
|
|
|
object_near.pop_item(0)
|
|
|
|
_add_item_overhead()
|
2024-02-19 12:16:42 +01:00
|
|
|
elif held_item != null:
|
2024-02-17 16:31:03 +01:00
|
|
|
object_near.add_item(held_item)
|
|
|
|
remove_child(held_item)
|
|
|
|
remove_child(held_item.Icon)
|
|
|
|
held_item = null
|
2024-02-19 12:16:42 +01:00
|
|
|
else :
|
|
|
|
pass
|
2024-02-17 16:31:03 +01:00
|
|
|
|
2024-02-17 12:42:08 +01:00
|
|
|
|
|
|
|
|
2024-02-17 16:31:03 +01:00
|
|
|
func _on_can_interact(object : Interactible):
|
|
|
|
can_interact_flag = true
|
|
|
|
object_near = object
|
2024-02-17 12:42:08 +01:00
|
|
|
|
2024-02-17 16:31:03 +01:00
|
|
|
|
|
|
|
func _on_remove_interact():
|
|
|
|
can_interact_flag = false
|
|
|
|
object_near = null
|
2024-02-19 12:16:42 +01:00
|
|
|
|
2024-02-17 16:31:03 +01:00
|
|
|
|
|
|
|
func _add_item_overhead() :
|
|
|
|
add_child(held_item)
|
|
|
|
add_child(held_item.Icon)
|
|
|
|
held_item.Icon.set_scale(Vector2(0.5,0.5))
|
|
|
|
held_item.Icon.offset = Vector2i(0,-10)
|
|
|
|
held_item.Icon.modulate = Color(1,1,1,0.4)
|
|
|
|
|