checking sounds
This commit is contained in:
parent
87878820af
commit
f276bb16db
5 changed files with 34 additions and 14 deletions
|
@ -25,7 +25,6 @@
|
|||
/processorParam:TextureFormat=Color
|
||||
/build:animation1.png
|
||||
|
||||
|
||||
#begin ButtonFont.spritefont
|
||||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
|
@ -33,6 +32,12 @@
|
|||
/processorParam:TextureFormat=Compressed
|
||||
/build:ButtonFont.spritefont
|
||||
|
||||
#begin DoomTestSong.mp3
|
||||
/importer:Mp3Importer
|
||||
/processor:SoundEffectProcessor
|
||||
/processorParam:Quality=Best
|
||||
/build:DoomTestSong.mp3
|
||||
|
||||
#begin Font_25.spritefont
|
||||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
|
|
BIN
DangerousD/Content/DoomTestSong.mp3
Normal file
BIN
DangerousD/Content/DoomTestSong.mp3
Normal file
Binary file not shown.
|
@ -23,11 +23,13 @@ namespace DangerousD.GameCore
|
|||
IDrawableObject OptionsGUI;
|
||||
IDrawableObject LoginGUI;
|
||||
IDrawableObject LobbyGUI;
|
||||
public Point inGameResolution;
|
||||
|
||||
public GameManager GameManager { get; private set; } = new GameManager();
|
||||
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
||||
public NetworkManager NetworkManager { get; private set; } = new NetworkManager();
|
||||
public InputManager InputManager { get; private set; } = new InputManager();
|
||||
public SoundManager SoundManager { get; private set; } = new SoundManager();
|
||||
public AppManager()
|
||||
{
|
||||
Instance = this;
|
||||
|
@ -60,6 +62,8 @@ namespace DangerousD.GameCore
|
|||
LobbyGUI.LoadContent();
|
||||
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
|
||||
SoundManager.LoadSounds();
|
||||
SoundManager.StartAmbientSound("DoomTestSong");
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
|
@ -68,6 +72,7 @@ namespace DangerousD.GameCore
|
|||
Exit();
|
||||
|
||||
InputManager.Update();
|
||||
SoundManager.Update();
|
||||
switch (gameState)
|
||||
{
|
||||
case GameState.Menu:
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace DangerousD.GameCore.Managers
|
|||
{
|
||||
internal class SettingsManager
|
||||
{
|
||||
public isFullScreen =false;
|
||||
public bool isFullScreen =false;
|
||||
public void SetResolution()
|
||||
{
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@ using System.IO;
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using System.Linq;
|
||||
using DangerousD.GameCore.Graphics;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DangerousD.GameCore
|
||||
{
|
||||
|
@ -12,23 +15,23 @@ namespace DangerousD.GameCore
|
|||
{
|
||||
public Dictionary<string, SoundEffectInstance> Sounds = new Dictionary<string, SoundEffectInstance>(); // словарь со звуками где строка - название файла
|
||||
public List<Sound> PlayingSounds = new List<Sound>(); // список со всеми звуками, которые проигрываются
|
||||
public string SoundDirectory = "Sounds"; // папка со звуками там где exe
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
sound.SoundEffect.IsLooped = false;
|
||||
sound.SoundEffect.Play();
|
||||
// sound.SoundEffect.Play();
|
||||
PlayingSounds.Add(sound);
|
||||
}
|
||||
|
||||
|
@ -47,14 +50,21 @@ namespace DangerousD.GameCore
|
|||
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)
|
||||
sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance;
|
||||
if (sound.SoundEffect.State == SoundState.Stopped)
|
||||
PlayingSounds.Remove(sound);
|
||||
foreach (var sound in PlayingSounds)
|
||||
{
|
||||
if (!sound.isAmbient)
|
||||
sound.SoundEffect.Volume = (float)sound.GetDistance(player.Pos) / MaxSoundDistance;
|
||||
if (sound.SoundEffect.State == SoundState.Stopped)
|
||||
PlayingSounds.Remove(sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue