GameOver sound
parent
e873873a78
commit
fd2c37f30b
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Godot.NET.Sdk/4.2.0-beta.3">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@ -1,26 +1,78 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Godot;
|
||||
|
||||
namespace Scripts;
|
||||
|
||||
public partial class SoundManager : Node {
|
||||
[Export] private AudioStreamPlayer backgroundMusic;
|
||||
[Export] private AudioStreamPlayer3D explosionSound;
|
||||
[Export] private AudioStreamPlayer gameOverMusic;
|
||||
[Export] private AudioStreamPlayer3D asteroidExplosionSound;
|
||||
[Export] private AudioStreamPlayer3D playerExplosionSound;
|
||||
[Export] private AudioStreamPlayer3D laserSound;
|
||||
|
||||
public static SoundManager Instance { get; private set; }
|
||||
|
||||
public override void _Ready() {
|
||||
Instance = this;
|
||||
public enum Sound {
|
||||
BackgroundMusic,
|
||||
AsteroidExplosion,
|
||||
PlayerExplosion,
|
||||
Laser,
|
||||
GameOver
|
||||
}
|
||||
|
||||
public void PlayExplosion(Vector3 position) {
|
||||
explosionSound.Position = position;
|
||||
explosionSound.PitchScale = (float)GD.RandRange(0.25f, 1.75f);
|
||||
explosionSound.Play();
|
||||
public override void _Ready() => Instance = this;
|
||||
|
||||
public void Play(Sound sound, [Optional] Vector3 position) {
|
||||
float pitchScale = 0;
|
||||
if (sound is Sound.Laser or Sound.AsteroidExplosion or Sound.PlayerExplosion) pitchScale = (float)GD.RandRange(0.25f, 1.75f);
|
||||
|
||||
switch (sound) {
|
||||
case Sound.AsteroidExplosion:
|
||||
asteroidExplosionSound.Position = position;
|
||||
asteroidExplosionSound.PitchScale = pitchScale;
|
||||
asteroidExplosionSound.Play();
|
||||
break;
|
||||
case Sound.Laser:
|
||||
laserSound.Position = position;
|
||||
laserSound.PitchScale = pitchScale;
|
||||
laserSound.Play();
|
||||
break;
|
||||
case Sound.PlayerExplosion:
|
||||
playerExplosionSound.Position = position;
|
||||
playerExplosionSound.PitchScale = pitchScale;
|
||||
playerExplosionSound.Play();
|
||||
break;
|
||||
case Sound.BackgroundMusic:
|
||||
backgroundMusic.Play();
|
||||
break;
|
||||
case Sound.GameOver:
|
||||
gameOverMusic.Play();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(sound), sound, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayLaserSound(Vector3 position) {
|
||||
laserSound.Position = position;
|
||||
laserSound.PitchScale = (float)GD.RandRange(0.25f, 1.75f);
|
||||
laserSound.Play();
|
||||
public void Stop(Sound sound) {
|
||||
switch (sound) {
|
||||
case Sound.AsteroidExplosion:
|
||||
asteroidExplosionSound.Stop();
|
||||
break;
|
||||
case Sound.Laser:
|
||||
laserSound.Stop();
|
||||
break;
|
||||
case Sound.PlayerExplosion:
|
||||
playerExplosionSound.Stop();
|
||||
break;
|
||||
case Sound.BackgroundMusic:
|
||||
backgroundMusic.Stop();
|
||||
break;
|
||||
case Sound.GameOver:
|
||||
gameOverMusic.Stop();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(sound), sound, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://boo3vdjp3i3if"
|
||||
path="res://.godot/imported/gameover.wav-f2ebf5eb7584291f79759c2ab9f5cabc.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sounds/gameover.wav"
|
||||
dest_files=["res://.godot/imported/gameover.wav-f2ebf5eb7584291f79759c2ab9f5cabc.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=0
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://bspwjmgsoxkbn"
|
||||
path="res://.godot/imported/gameover2.wav-5f9b1f4fc6807498ae9eb6738b6d0ddf.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Sounds/gameover2.wav"
|
||||
dest_files=["res://.godot/imported/gameover2.wav-5f9b1f4fc6807498ae9eb6738b6d0ddf.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=0
|
||||
Loading…
Reference in New Issue