69 lines
1.6 KiB
GDScript
69 lines
1.6 KiB
GDScript
extends Sprite2D
|
|
|
|
var is_clickable = false
|
|
var is_picked_up = false
|
|
var is_dropable = false
|
|
var is_cutting_possible = false
|
|
var is_cutting = false
|
|
|
|
@onready var pickup_area = $PickupArea
|
|
@onready var cut_area = $CutArea
|
|
|
|
func _ready():
|
|
pickup_area.connect("mouse_entered", func(): is_clickable = true)
|
|
pickup_area.connect("mouse_exited", func(): is_clickable = false)
|
|
|
|
func _input(event: InputEvent):
|
|
if event is InputEventMouseButton and event.is_pressed():
|
|
if is_picked_up:
|
|
if is_dropable:
|
|
is_picked_up = false
|
|
elif is_cutting_possible:
|
|
start_cutting()
|
|
elif is_clickable:
|
|
is_picked_up = true
|
|
elif event is InputEventMouseButton and event.is_released():
|
|
if is_cutting:
|
|
stop_cutting()
|
|
if is_picked_up and event is InputEventMouseMotion:
|
|
global_position = event.global_position
|
|
|
|
|
|
func _on_dropoff_area_entered(area):
|
|
if area != pickup_area: return
|
|
is_dropable = true
|
|
|
|
|
|
func _on_dropoff_area_exited(area):
|
|
if area != pickup_area: return
|
|
is_dropable = false
|
|
|
|
|
|
func _on_body_area_entered(area):
|
|
if area != cut_area: return
|
|
is_cutting_possible = true
|
|
|
|
|
|
func _on_body_area_exited(area):
|
|
if area != cut_area: return
|
|
is_cutting_possible = false
|
|
stop_cutting()
|
|
|
|
func start_cutting():
|
|
if is_cutting: return
|
|
print("Start cut")
|
|
_on_cut_hurt_timer_timeout()
|
|
%CutHurtTimer.start(1)
|
|
is_cutting = true
|
|
|
|
func stop_cutting():
|
|
if not is_cutting: return
|
|
print("Stop cut")
|
|
%CutHurtTimer.stop()
|
|
is_cutting = false
|
|
|
|
|
|
func _on_cut_hurt_timer_timeout():
|
|
# TODO: Check if should hurt
|
|
%PatienceBar.value = clampi(%PatienceBar.value - 5, 0, 100)
|
|
print("Splatter")
|