minoryrefectlring

This commit is contained in:
SergoDobro 2023-08-17 02:08:34 +03:00
parent dca6928daf
commit 634a986e70
3 changed files with 86 additions and 23 deletions

View file

@ -8,6 +8,8 @@ using DangerousD.GameCore.GUI;
using Microsoft.Xna.Framework.Input;
using DangerousD.GameCore.Graphics;
using DangerousD.GameCore.Network;
using MonogameLibrary.UI.Base;
using DangerousD.GameCore.Managers;
namespace DangerousD.GameCore
{
@ -17,19 +19,21 @@ namespace DangerousD.GameCore
public static AppManager Instance { get; private set; }
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public Point resolution;
GameState gameState;
IDrawableObject MenuGUI;
IDrawableObject OptionsGUI;
IDrawableObject LoginGUI;
IDrawableObject LobbyGUI;
public Point inGameResolution;
public Point resolution = new Point(1920, 1080);
public Point inGameResolution = new Point(800, 480);
private RenderTarget2D renderTarget;
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 SettingsManager SettingsManager { get; private set; } = new SettingsManager();
public AppManager()
{
Instance = this;
@ -38,11 +42,19 @@ namespace DangerousD.GameCore
IsMouseVisible = true;
TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / 30);
resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight);
SettingsManager = new SettingsManager();
SettingsManager.LoadSettings();
resolution = SettingsManager.Resolution;
_graphics.PreferredBackBufferWidth = resolution.X;
_graphics.PreferredBackBufferHeight = resolution.Y;
// _graphics.IsFullScreen = true;
gameState = GameState.Menu;
MenuGUI = new MenuGUI();
LoginGUI = new LoginGUI();
LobbyGUI = new LobbyGUI();
UIManager.resolution = resolution;
UIManager.resolutionInGame = inGameResolution;
}
protected override void Initialize()
@ -64,6 +76,7 @@ namespace DangerousD.GameCore
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
SoundManager.LoadSounds();
SoundManager.StartAmbientSound("DoomTestSong");
renderTarget = new RenderTarget2D(GraphicsDevice, inGameResolution.X, inGameResolution.Y);
}
protected override void Update(GameTime gameTime)
@ -117,13 +130,17 @@ namespace DangerousD.GameCore
LobbyGUI.Draw(_spriteBatch);
break;
case GameState.Game:
_spriteBatch.Begin(SpriteSortMode.Deferred,null,SamplerState.PointClamp);
_spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
GameManager.Draw(_spriteBatch);
_spriteBatch.End();
break;
default:
break;
}
GraphicsDevice.SetRenderTarget(null);
_spriteBatch.Begin();
_spriteBatch.Draw(renderTarget, new Rectangle(0, 0, _graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight), Color.White);
_spriteBatch.End();
base.Draw(gameTime);

View file

@ -1,31 +1,77 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Microsoft.Xna;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
namespace DangerousD.GameCore.Managers
{
internal class SettingsManager
public class SettingsManager
{
public bool isFullScreen =false;
public void SetResolution()
private SettingsContainer settingsContainer= new SettingsContainer();
public bool IsFullScreen { get => settingsContainer.IsFullScreen; }
public float MainVolume { get => settingsContainer.MainVolume; }
public float MusicVolume { get => settingsContainer.MusicVolume; }
public float SoundEffectsVolume { get => settingsContainer.SoundEffectsVolume; }
public Point Resolution { get => settingsContainer.Resolution; }
public void SetResolution(Point resolution)
{
settingsContainer.Resolution = resolution;
}
public void SetMainVolume(float volume)
{
settingsContainer.MainVolume = MainVolume;
}
public void SetMainVolume()
public void SetMusicVolume(float volume)
{
settingsContainer.MusicVolume = MainVolume;
}
public void SetMusicVolume()
public void SetSoundEffectsVolume(float volume)
{
settingsContainer.SoundEffectsVolume = MainVolume;
}
public void SetIsFullScreen(bool isFullScreen)
{
settingsContainer.IsFullScreen = isFullScreen;
}
public void LoadSettings()
{
if (!File.Exists("GameSettings.txt"))
{
File.Create("GameSettings.txt");
SaveSettings();
return;
}
var serializedObject = JsonConvert.DeserializeObject<SettingsContainer>(File.ReadAllText("GameSettings.txt"));
}
public void SaveSettings()
{
if (!File.Exists("GameSettings.txt"))
File.Create("GameSettings.txt");
File.WriteAllText("GameSettings.txt", JsonConvert.SerializeObject(settingsContainer));
}
}
public class SettingsContainer
{
[JsonProperty("IsFullScreen")]
public bool IsFullScreen { get; set; } = false;
[JsonProperty("MainVolume")]
public float MainVolume { get; set; } = 1;
[JsonProperty("MusicVolume")]
public float MusicVolume { get; set; } = 1;
[JsonProperty("SoundEffectsVolume")]
public float SoundEffectsVolume { get; set; } = 1;
[JsonProperty("Resolution")]
public Point Resolution { get; set; } = new Point(1920,1080);
}
}

View file

@ -31,7 +31,7 @@ namespace DangerousD.GameCore
{
var sound = new Sound(Sounds[soundName]);
sound.SoundEffect.IsLooped = false;
// sound.SoundEffect.Play();
sound.SoundEffect.Play();
PlayingSounds.Add(sound);
}
@ -42,7 +42,7 @@ namespace DangerousD.GameCore
sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance;
sound.SoundEffect.Play();
PlayingSounds.Add(sound);
}//GameManager.SendSound
}
public void StopAllSounds() // остановка всех звуков
{
foreach (var sound in PlayingSounds)
@ -58,12 +58,12 @@ namespace DangerousD.GameCore
var player = AppManager.Instance.GameManager.GetPlayer1;
if (player != null)
{
foreach (var sound in PlayingSounds)
for (int i = 0; i < PlayingSounds.Count; i++)
{
if (!sound.isAmbient)
sound.SoundEffect.Volume = (float)sound.GetDistance(player.Pos) / MaxSoundDistance;
if (sound.SoundEffect.State == SoundState.Stopped)
PlayingSounds.Remove(sound);
if (!PlayingSounds[i].isAmbient)
PlayingSounds[i].SoundEffect.Volume = (float)PlayingSounds[i].GetDistance(player.Pos) / MaxSoundDistance;
if (PlayingSounds[i].SoundEffect.State == SoundState.Stopped)
PlayingSounds.Remove(PlayingSounds[i]);
}
}
}