feat: started adding animation behaviour

This commit is contained in:
Gerard Gascón 2025-04-12 14:16:06 +02:00
parent 2f60fd19d6
commit 2a9e824a9e
12 changed files with 123 additions and 93 deletions

View file

@ -2,10 +2,10 @@ extends Node2D
class_name DragonSprite
@export var hat: Sprite2D
@export var shirt: Sprite2D
@export var decor: Sprite2D
@export var color: Sprite2D
@export var hat: AnimatedSprite2D
@export var shirt: AnimatedSprite2D
@export var decor: AnimatedSprite2D
@export var color: AnimatedSprite2D
@export var hat_outfits: DragonOutfit
@export var shirt_outfits: DragonOutfit
@ -14,10 +14,19 @@ class_name DragonSprite
func dress(properties: DragonProperties):
self.hat.texture = hat_outfits.get_texture(properties.hat)
self.shirt.texture = shirt_outfits.get_texture(properties.shirt)
self.decor.texture = decor_outfits.get_texture(properties.decor)
self.color.texture = color_outfits.get_texture(properties.color)
_set_dress(hat, hat_outfits.get_texture(properties.hat))
_set_dress(shirt, shirt_outfits.get_texture(properties.shirt))
_set_dress(decor, decor_outfits.get_texture(properties.decor))
_set_dress(color, color_outfits.get_texture(properties.color))
play_idle()
func _set_dress(part: AnimatedSprite2D, dress: SpriteFrames):
if dress == null:
part.visible = false
else:
part.visible = true
part.set_sprite_frames(dress)
func walk_left():
@ -28,3 +37,30 @@ func walk_left():
func walk_right():
$Sprite.scale.x = -1
$DragonBody.scale.x = -1
func _play_animation(animation_name: String, part: AnimatedSprite2D) -> void:
if !part.is_visible():
return
part.play(animation_name)
func play_idle() -> void:
_play_animation("idle", hat)
_play_animation("idle", shirt)
_play_animation("idle", decor)
_play_animation("idle", color)
func play_fly() -> void:
_play_animation("fly", hat)
_play_animation("fly", shirt)
_play_animation("fly", decor)
_play_animation("fly", color)
func play_walk() -> void:
_play_animation("walk", hat)
_play_animation("walk", shirt)
_play_animation("walk", decor)
_play_animation("walk", color)

View file

@ -1,27 +1,24 @@
[gd_scene load_steps=12 format=3 uid="uid://baa8gpicw2yg0"]
[gd_scene load_steps=11 format=3 uid="uid://baa8gpicw2yg0"]
[ext_resource type="Script" uid="uid://bjiap06gs02j" path="res://scenes/dragons/dragon_sprite.gd" id="1_oaoux"]
[ext_resource type="Resource" uid="uid://cnhwn6kfcbjl5" path="res://assets/outfits/hats.tres" id="2_mxc00"]
[ext_resource type="Texture2D" uid="uid://12fv5nymaljj" path="res://assets/sprites/hats/DragonPet_barret_barretina.png" id="3_oaoux"]
[ext_resource type="Resource" uid="uid://etegcak2sphs" path="res://assets/outfits/shirts.tres" id="3_umqeb"]
[ext_resource type="Resource" uid="uid://ba5684xylts3f" path="res://assets/outfits/shoes.tres" id="4_7b2ll"]
[ext_resource type="Texture2D" uid="uid://b3xnii6r00hol" path="res://assets/sprites/shirts/DragonPet_roba_traje.png" id="4_oaoux"]
[ext_resource type="Texture2D" uid="uid://c1b8gp5uf2ehk" path="res://assets/sprites/decor/DragonPet_acc_rosa.png" id="5_stf6f"]
[ext_resource type="Resource" uid="uid://ba5684xylts3f" path="res://assets/outfits/decor.tres" id="4_7b2ll"]
[ext_resource type="Resource" uid="uid://bcs60f2k7h0jc" path="res://assets/outfits/dragons.tres" id="5_x2k4p"]
[ext_resource type="SpriteFrames" uid="uid://4cm7picl2gvs" path="res://assets/animations/dragons/green.tres" id="6_yf7bj"]
[ext_resource type="SpriteFrames" uid="uid://cwxqw54jvqryh" path="res://assets/animations/hats/barretina.tres" id="10_7b2ll"]
[ext_resource type="SpriteFrames" uid="uid://csm1127xw2qoh" path="res://assets/animations/shirts/traje.tres" id="11_x2k4p"]
[ext_resource type="SpriteFrames" uid="uid://cjoufnwxcvvf4" path="res://assets/animations/decor/rosa.tres" id="12_rhebu"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_oaoux"]
size = Vector2(76, 88)
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_f0h1k"]
load_path = "res://.godot/imported/DragonPet_drac01.png-225ecd48e88f7c99a74b06cb880c2607.ctex"
size = Vector2(108, 88)
[node name="Dragon" type="Node2D" node_paths=PackedStringArray("hat", "shirt", "decor", "color")]
script = ExtResource("1_oaoux")
hat = NodePath("Sprite/Hat")
shirt = NodePath("Sprite/Shirt")
decor = NodePath("Sprite/Decor")
color = NodePath("Sprite")
hat = NodePath("Dragon/Hat")
shirt = NodePath("Dragon/Shirt")
decor = NodePath("Dragon/Decor")
color = NodePath("Dragon")
hat_outfits = ExtResource("2_mxc00")
shirt_outfits = ExtResource("3_umqeb")
decor_outfits = ExtResource("4_7b2ll")
@ -30,29 +27,22 @@ color_outfits = ExtResource("5_x2k4p")
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(38, 44)
position = Vector2(54, 44)
shape = SubResource("RectangleShape2D_oaoux")
[node name="Sprite" type="Sprite2D" parent="."]
position = Vector2(38, 44)
texture = SubResource("CompressedTexture2D_f0h1k")
[node name="Hat" type="Sprite2D" parent="Sprite"]
texture = ExtResource("3_oaoux")
[node name="Shirt" type="Sprite2D" parent="Sprite"]
texture = ExtResource("4_oaoux")
[node name="Decor" type="Sprite2D" parent="Sprite"]
texture = ExtResource("5_stf6f")
[node name="DragonBody" type="AnimatedSprite2D" parent="."]
visible = false
position = Vector2(36, 34)
[node name="Dragon" type="AnimatedSprite2D" parent="."]
position = Vector2(54, 34)
sprite_frames = ExtResource("6_yf7bj")
animation = &"idle"
autoplay = "idle"
frame_progress = 0.10072
[node name="Hat" type="AnimatedSprite2D" parent="Dragon"]
sprite_frames = ExtResource("10_7b2ll")
[node name="Shirt" type="AnimatedSprite2D" parent="Dragon"]
sprite_frames = ExtResource("11_x2k4p")
[node name="Decor" type="AnimatedSprite2D" parent="Dragon"]
sprite_frames = ExtResource("12_rhebu")
animation = &"walk"
[connection signal="mouse_entered" from="Area2D" to="." method="_on_area_2d_mouse_entered"]
[connection signal="mouse_exited" from="Area2D" to="." method="_on_area_2d_mouse_exited"]