Adding background music and sfx

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
Ethan Wellenreiter 2025-01-04 23:03:50 -05:00
parent 319a8ce7b9
commit ec30b8e972
14 changed files with 108 additions and 3 deletions

Binary file not shown.

BIN
assets/sound/jump.aup3 Normal file

Binary file not shown.

BIN
assets/sound/jump.mp3 Normal file

Binary file not shown.

BIN
assets/sound/run.aup3 Normal file

Binary file not shown.

BIN
assets/sound/run.mp3 Normal file

Binary file not shown.

BIN
assets/sound/shoot.aup3 Normal file

Binary file not shown.

BIN
assets/sound/shoot.mp3 Normal file

Binary file not shown.

View File

@ -0,0 +1,32 @@
extends Node2D
class_name PlayerAudio
@onready var jump : AudioStreamPlayer = $Jump
@onready var shoot : AudioStreamPlayer = $Shoot
@onready var run : AudioStreamPlayer = $Run
@onready var slide : AudioStreamPlayer = $Slide
@export var mute : bool = false
@onready var sound_names : Dictionary = {"jump": jump, "shoot":shoot, "run":run, "slide":slide}
func play_sound(sound_name: String) -> void:
if not mute:
if sound_names.has(sound_name):
#print(shoot)
#print(sound_names["shoot"])
#print(sound_names[sound_name])
#print(sound_name)
sound_names[sound_name].play()
func is_playing(sound_name: String)->bool:
if sound_names.has(sound_name):
return sound_names[sound_name].playing
return false
func stop_sound(sound_name: String) -> void:
if sound_names.has(sound_name):
sound_names[sound_name].stop()

View File

@ -20,6 +20,7 @@ func _process(delta: float) -> void:
if Input.is_action_just_pressed("fire"):
#print("hi")
if (not player.on_rope):
%PlayerAudio.play_sound("shoot")
#fire rope
#vec2 aim_pos = get_global_mouse_position()

View File

@ -80,12 +80,30 @@ func _physics_process(delta: float) -> void:
else:
#reset sprite orientation here
$CollisionShape2D.shape = load("res://assets/normal_shape.tres")
sprite.rotation = 0
$CollisionShape2D.transform = Transform2D(0,Vector2(-1.5,-0.5))
if sprite.animation == "swing":
sprite.play("mid_air")
if velocity.x < 0:
sprite.flip_h = true
elif velocity.x > 0:
sprite.flip_h = false
#print("hi")
$CollisionShape2D.shape = load("res://assets/mid_air_shape.tres")
$CollisionShape2D.transform = Transform2D(0,Vector2(-2,16))
elif sprite.animation != "mid_air" or is_on_floor():
if velocity.x < 0:
sprite.flip_h = true
elif velocity.x > 0:
sprite.flip_h = false
if abs(velocity.x) > 0:
sprite.play("run")
$CollisionShape2D.shape = load("res://assets/normal_shape.tres")
$CollisionShape2D.transform = Transform2D(0,Vector2(-1.5,-0.5))
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
%PlayerAudio.play_sound("jump")
velocity.y = JUMP_VELOCITY
var direction := Input.get_axis("move_left", "move_right") ## walking left and right
@ -105,6 +123,13 @@ func _physics_process(delta: float) -> void:
sprite.flip_h = true
else:
velocity.x = move_toward(velocity.x, 0, SLOW_SPEED_MULTIPLIER*WALK_SPEED*delta)
if abs(velocity.x) > 0:
#print("hi")
if not %PlayerAudio.is_playing("run"):
%PlayerAudio.play_sound("run")
else:
%PlayerAudio.stop_sound("run")
else:
if direction:
var acting_speed : float = MID_AIR_MOVEMENT_SPEED
@ -113,6 +138,7 @@ func _physics_process(delta: float) -> void:
if abs(velocity.x + (direction * delta * acting_speed)) < MID_AIR_MOVEMENT_SPEED:
velocity.x = clamp(velocity.x + (direction*delta*acting_speed), -MID_AIR_MOVEMENT_SPEED, MID_AIR_MOVEMENT_SPEED)
move_and_slide()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://brhc07imuholv"]
[gd_scene load_steps=21 format=3 uid="uid://brhc07imuholv"]
[ext_resource type="Texture2D" uid="uid://87gegwimvax2" path="res://assets/test_player.png" id="1_0ushe"]
[ext_resource type="Script" path="res://player/player.gd" id="1_x227h"]
@ -12,11 +12,13 @@
[ext_resource type="Texture2D" uid="uid://brwxhphgmui7h" path="res://assets/idle-4.png" id="5_y7yb1"]
[ext_resource type="Texture2D" uid="uid://dmsx3wyah7tqv" path="res://assets/run-2.png" id="6_fq4sj"]
[ext_resource type="Texture2D" uid="uid://besblp1nasfcg" path="res://assets/idle-5.png" id="6_rcurq"]
[ext_resource type="Texture2D" uid="uid://d1g75ao0kljjq" path="res://assets/mid_air.png" id="7_8p4j7"]
[ext_resource type="Texture2D" uid="uid://dekab4yvffotr" path="res://assets/run-3.png" id="7_gyyvx"]
[ext_resource type="Texture2D" uid="uid://ca8fxmbredrie" path="res://assets/run-4.png" id="8_0s8qb"]
[ext_resource type="Texture2D" uid="uid://cyfnxnbpgw3ig" path="res://assets/run-5.png" id="9_k0qre"]
[ext_resource type="Texture2D" uid="uid://bkaop26r76o40" path="res://assets/swing.png" id="12_dxoth"]
[ext_resource type="Shape2D" uid="uid://bgprpaxew08jq" path="res://assets/normal_shape.tres" id="14_fhcn0"]
[ext_resource type="PackedScene" uid="uid://iuh6ib27bgq7" path="res://player/player_audio.tscn" id="18_708qa"]
[sub_resource type="SpriteFrames" id="SpriteFrames_1bpu4"]
animations = [{
@ -42,6 +44,14 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("7_8p4j7")
}],
"loop": true,
"name": &"mid_air",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("5_00etc")
}, {
"duration": 1.0,
@ -103,6 +113,9 @@ position = Vector2(83, 0)
scale = Vector2(0.266667, 0.266667)
texture = ExtResource("4_c2t2l")
[node name="PlayerAudio" parent="Player" instance=ExtResource("18_708qa")]
unique_name_in_owner = true
[node name="Rope" type="Node2D" parent="."]
unique_name_in_owner = true
script = ExtResource("5_thjoo")

23
player/player_audio.tscn Normal file
View File

@ -0,0 +1,23 @@
[gd_scene load_steps=5 format=3 uid="uid://iuh6ib27bgq7"]
[ext_resource type="Script" path="res://player/audio_controller.gd" id="1_3ua83"]
[ext_resource type="AudioStream" uid="uid://h7qpmq6tvh3m" path="res://assets/sound/jump.mp3" id="2_h8t3a"]
[ext_resource type="AudioStream" uid="uid://de05xt6vytief" path="res://assets/sound/shoot.mp3" id="2_v5h44"]
[ext_resource type="AudioStream" uid="uid://eppyw8gdo560" path="res://assets/sound/run.mp3" id="4_8jpbn"]
[node name="PlayerAudio" type="Node2D"]
script = ExtResource("1_3ua83")
[node name="Jump" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_h8t3a")
volume_db = -10.0
[node name="Shoot" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_v5h44")
volume_db = -5.0
[node name="Run" type="AudioStreamPlayer" parent="."]
stream = ExtResource("4_8jpbn")
volume_db = -10.0
[node name="Slide" type="AudioStreamPlayer" parent="."]

View File

@ -18,6 +18,7 @@ config/icon="res://icon.svg"
[autoload]
Universe="*res://world/universe/universe.gd"
BackgroundMusic="*res://world/background_music.tscn"
[display]

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://dgsll441ctpno"]
[ext_resource type="AudioStream" uid="uid://cail44kwspy30" path="res://assets/sound/Background_Music_local_game_jam.mp3" id="1_ri7ye"]
[node name="AudioStreamPlayer" type="AudioStreamPlayer"]
stream = ExtResource("1_ri7ye")
volume_db = -15.0
autoplay = true
parameters/looping = true