feat: sound effects & music

This commit is contained in:
2025-12-06 18:52:19 -05:00
Unverified
parent 6e8014f5e9
commit 7ee74478c3
31 changed files with 255 additions and 40 deletions

View File

@@ -3,7 +3,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
public partial class BoardScreen : Node2D {
public partial class BoardScreen : Node2D
{
[Export] private AudioStream endingSfx;
private const string RED_CHIP_PATH = "res://scenes/red_chip.tscn";
private const string YELLOW_CHIP_PATH = "res://scenes/yellow_chip.tscn";
@@ -24,9 +27,7 @@ public partial class BoardScreen : Node2D {
private Node2D player1Card;
private Node2D player2Card;
private MatchData matchData;
private List<(string, int)> moves;
private RigidBody2D[,] chips = new RigidBody2D[6, 7]; // 6 rows 7 cols | 0, 0 is top left
// Called when the node enters the scene tree for the first time.
@@ -102,7 +103,6 @@ public partial class BoardScreen : Node2D {
private void ObserveMove(string username, int column)
{
GD.Print(username);
if (username == matchData.player1)
{
player1Card.GetNode<Label>("Status").Hide();
@@ -139,6 +139,10 @@ public partial class BoardScreen : Node2D {
popup.Size = new Vector2I(200, 100);
var text = new Label();
text.Text = message;
var sfx = new AudioStreamPlayer();
sfx.Stream = endingSfx;
sfx.VolumeDb = -2;
popup.AddChild(sfx);
popup.AddChild(text);
text.GrowHorizontal = Control.GrowDirection.Both;
text.GrowVertical = Control.GrowDirection.Both;
@@ -146,7 +150,9 @@ public partial class BoardScreen : Node2D {
text.VerticalAlignment = VerticalAlignment.Center;
text.AnchorsPreset = (int) Control.LayoutPreset.FullRect;
popup.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
popup.PopupHide += () => popup.QueueFree();
GetTree().Root.AddChild(popup);
sfx.Play();
popup.Show();
TransitionToBracket();
}

View File

@@ -0,0 +1,8 @@
extends Node
func _ready() -> void:
var music = AudioStreamPlayer.new()
add_child(music)
music.stream = load("res://assets/music/jazz_music.mp3")
music.volume_db = -10
music.play()

View File

@@ -0,0 +1 @@
uid://hh10ct26xx1b

13
scripts/chip_sfx.gd Normal file
View File

@@ -0,0 +1,13 @@
extends RigidBody2D
@export var audio_stream_player_2d: AudioStreamPlayer2D
@export var velocity_for_sfx: float = 2.0
@export var sounds: Array[AudioStream]
func _on_body_entered(body: Node) -> void:
if body.name.begins_with("@RigidBody2D@") || body.name.begins_with("Floor"):
var rng = RandomNumberGenerator.new()
rng.randomize()
var index = rng.randi_range(0, sounds.size() - 1)
audio_stream_player_2d.stream = sounds[index]
audio_stream_player_2d.play();

View File

@@ -1,12 +0,0 @@
extends RigidBody2D
var color_ = "red";
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass

View File

@@ -1,12 +0,0 @@
extends RigidBody2D
var color_ = "yellow";
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass

View File

@@ -1 +0,0 @@
uid://ddg7dv686sbrb