necra-prototypes/pickup_area.gd
Antonio Dell'Annunziata 2cb41beef2
All checks were successful
/ test (push) Successful in 2s
Add choices to dialogs
2025-03-28 07:34:57 +01:00

47 lines
1,007 B
GDScript

class_name PickupArea
extends Area2D
signal picked_up()
signal dropped()
var is_picked_up = false
var is_dropable = false
var is_dropping_enabled = true
var parent: Node2D
func _ready():
parent = get_parent() as Node2D
func _on_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton and event.is_pressed():
if is_picked_up and is_dropable and is_dropping_enabled:
_drop()
elif not is_picked_up:
_pickup()
func _physics_process(delta):
if is_picked_up:
parent.global_position = get_viewport().get_mouse_position()
func _exit_tree():
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _on_dropoff_area_entered(area):
if area is not DropoffArea: return
is_dropable = true
func _on_dropoff_area_exited(area):
if area is not DropoffArea: return
is_dropable = false
func _pickup():
is_picked_up = true
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
picked_up.emit()
func _drop():
is_picked_up = false
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
dropped.emit()