diff --git a/assets/sfx/explosion.wav b/assets/sfx/explosion.wav new file mode 100644 index 0000000..323a0ac Binary files /dev/null and b/assets/sfx/explosion.wav differ diff --git a/assets/sfx/explosion.wav.import b/assets/sfx/explosion.wav.import new file mode 100644 index 0000000..d45a9b3 --- /dev/null +++ b/assets/sfx/explosion.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://cycpanck51dqd" +path="res://.godot/imported/explosion.wav-e1f35b1a1dc4bf25a23a1f22f1673be5.sample" + +[deps] + +source_file="res://assets/sfx/explosion.wav" +dest_files=["res://.godot/imported/explosion.wav-e1f35b1a1dc4bf25a23a1f22f1673be5.sample"] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/scenes/comet.gd b/scenes/comet.gd index 1a79093..cbafd72 100644 --- a/scenes/comet.gd +++ b/scenes/comet.gd @@ -12,3 +12,11 @@ func _ready() -> void: func _physics_process(delta: float) -> void: rotate(deg_to_rad(rotaion_direction * rotation_speed * delta)) + + + + +func _on_body_entered(body: Node2D) -> void: + print(body) + if body.is_in_group("ship"): + body.crash() diff --git a/scenes/comet.tscn b/scenes/comet.tscn index 0241d65..2a59d20 100644 --- a/scenes/comet.tscn +++ b/scenes/comet.tscn @@ -11,3 +11,5 @@ texture = ExtResource("1_6q67h") [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] polygon = PackedVector2Array(19, -27, 22, -25, 25, -24, 27, -21, 31, -17, 32, -3, 32, 27, 27, 30, -8, 29, -17, 28, -25, 26, -32, 22, -32, 18, -23, 8, -20, 7, -21, 2, -29, -17, -29, -26, -27, -29, -25, -32, -14, -32, 0, -30) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/ship.tscn b/scenes/ship.tscn index f67d734..4b999da 100644 --- a/scenes/ship.tscn +++ b/scenes/ship.tscn @@ -1,8 +1,59 @@ -[gd_scene load_steps=4 format=3 uid="uid://cbo47ftx0vcro"] +[gd_scene load_steps=8 format=3 uid="uid://cbo47ftx0vcro"] [ext_resource type="Script" path="res://scripts/ship.gd" id="1_japvq"] [ext_resource type="Texture2D" uid="uid://qcnuvee2jcp0" path="res://assets/img/ship.png" id="1_ymcdl"] [ext_resource type="AudioStream" uid="uid://cg6v2xvf4jkkv" path="res://assets/sfx/shoot.wav" id="3_kvryg"] +[ext_resource type="AudioStream" uid="uid://cycpanck51dqd" path="res://assets/sfx/explosion.wav" id="4_gdodt"] + +[sub_resource type="Animation" id="Animation_ctlro"] +resource_name = "crash" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CrashSound:playing") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [true] +} +tracks/1/type = "method" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath(".") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0.6), +"transitions": PackedFloat32Array(1), +"values": [{ +"args": [], +"method": &"queue_free" +}] +} + +[sub_resource type="Animation" id="Animation_qfhr1"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CrashSound:playing") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_3jmf3"] +_data = { +"RESET": SubResource("Animation_qfhr1"), +"crash": SubResource("Animation_ctlro") +} [node name="Ship" type="CharacterBody2D" groups=["ship"]] collision_mask = 2 @@ -34,4 +85,12 @@ position = Vector2(0, -33) [node name="ShootSound" type="AudioStreamPlayer" parent="."] stream = ExtResource("3_kvryg") +[node name="CrashSound" type="AudioStreamPlayer" parent="."] +stream = ExtResource("4_gdodt") + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_3jmf3") +} + [connection signal="timeout" from="ShotCooldown" to="." method="_on_shot_cooldown_timeout"] diff --git a/scripts/ship.gd b/scripts/ship.gd index b005e87..7c9f954 100644 --- a/scripts/ship.gd +++ b/scripts/ship.gd @@ -42,5 +42,9 @@ func fire_gun(pos : Vector2, rot : float) -> void: can_shoot = false $ShotCooldown.start() +func crash(): + $AnimationPlayer.play("crash") + + func _on_shot_cooldown_timeout() -> void: can_shoot = true