From a1b28ee5d3b0e0b12a9ecc026eafebbe33caaf18 Mon Sep 17 00:00:00 2001 From: Foohoo Date: Tue, 21 Oct 2025 20:28:54 +0100 Subject: [PATCH] add jumping sound --- scenes/player.tscn | 49 +++++++++++++++++++++++++++++++++++++++++++++- scripts/player.gd | 2 ++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/scenes/player.tscn b/scenes/player.tscn index 2ce3f08..540b3da 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=26 format=3 uid="uid://3wumh6kpw3ai"] +[gd_scene load_steps=30 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"] +[ext_resource type="AudioStream" uid="uid://bkby1mto2lk2a" path="res://assets/sounds/jump.wav" id="3_qhqgy"] [sub_resource type="AtlasTexture" id="AtlasTexture_g2els"] atlas = ExtResource("1_3vyb7") @@ -171,6 +172,43 @@ 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 @@ -187,3 +225,12 @@ autoplay = "idle" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -5) shape = SubResource("CircleShape2D_fjrip") + +[node name="Jump" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource("3_qhqgy") +bus = &"SFX" + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +&"": SubResource("AnimationLibrary_tuyoq") +} diff --git a/scripts/player.gd b/scripts/player.gd index 5d753f4..f47eb6e 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -5,6 +5,7 @@ extends CharacterBody2D @export var jump_velocity = -400.0 @onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D +@onready var animation_player: AnimationPlayer = $AnimationPlayer func _physics_process(delta: float) -> void: # Add the gravity. @@ -13,6 +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") velocity.y = jump_velocity # Get the input direction and handle the movement/deceleration.