Updating hammer animation logic

This commit is contained in:
vandomej 2025-10-06 11:42:23 -07:00
parent 6327f89bc8
commit 9897839420
2 changed files with 32 additions and 11 deletions

View file

@ -53,7 +53,7 @@
[ext_resource type="Texture2D" uid="uid://cxwxmqnnbyl3s" path="res://assets/numpad/ask-depressed.png" id="28_4l1rv"] [ext_resource type="Texture2D" uid="uid://cxwxmqnnbyl3s" path="res://assets/numpad/ask-depressed.png" id="28_4l1rv"]
[ext_resource type="AudioStream" uid="uid://bvto7ghmy8j0o" path="res://assets/gavel/audio/invalid-bet.wav" id="31_v5y5a"] [ext_resource type="AudioStream" uid="uid://bvto7ghmy8j0o" path="res://assets/gavel/audio/invalid-bet.wav" id="31_v5y5a"]
[ext_resource type="AudioStream" uid="uid://bq5yl788b424g" path="res://assets/numpad/ask-bet-final.wav" id="53_mq8ri"] [ext_resource type="AudioStream" uid="uid://bq5yl788b424g" path="res://assets/numpad/ask-bet-final.wav" id="53_mq8ri"]
[ext_resource type="Script" uid="uid://cwnif1u23aa2" path="res://bark.gd" id="54_bxpdm"] [ext_resource type="Script" path="res://bark.gd" id="54_bxpdm"]
[ext_resource type="Texture2D" uid="uid://b6n841u18dddv" path="res://assets/buttons/button_up.png" id="55_8sdgr"] [ext_resource type="Texture2D" uid="uid://b6n841u18dddv" path="res://assets/buttons/button_up.png" id="55_8sdgr"]
[ext_resource type="Texture2D" uid="uid://bdjfior4od5ub" path="res://assets/buttons/button_down.png" id="56_k4eer"] [ext_resource type="Texture2D" uid="uid://bdjfior4od5ub" path="res://assets/buttons/button_down.png" id="56_k4eer"]

View file

@ -10,6 +10,9 @@ var swing_start = Vector2(0, 0)
@export var gavel_root_position = Vector2(0, 0) @export var gavel_root_position = Vector2(0, 0)
@export var audio_player: AudioStreamPlayer2D @export var audio_player: AudioStreamPlayer2D
enum GavelState { HOVER, SWING, UNHOVER, IDLE }
var current_state: GavelState = GavelState.IDLE
#func _input(event: InputEvent) -> void: #func _input(event: InputEvent) -> void:
#if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: #if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
## check to see if the player clicked on the gavel ## check to see if the player clicked on the gavel
@ -26,28 +29,46 @@ var swing_start = Vector2(0, 0)
#gavel_hit.emit() #gavel_hit.emit()
#$Sprite2D.position = gavel_root_position #$Sprite2D.position = gavel_root_position
func transition(new_state: GavelState):
match new_state:
GavelState.HOVER:
if current_state == GavelState.UNHOVER:
$GavelAnimations.animation_finished.disconnect(_on_unhover_complete)
$GavelAnimations.play("Hover")
GavelState.IDLE:
$TextureButton.mouse_default_cursor_shape = Control.CURSOR_ARROW
$GavelAnimations.play("Idle")
GavelState.UNHOVER:
$GavelAnimations.play("Unhover")
$GavelAnimations.animation_finished.connect(_on_unhover_complete)
GavelState.SWING:
$TextureButton.mouse_default_cursor_shape = Control.CURSOR_DRAG
audio_player.play()
gavel_hit.emit()
if current_state == GavelState.SWING:
$GavelAnimations.frame = 0
$GavelAnimations.play("Press")
current_state = new_state
func _on_texture_button_button_down() -> void: func _on_texture_button_button_down() -> void:
$TextureButton.mouse_default_cursor_shape = Control.CURSOR_DRAG transition(GavelState.SWING)
audio_player.play()
gavel_hit.emit()
if $GavelAnimations.animation == "Press":
$GavelAnimations.frame = 0
$GavelAnimations.play("Press")
func _on_texture_button_mouse_entered() -> void: func _on_texture_button_mouse_entered() -> void:
$GavelAnimations.play("Hover") transition(GavelState.HOVER)
func _on_texture_button_mouse_exited() -> void: func _on_texture_button_mouse_exited() -> void:
transition(GavelState.UNHOVER)
#if $TextureButton.pressed: #if $TextureButton.pressed:
$GavelAnimations.play("Unhover")
await $GavelAnimations.animation_finished
$GavelAnimations.play("Idle")
#else: #else:
#$GavelAnimations.play("Hover", -1.0) #$GavelAnimations.play("Hover", -1.0)
#$GavelAnimations.play("Idle") #$GavelAnimations.play("Idle")
func _on_unhover_complete() -> void:
$GavelAnimations.animation_finished.disconnect(_on_unhover_complete)
transition(GavelState.IDLE)
func _on_texture_button_button_release() -> void: func _on_texture_button_button_release() -> void:
$TextureButton.mouse_default_cursor_shape = Control.CURSOR_ARROW $TextureButton.mouse_default_cursor_shape = Control.CURSOR_ARROW