necra-prototypes/operation/test_scalpel.gd
Antonio Dell'Annunziata 7ef763605e
All checks were successful
/ test (push) Successful in 1s
Add main scene
2025-03-03 06:21:38 +01:00

59 lines
1.4 KiB
GDScript

class_name Scalpel
extends Sprite2D
signal cut_started
signal cut_ended
var is_cutting_possible = false
var is_cutting = false
@onready var pickup_area: PickupArea = $PickupArea
@onready var cut_area: Area2D = $CutArea
@onready var feedback_canvas_modulate: FeedbackCanvasModulate = %FeedbackCanvasModulate
func _input(event: InputEvent):
if event is InputEventMouseButton:
if event.is_pressed() and is_cutting_possible:
start_cutting()
elif event.is_released() and is_cutting:
stop_cutting()
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()
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(2)
is_cutting = true
cut_started.emit()
func stop_cutting():
if not is_cutting: return
print("Stop cut")
rotation_degrees = _scalpel_degrees_default
%CutHurtTimer.stop()
is_cutting = false
cut_ended.emit()
func _on_cut_hurt_timer_timeout():
# TODO: Check if should hurt
feedback_canvas_modulate.show_hurt_feedback()
%PatienceBar.value = clampi(%PatienceBar.value - 5, 0, 100)
print("Splatter")