ld58-collector/gavel.gd
2025-10-05 23:54:24 -07:00

51 lines
1.7 KiB
GDScript

class_name Gavel extends Node2D
signal gavel_hit
var swinging
var click_radius = 32 # will need to determine click radius based on sprite size -- should be equal
var swing_threshold = 64 # will also need to scale this based on sprite size
var swing_start = Vector2(0, 0)
@export var gavel_root_position = Vector2(0, 0)
@export var audio_player: AudioStreamPlayer2D
#func _input(event: InputEvent) -> void:
#if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
## check to see if the player clicked on the gavel
#if (event.position - $Sprite2D.position).length() < click_radius:
#if not swinging and event.pressed():
#swinging = true
#swing_start = InputEventMouseMotion.screen_relative
#if swinging and not event.pressed():
#swinging = false
#
#if event is InputEventMouseMotion and swinging:
#$Sprite2D.position = event.position
#if InputEventMouseMotion.screen_relative.length() - swing_start.length() == swing_threshold:
#gavel_hit.emit()
#$Sprite2D.position = gavel_root_position
func _on_texture_button_button_down() -> void:
$TextureButton.mouse_default_cursor_shape = Control.CURSOR_DRAG
audio_player.play()
gavel_hit.emit()
$GavelAnimations.play("Press")
func _on_texture_button_mouse_entered() -> void:
$GavelAnimations.play("Hover")
func _on_texture_button_mouse_exited() -> void:
#if $TextureButton.pressed:
$GavelAnimations.play("Unhover")
await $GavelAnimations.animation_finished
$GavelAnimations.play("Idle")
#else:
#$GavelAnimations.play("Hover", -1.0)
#$GavelAnimations.play("Idle")
func _on_texture_button_button_release() -> void:
$TextureButton.mouse_default_cursor_shape = Control.CURSOR_ARROW