Player crash when hit comet

This commit is contained in:
Rain Clark 2024-05-12 01:03:18 -04:00
parent 41dc281b66
commit c7ce3be782
6 changed files with 98 additions and 1 deletions

BIN
assets/sfx/explosion.wav Normal file

Binary file not shown.

View File

@ -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

View File

@ -12,3 +12,11 @@ func _ready() -> void:
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
rotate(deg_to_rad(rotaion_direction * rotation_speed * delta)) 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()

View File

@ -11,3 +11,5 @@ texture = ExtResource("1_6q67h")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] [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) 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"]

View File

@ -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="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="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://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"]] [node name="Ship" type="CharacterBody2D" groups=["ship"]]
collision_mask = 2 collision_mask = 2
@ -34,4 +85,12 @@ position = Vector2(0, -33)
[node name="ShootSound" type="AudioStreamPlayer" parent="."] [node name="ShootSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3_kvryg") 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"] [connection signal="timeout" from="ShotCooldown" to="." method="_on_shot_cooldown_timeout"]

View File

@ -42,5 +42,9 @@ func fire_gun(pos : Vector2, rot : float) -> void:
can_shoot = false can_shoot = false
$ShotCooldown.start() $ShotCooldown.start()
func crash():
$AnimationPlayer.play("crash")
func _on_shot_cooldown_timeout() -> void: func _on_shot_cooldown_timeout() -> void:
can_shoot = true can_shoot = true