checking sounds

This commit is contained in:
SergoDobro 2023-08-17 00:55:45 +03:00
parent 87878820af
commit f276bb16db
5 changed files with 34 additions and 14 deletions

View file

@ -25,7 +25,6 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:animation1.png /build:animation1.png
#begin ButtonFont.spritefont #begin ButtonFont.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor
@ -33,6 +32,12 @@
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Compressed
/build:ButtonFont.spritefont /build:ButtonFont.spritefont
#begin DoomTestSong.mp3
/importer:Mp3Importer
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:DoomTestSong.mp3
#begin Font_25.spritefont #begin Font_25.spritefont
/importer:FontDescriptionImporter /importer:FontDescriptionImporter
/processor:FontDescriptionProcessor /processor:FontDescriptionProcessor

Binary file not shown.

View file

@ -23,11 +23,13 @@ namespace DangerousD.GameCore
IDrawableObject OptionsGUI; IDrawableObject OptionsGUI;
IDrawableObject LoginGUI; IDrawableObject LoginGUI;
IDrawableObject LobbyGUI; IDrawableObject LobbyGUI;
public Point inGameResolution;
public GameManager GameManager { get; private set; } = new GameManager(); public GameManager GameManager { get; private set; } = new GameManager();
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder(); public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
public NetworkManager NetworkManager { get; private set; } = new NetworkManager(); public NetworkManager NetworkManager { get; private set; } = new NetworkManager();
public InputManager InputManager { get; private set; } = new InputManager(); public InputManager InputManager { get; private set; } = new InputManager();
public SoundManager SoundManager { get; private set; } = new SoundManager();
public AppManager() public AppManager()
{ {
Instance = this; Instance = this;
@ -60,6 +62,8 @@ namespace DangerousD.GameCore
LobbyGUI.LoadContent(); LobbyGUI.LoadContent();
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1); GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) }); GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
SoundManager.LoadSounds();
SoundManager.StartAmbientSound("DoomTestSong");
} }
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
@ -68,6 +72,7 @@ namespace DangerousD.GameCore
Exit(); Exit();
InputManager.Update(); InputManager.Update();
SoundManager.Update();
switch (gameState) switch (gameState)
{ {
case GameState.Menu: case GameState.Menu:

View file

@ -9,7 +9,7 @@ namespace DangerousD.GameCore.Managers
{ {
internal class SettingsManager internal class SettingsManager
{ {
public isFullScreen =false; public bool isFullScreen =false;
public void SetResolution() public void SetResolution()
{ {

View file

@ -5,6 +5,9 @@ using System.IO;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using System.Linq;
using DangerousD.GameCore.Graphics;
using Newtonsoft.Json;
namespace DangerousD.GameCore namespace DangerousD.GameCore
{ {
@ -12,23 +15,23 @@ namespace DangerousD.GameCore
{ {
public Dictionary<string, SoundEffectInstance> Sounds = new Dictionary<string, SoundEffectInstance>(); // словарь со звуками где строка - название файла public Dictionary<string, SoundEffectInstance> Sounds = new Dictionary<string, SoundEffectInstance>(); // словарь со звуками где строка - название файла
public List<Sound> PlayingSounds = new List<Sound>(); // список со всеми звуками, которые проигрываются public List<Sound> PlayingSounds = new List<Sound>(); // список со всеми звуками, которые проигрываются
public string SoundDirectory = "Sounds"; // папка со звуками там где exe
public float MaxSoundDistance = 1500; // максимальная дальность звука public float MaxSoundDistance = 1500; // максимальная дальность звука
public void LoadSounds(ContentManager content) // метод для загрузки звуков из папки public void LoadSounds() // метод для загрузки звуков из папки
{ {
var soundFiles = Directory.GetFiles(SoundDirectory); string[] soundFiles = Directory.GetFiles("../../../Content").Where(x=>x.EndsWith("mp3")).Select(x=>x.Split("\\").Last().Replace(".mp3", "")).ToArray();// папка со звуками там где exe
foreach (var soundFile in soundFiles) foreach (var soundFile in soundFiles)
{ {
Sounds.Add(soundFile, content.Load<SoundEffectInstance>(soundFile)); Sounds.Add(soundFile, AppManager.Instance.Content.Load<SoundEffect>(soundFile).CreateInstance());
} }
} }
public void StartSound(string soundName) // запустить звук у которого нет позиции public void StartAmbientSound(string soundName) // запустить звук у которого нет позиции
{ {
var sound = new Sound(Sounds[soundName]); var sound = new Sound(Sounds[soundName]);
sound.SoundEffect.IsLooped = false; sound.SoundEffect.IsLooped = false;
sound.SoundEffect.Play(); // sound.SoundEffect.Play();
PlayingSounds.Add(sound); PlayingSounds.Add(sound);
} }
@ -47,14 +50,21 @@ namespace DangerousD.GameCore
PlayingSounds.Clear(); PlayingSounds.Clear();
} }
public void Update(Vector2 playerPos) // апдейт, тут происходит изменение громкости
public void Update() // апдейт, тут происходит изменение громкости
{ {
foreach (var sound in PlayingSounds)
var player = AppManager.Instance.GameManager.GetPlayer1;
if (player != null)
{ {
if (!sound.isAmbient) foreach (var sound in PlayingSounds)
sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance; {
if (sound.SoundEffect.State == SoundState.Stopped) if (!sound.isAmbient)
PlayingSounds.Remove(sound); sound.SoundEffect.Volume = (float)sound.GetDistance(player.Pos) / MaxSoundDistance;
if (sound.SoundEffect.State == SoundState.Stopped)
PlayingSounds.Remove(sound);
}
} }
} }
} }