Ajout d'animation de plante

This commit is contained in:
Zacharie Guet 2024-09-01 19:46:39 +02:00
parent e7c469d0ae
commit ebcea9f687
2 changed files with 48 additions and 7 deletions

View File

@ -1,17 +1,13 @@
[gd_scene load_steps=6 format=3 uid="uid://x4kv2y5f52cm"]
[gd_scene load_steps=8 format=3 uid="uid://x4kv2y5f52cm"]
[ext_resource type="Script" path="res://scripts/plant.gd" id="1_drvq1"]
[ext_resource type="Texture2D" uid="uid://b3kjaw1hajc6s" path="res://assets/grille_seeds.png" id="1_n5onq"]
[sub_resource type="AtlasTexture" id="AtlasTexture_5did5"]
atlas = ExtResource("1_n5onq")
region = Rect2(810, 540, 270, 270)
[ext_resource type="Texture2D" uid="uid://br1olfut3p0tx" path="res://assets/plants/evolution1.1.png" id="2_gm8i8"]
[sub_resource type="SpriteFrames" id="SpriteFrames_667un"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_5did5")
"texture": ExtResource("2_gm8i8")
}],
"loop": true,
"name": &"SEED",
@ -21,6 +17,43 @@ animations = [{
[sub_resource type="CircleShape2D" id="CircleShape2D_jksuk"]
radius = 36.0
[sub_resource type="Animation" id="Animation_3rkca"]
resource_name = "Growing"
length = 0.3
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("AnimatedSprite2D:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.133333, 0.3),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector2(0.1, 0.05), Vector2(0.122, 0.3), Vector2(0.2, 0.2)]
}
[sub_resource type="Animation" id="Animation_j53j8"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("AnimatedSprite2D:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0.2, 0.2)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_cop0v"]
_data = {
"Growing": SubResource("Animation_3rkca"),
"RESET": SubResource("Animation_j53j8")
}
[node name="Plant" type="Node2D"]
script = ExtResource("1_drvq1")
@ -45,6 +78,11 @@ offset = Vector2(0, -250)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("CircleShape2D_jksuk")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_cop0v")
}
[connection signal="timeout" from="Growing" to="." method="_on_growing_timeout"]
[connection signal="timeout" from="NeedChecker" to="." method="_on_need_checker_timeout"]
[connection signal="timeout" from="SaplingCountDown" to="." method="_on_sapling_count_down_timeout"]

View File

@ -76,6 +76,7 @@ func plant(new_position: Vector2):
state = PlantState.SAPLING
growing_timer.start(parameter.growing_time)
sprite_node.play("SAPLING")
$AnimationPlayer.play("Growing")
func grow():
@ -102,6 +103,7 @@ func grow():
grown.emit()
sprite_node.play("GROWN")
$AnimationPlayer.play("Growing")
func die():
@ -122,6 +124,7 @@ func die():
growing_timer.start(parameter.dead_time)
died.emit()
sprite_node.play("DEAD")
$AnimationPlayer.play("Growing")
func remove(was_dead: bool = true):
if was_dead: