Added lever animation

This commit is contained in:
2026-03-17 21:56:31 +03:00
parent 489c89e1ac
commit 8ec34e1285
4 changed files with 86 additions and 14 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ func _physics_process(delta: float) -> void:
if is_dead:
_slow_down(delta*3)
else:
if Input.is_action_just_pressed("interact"):
if Input.is_action_pressed("interact"):
interacted.emit()
if Input.is_action_just_pressed("jump"):
@@ -5,8 +5,7 @@ extends Node2D
@onready var hint_sprite : Sprite2D = $HintSprite
func activate() -> void:
pass
var _player_in_range := false
func _ready() -> void:
@@ -16,10 +15,16 @@ func _ready() -> void:
func _on_body_entered(body: Node2D) -> void:
if body is Player:
hint_sprite.show()
body.interacted.connect(activate)
_player_in_range = true
body.interacted.connect(_activate)
func _on_body_exited(body: Node2D) -> void:
if body is Player:
hint_sprite.hide()
body.interacted.disconnect(activate)
_player_in_range = false
body.interacted.disconnect(_activate)
func _activate() -> void:
pass
+66 -2
View File
@@ -1,5 +1,69 @@
extends AbstractActivatableObject
func activate() -> void:
pass
signal switching
signal switched
enum State {
TurnedLeft,
TurnedRight,
TurningLeft,
TurningRight,
}
const ANIMATION_BY_STATE : Dictionary[State, String] = {
State.TurnedLeft: "turned_left",
State.TurnedRight: "turned_right",
State.TurningLeft: "turning_left",
State.TurningRight: "turning_right",
}
@export var initial_state: State = State.TurnedLeft
var _current_state : State
@onready var animated_sprite : AnimatedSprite2D = $AnimatedSprite2D
func _ready() -> void:
super._ready()
_current_state = initial_state
_update_animation()
func _activate() -> void:
var set_state := func(state: State) -> void:
_current_state = state
_update_animation()
hint_sprite.hide()
switching.emit()
match _current_state:
State.TurnedLeft:
set_state.call(State.TurningRight)
State.TurnedRight:
set_state.call(State.TurningLeft)
func _update_animation() -> void:
var animation := ANIMATION_BY_STATE[_current_state]
animated_sprite.play(animation)
func _on_animation_finished() -> void:
var set_state := func(state: State) -> void:
_current_state = state
_update_animation()
switched.emit()
if _player_in_range:
hint_sprite.show()
match _current_state:
State.TurningLeft:
set_state.call(State.TurnedLeft)
State.TurningRight:
set_state.call(State.TurnedRight)
+10 -7
View File
@@ -66,7 +66,7 @@ animations = [{
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"duration": 2.0,
"texture": SubResource("AtlasTexture_fmhac")
}, {
"duration": 1.0,
@@ -75,15 +75,15 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_m2d68")
}, {
"duration": 1.0,
"duration": 2.0,
"texture": SubResource("AtlasTexture_eom63")
}],
"loop": false,
"name": &"turning_left",
"speed": 10.0
"speed": 20.0
}, {
"frames": [{
"duration": 1.0,
"duration": 2.0,
"texture": SubResource("AtlasTexture_0m1ch")
}, {
"duration": 1.0,
@@ -92,12 +92,12 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_b2o5l")
}, {
"duration": 1.0,
"duration": 2.0,
"texture": SubResource("AtlasTexture_5h41l")
}],
"loop": false,
"name": &"turning_right",
"speed": 10.0
"speed": 20.0
}]
[sub_resource type="AtlasTexture" id="AtlasTexture_5upgc"]
@@ -106,6 +106,7 @@ region = Rect2(96, 0, 16, 16)
[node name="Lever" unique_id=1479061220 instance=ExtResource("1_rl4ey")]
script = ExtResource("2_5hu3b")
initial_state = 0
[node name="CollisionShape2D" parent="." index="0" unique_id=2065213362]
position = Vector2(0, -4)
@@ -116,7 +117,9 @@ position = Vector2(0, -11)
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." index="2" unique_id=2086579452]
sprite_frames = SubResource("SpriteFrames_kky3u")
animation = &"turned_left"
animation = &"turning_left"
[node name="BaseSprite" type="Sprite2D" parent="." index="3" unique_id=256419860]
texture = SubResource("AtlasTexture_5upgc")
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]