86 lines
2 KiB
GDScript
86 lines
2 KiB
GDScript
class_name Scalpel
|
|
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:
|
|
_drop_scalpel()
|
|
elif is_cutting_possible:
|
|
start_cutting()
|
|
elif is_clickable:
|
|
_pickup_scalpel()
|
|
if 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 _pickup_scalpel():
|
|
is_picked_up = true
|
|
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
|
|
|
func _drop_scalpel():
|
|
is_picked_up = false
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
func _exit_tree():
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
var _scalpel_degrees_default: float
|
|
const SCALPEL_ROTATION_CUTTING = -90.0
|
|
func start_cutting():
|
|
if is_cutting: return
|
|
print("Start cut")
|
|
_scalpel_degrees_default = rotation_degrees
|
|
rotation_degrees = SCALPEL_ROTATION_CUTTING
|
|
_on_cut_hurt_timer_timeout()
|
|
%CutHurtTimer.start(1)
|
|
is_cutting = true
|
|
|
|
func stop_cutting():
|
|
if not is_cutting: return
|
|
print("Stop cut")
|
|
rotation_degrees = _scalpel_degrees_default
|
|
%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")
|