feat: animations working

This commit is contained in:
Gerard Gascón 2025-04-12 17:12:04 +02:00
parent 2a9e824a9e
commit 2445a71f0c
63 changed files with 3023 additions and 1408 deletions

View file

@ -35,7 +35,7 @@ var current_state: State = State.WALKING_IDLE
func _ready() -> void:
draggable.on_drag.connect(_on_drag)
draggable.on_drop.connect(_on_drop)
current_state = State.FALLING
_change_state(State.FALLING)
func on_place_back() -> void:
@ -50,12 +50,6 @@ func _process(delta: float) -> void:
State.DRAGGING:
_thinking_path = false
_actual_position = position
State.WALKING_IDLE:
if not _thinking_path:
_think_path()
State.FLYING_IDLE:
if not _thinking_path:
_think_path()
State.WALKING:
_move_to_target(delta)
State.FALLING:
@ -66,12 +60,30 @@ func _process(delta: float) -> void:
properties.position = position
func _change_state(new_state):
match new_state:
State.DRAGGING:
dragon.play_idle()
State.WALKING_IDLE:
dragon.play_idle()
_think_path()
State.FLYING_IDLE:
_think_path()
State.WALKING:
dragon.play_walk()
State.FALLING:
dragon.play_idle()
State.FLYING:
dragon.play_fly()
current_state = new_state
func dress():
dragon.dress(properties)
func _think_path():
_thinking_path = true
await get_tree().create_timer(rng.randf_range(2, 7)).timeout
dragon_speed = rng.randf_range(dragon_speed_min, dragon_speed_max)
@ -86,7 +98,7 @@ func _think_path():
var decision: int = rng.randi_range(0, 99)
if decision < 30:
_fall_speed = 0
current_state = State.FALLING
_change_state(State.FALLING)
else:
_pick_random_screen_fly_position()
@ -98,7 +110,7 @@ func _fall(delta: float) -> void:
var ground_height: int = _ground_height()
if position.y >= ground_height:
current_state = State.WALKING_IDLE
_change_state(State.WALKING_IDLE)
position.y = ground_height
_actual_position.y = ground_height
@ -117,24 +129,24 @@ func _move_to_target(delta: float):
match current_state:
State.FLYING:
current_state = State.FLYING_IDLE
_change_state(State.FLYING_IDLE)
State.WALKING:
current_state = State.WALKING_IDLE
_change_state(State.WALKING_IDLE)
func _on_drag():
current_state = State.DRAGGING
_change_state(State.DRAGGING)
func _on_drop():
var ground_height: int = _ground_height()
if position.y >= ground_height:
current_state = State.WALKING_IDLE
_change_state(State.WALKING_IDLE)
position.y = ground_height
_actual_position.y = ground_height
else:
_fall_speed = 0
current_state = State.FALLING
_change_state(State.FALLING)
func _get_display_limits() -> Rect2i:
@ -151,7 +163,7 @@ func _ground_height() -> int:
func _pick_random_screen_fly_position() -> void:
current_state = State.FLYING
_change_state(State.FLYING)
_thinking_path = false
var limits: Rect2i = _get_display_limits()
@ -165,7 +177,7 @@ func _pick_random_screen_fly_position() -> void:
func _pick_random_screen_walk_position() -> void:
current_state = State.WALKING
_change_state(State.WALKING)
_thinking_path = false
var limits: Rect2i = _get_display_limits()

View file

@ -7,7 +7,7 @@
[node name="DragonPopup" type="Window" node_paths=PackedStringArray("dragon", "draggable")]
disable_3d = true
transparent_bg = true
size = Vector2i(76, 88)
size = Vector2i(108, 88)
unresizable = true
borderless = true
always_on_top = true