feat: sound effects & music
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
8
scripts/background_music.gd
Normal file
8
scripts/background_music.gd
Normal 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()
|
||||
1
scripts/background_music.gd.uid
Normal file
1
scripts/background_music.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://hh10ct26xx1b
|
||||
13
scripts/chip_sfx.gd
Normal file
13
scripts/chip_sfx.gd
Normal 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();
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1 +0,0 @@
|
||||
uid://ddg7dv686sbrb
|
||||
Reference in New Issue
Block a user