added damage flash to asteroids

asteroid will flash before being destroyed.
This commit is contained in:
Red3Tango 2023-12-12 15:45:42 -07:00
parent 4571943fe1
commit d3a0de2cea
2 changed files with 34 additions and 1 deletions

View File

@ -7,6 +7,7 @@ var start_spin: float = 0.0
var health: int = 0
@onready var ttl: Timer = $TTL
@onready var sprite_2d: Sprite2D = $Sprite2D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
func _ready() -> void:
@ -19,6 +20,8 @@ func _ready() -> void:
func take_damage() -> void:
animation_player.play("flash")
await animation_player.animation_finished
health -= 1
if health <= 0:
queue_free()

View File

@ -1,16 +1,40 @@
[gd_scene load_steps=3 format=3 uid="uid://pqyv83m76jeq"]
[gd_scene load_steps=6 format=3 uid="uid://pqyv83m76jeq"]
[ext_resource type="Script" path="res://prefabs/asteroid/asteroid.gd" id="1_f7xce"]
[ext_resource type="Texture2D" uid="uid://dkr1igpw1hfnn" path="res://icon.svg" id="2_0eret"]
[sub_resource type="CircleShape2D" id="CircleShape2D_58hxo"]
resource_local_to_scene = true
[sub_resource type="Animation" id="Animation_oi28q"]
resource_name = "flash"
length = 0.06
step = 0.01
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:self_modulate:v")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.03, 0.06),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [1.0, 10.0, 1.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_t2fgx"]
_data = {
"flash": SubResource("Animation_oi28q")
}
[node name="Asteroid" type="RigidBody2D"]
linear_damp_mode = 1
angular_damp_mode = 1
script = ExtResource("1_f7xce")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_0eret")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_58hxo")
@ -22,6 +46,12 @@ wait_time = 4.0
one_shot = true
autostart = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
reset_on_save = false
libraries = {
"": SubResource("AnimationLibrary_t2fgx")
}
[connection signal="screen_entered" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_entered"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_screen_exited"]
[connection signal="timeout" from="TTL" to="." method="queue_free"]