add death sound and refactor jump sound

This commit is contained in:
2025-10-21 20:33:38 +01:00
parent a1b28ee5d3
commit 1fcc9a0a35
5 changed files with 13 additions and 47 deletions

View File

@@ -393,6 +393,7 @@ position_smoothing_enabled = true
position = Vector2(164, 165)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Killzone"]
position = Vector2(-3, -37)
shape = SubResource("WorldBoundaryShape2D_iywne")
[node name="Coins" type="Node" parent="."]

View File

@@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://dpox5fa2pojpo"]
[gd_scene load_steps=3 format=3 uid="uid://dpox5fa2pojpo"]
[ext_resource type="Script" uid="uid://cc1vfgnshjrgf" path="res://scripts/killzone.gd" id="1_xlapc"]
[ext_resource type="AudioStream" uid="uid://beoigk7eu8f6a" path="res://assets/sounds/hurt.wav" id="2_kl8fp"]
[node name="Killzone" type="Area2D"]
collision_mask = 2
@@ -10,5 +11,9 @@ script = ExtResource("1_xlapc")
wait_time = 0.6
one_shot = true
[node name="Death" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("2_kl8fp")
bus = &"SFX"
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=30 format=3 uid="uid://3wumh6kpw3ai"]
[gd_scene load_steps=27 format=3 uid="uid://3wumh6kpw3ai"]
[ext_resource type="Texture2D" uid="uid://pc081i405fo4" path="res://assets/sprites/knight.png" id="1_3vyb7"]
[ext_resource type="Script" uid="uid://dkpsredq14h2l" path="res://scripts/player.gd" id="1_g2els"]
@@ -172,43 +172,6 @@ animations = [{
[sub_resource type="CircleShape2D" id="CircleShape2D_fjrip"]
radius = 5.0
[sub_resource type="Animation" id="Animation_dqkch"]
resource_name = "jump"
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Jump:playing")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="Animation" id="Animation_qlg0r"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Jump: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_tuyoq"]
_data = {
&"RESET": SubResource("Animation_qlg0r"),
&"jump": SubResource("Animation_dqkch")
}
[node name="Player" type="CharacterBody2D"]
z_index = 5
collision_layer = 2
@@ -226,11 +189,6 @@ autoplay = "idle"
position = Vector2(0, -5)
shape = SubResource("CircleShape2D_fjrip")
[node name="Jump" type="AudioStreamPlayer2D" parent="."]
[node name="JumpSound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("3_qhqgy")
bus = &"SFX"
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_tuyoq")
}

View File

@@ -1,9 +1,11 @@
extends Area2D
@onready var timer: Timer = $Timer
@onready var death: AudioStreamPlayer2D = $Death
func _on_body_entered(player_body: Node2D) -> void:
print("You died.")
death.play()
Engine.time_scale = 0.5
player_body.get_node(NodeTypes.COLLISION_SHAPE_2D).queue_free()
var player_character_body = player_body as CharacterBody2D

View File

@@ -5,7 +5,7 @@ extends CharacterBody2D
@export var jump_velocity = -400.0
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var jump_sound: AudioStreamPlayer2D = $JumpSound
func _physics_process(delta: float) -> void:
# Add the gravity.
@@ -14,7 +14,7 @@ func _physics_process(delta: float) -> void:
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
animation_player.play("jump")
jump_sound.play()
velocity.y = jump_velocity
# Get the input direction and handle the movement/deceleration.