MergeFixCommit
This commit is contained in:
commit
1ea1113bfb
7 changed files with 118 additions and 36 deletions
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||
using DangerousD.GameCore.Managers;
|
||||
using MonogameLibrary.UI.Base;
|
||||
using System.Diagnostics;
|
||||
using DangerousD.GameCore.Network;
|
||||
|
||||
namespace DangerousD.GameCore.GUI
|
||||
{
|
||||
|
@ -32,8 +33,32 @@ namespace DangerousD.GameCore.GUI
|
|||
Elements.Add(new Label(Manager) { rectangle = new Rectangle(screenWidth / 30 * 2, screenHeight / 30 * 5,
|
||||
screenWidth / 30 * 26, screenHeight / 15 * 10) });
|
||||
|
||||
// Buttons
|
||||
// Buttons and ip textbox
|
||||
{
|
||||
TextBox searchBarTextBox = new TextBox(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(screenWidth / 30 * 14, screenHeight / 30,
|
||||
screenWidth / 30 * 10, screenHeight / 30 * 3),
|
||||
text = "ip",
|
||||
scale = 0.16f,
|
||||
fontColor = Color.Gray,
|
||||
fontName = "font2",
|
||||
textAligment = TextAligment.Left
|
||||
|
||||
};
|
||||
searchBarTextBox.TextChanged += input => {
|
||||
if (searchBarTextBox.fontColor == Color.Gray)
|
||||
{
|
||||
searchBarTextBox.text = ""; searchBarTextBox.fontColor = Color.Black;
|
||||
}
|
||||
};
|
||||
searchBarTextBox.StopChanging += input => {
|
||||
if (input.Length == 0)
|
||||
{
|
||||
searchBarTextBox.fontColor = Color.Gray;
|
||||
searchBarTextBox.text = "ip";
|
||||
}
|
||||
};
|
||||
Button backButton = new ButtonText(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(screenWidth / 30, screenHeight / 30, 60, 50),
|
||||
|
@ -56,6 +81,8 @@ namespace DangerousD.GameCore.GUI
|
|||
};
|
||||
hostButton.LeftButtonPressed += () => {
|
||||
|
||||
AppManager.Instance.NetworkManager.HostInit(AppManager.Instance.IpAddress);
|
||||
|
||||
};
|
||||
|
||||
Button refreshButton = new ButtonText(Manager)
|
||||
|
@ -79,7 +106,7 @@ namespace DangerousD.GameCore.GUI
|
|||
fontName = "font2"
|
||||
};
|
||||
joinSelectedButton.LeftButtonPressed += () => {
|
||||
|
||||
AppManager.Instance.NetworkManager.ClientInit(AppManager.Instance.IpAddress);
|
||||
};
|
||||
Button joinByIpButton = new ButtonText(Manager)
|
||||
{
|
||||
|
@ -90,34 +117,7 @@ namespace DangerousD.GameCore.GUI
|
|||
fontName = "font2"
|
||||
};
|
||||
joinByIpButton.LeftButtonPressed += () => {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// SearchBar
|
||||
{
|
||||
TextBox searchBarTextBox = new TextBox(Manager) {
|
||||
rectangle = new Rectangle(screenWidth / 30 * 14, screenHeight / 30,
|
||||
screenWidth / 30 * 10, screenHeight / 30 * 3),
|
||||
text = "ip",
|
||||
scale = 0.16f,
|
||||
fontColor = Color.Gray,
|
||||
fontName = "font2",
|
||||
textAligment = TextAligment.Left
|
||||
|
||||
};
|
||||
searchBarTextBox.TextChanged += input => {
|
||||
if (searchBarTextBox.fontColor == Color.Gray)
|
||||
{
|
||||
searchBarTextBox.text = ""; searchBarTextBox.fontColor = Color.Black;
|
||||
}
|
||||
};
|
||||
searchBarTextBox.StopChanging += input => {
|
||||
if (input.Length == 0)
|
||||
{
|
||||
searchBarTextBox.fontColor = Color.Gray;
|
||||
searchBarTextBox.text = "ip";
|
||||
}
|
||||
AppManager.Instance.NetworkManager.ClientInit(searchBarTextBox.text);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ internal class MenuGUI : AbstractGui
|
|||
butSingle.LeftButtonPressed += () =>
|
||||
{
|
||||
AppManager.Instance.ChangeGameState(GameState.Game);
|
||||
AppManager.Instance.SetMultiplayerState(MultiPlayerStatus.SinglePlayer);
|
||||
};
|
||||
var butMulti = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, 190, 300, 50), text = "Multiplayer", fontName = "ButtonFont" };
|
||||
Elements.Add(butMulti);
|
||||
|
|
|
@ -14,12 +14,15 @@ using DangerousD.GameCore.Managers;
|
|||
namespace DangerousD.GameCore
|
||||
{
|
||||
public enum GameState { Menu, Options, Lobby, Game, Login, GameOver }
|
||||
public enum MultiPlayerStatus { SinglePlayer, Host, Client }
|
||||
public class AppManager : Game
|
||||
{
|
||||
public static AppManager Instance { get; private set; }
|
||||
public string IpAddress { get; private set; } = "127.0.0.1";
|
||||
private GraphicsDeviceManager _graphics;
|
||||
private SpriteBatch _spriteBatch;
|
||||
GameState gameState;
|
||||
public GameState gameState { get; private set; }
|
||||
public MultiPlayerStatus multiPlayerStatus { get; private set; }
|
||||
IDrawableObject MenuGUI;
|
||||
IDrawableObject OptionsGUI;
|
||||
IDrawableObject LoginGUI;
|
||||
|
@ -45,6 +48,8 @@ namespace DangerousD.GameCore
|
|||
SettingsManager = new SettingsManager();
|
||||
SettingsManager.LoadSettings();
|
||||
|
||||
NetworkManager.GetReceivingMessages += NetworkSync;
|
||||
|
||||
resolution = SettingsManager.Resolution;
|
||||
_graphics.PreferredBackBufferWidth = resolution.X;
|
||||
_graphics.PreferredBackBufferHeight = resolution.Y;
|
||||
|
@ -169,5 +174,32 @@ namespace DangerousD.GameCore
|
|||
}
|
||||
}
|
||||
|
||||
public void NetworkSync(NetworkTask networkTask)
|
||||
{
|
||||
switch (networkTask.operation)
|
||||
{
|
||||
case NetworkTaskOperationEnum.TakeDamage:
|
||||
break;
|
||||
case NetworkTaskOperationEnum.SendSound:
|
||||
SoundManager.StartSound(networkTask.name, networkTask.position, GameManager.GetPlayer1.Pos);
|
||||
break;
|
||||
case NetworkTaskOperationEnum.CreateEntity:
|
||||
break;
|
||||
case NetworkTaskOperationEnum.SendPosition:
|
||||
break;
|
||||
case NetworkTaskOperationEnum.ChangeState:
|
||||
break;
|
||||
case NetworkTaskOperationEnum.ConnectToHost:
|
||||
break;
|
||||
case NetworkTaskOperationEnum.GetClientPlayerId:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void SetMultiplayerState(MultiPlayerStatus multiPlayerStatus)
|
||||
{
|
||||
this.multiPlayerStatus = multiPlayerStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace DangerousD.GameCore
|
|||
{
|
||||
public class GameManager
|
||||
{
|
||||
|
||||
public List<GameObject> GetAllGameObjects { get; private set; }
|
||||
public List<LivingEntity> livingEntities;
|
||||
public List<Entity> entities;
|
||||
public List<MapObject> mapObjects;
|
||||
|
@ -23,6 +23,7 @@ namespace DangerousD.GameCore
|
|||
public Player GetPlayer1 { get; private set; }
|
||||
public GameManager()
|
||||
{
|
||||
GetAllGameObjects = new List<GameObject>();
|
||||
livingEntities = new List<LivingEntity>();
|
||||
mapObjects = new List<MapObject>();
|
||||
entities = new List<Entity>();
|
||||
|
|
|
@ -206,5 +206,22 @@ namespace DangerousD.GameCore.Managers
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<GameObject> CheckRectangle(Rectangle rectangle, Type type)
|
||||
{
|
||||
var gameObjects = AppManager.Instance.GameManager.GetAllGameObjects;
|
||||
List<GameObject> intersected = new List<GameObject>();
|
||||
for (int i = 0; i < gameObjects.Count; i++)
|
||||
{
|
||||
if (gameObjects[i].GetType() == type)
|
||||
{
|
||||
if (gameObjects[i].Rectangle.Intersects(rectangle))
|
||||
{
|
||||
intersected.Add(gameObjects[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return intersected;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,8 +33,11 @@ namespace DangerousD.GameCore
|
|||
sound.SoundEffect.IsLooped = false;
|
||||
sound.SoundEffect.Play();
|
||||
PlayingSounds.Add(sound);
|
||||
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.Host)
|
||||
{
|
||||
AppManager.Instance.NetworkManager.SendMsg(new Network.NetworkTask(Vector2.Zero, soundName));
|
||||
}
|
||||
}
|
||||
|
||||
public void StartSound(string soundName, Vector2 soundPos, Vector2 playerPos) // запустить звук у которого есть позиция
|
||||
{
|
||||
var sound = new Sound(Sounds[soundName], soundPos);
|
||||
|
@ -42,6 +45,10 @@ namespace DangerousD.GameCore
|
|||
sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance;
|
||||
sound.SoundEffect.Play();
|
||||
PlayingSounds.Add(sound);
|
||||
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.Host)
|
||||
{
|
||||
AppManager.Instance.NetworkManager.SendMsg(new Network.NetworkTask(soundPos, soundName));
|
||||
}
|
||||
}
|
||||
public void StopAllSounds() // остановка всех звуков
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace DangerousD.GameCore.Network
|
|||
public NetworkTaskOperationEnum operation { get; set; }
|
||||
public string name { get; set; }
|
||||
public int value { get; set; }
|
||||
public bool isParam { get; set; }
|
||||
public int objId { get; set; }
|
||||
public Vector2 position { get; set; }
|
||||
public Vector2 velocity { get; set; }
|
||||
|
@ -102,5 +103,28 @@ namespace DangerousD.GameCore.Network
|
|||
operation = NetworkTaskOperationEnum.GetClientPlayerId;
|
||||
objId = PlayerId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Универсальный конструктор для нестандартных операций. То, что не нужно(кроме операции) делать null.
|
||||
/// </summary>
|
||||
/// <param name="operation"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="isParam"></param>
|
||||
/// <param name="objId"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="velocity"></param>
|
||||
/// <param name="type"></param>
|
||||
public NetworkTask(NetworkTaskOperationEnum operation, string name, int value, bool isParam, int objId, Vector2 position, Vector2 velocity, Type type)
|
||||
{
|
||||
this.operation = operation;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.isParam = isParam;
|
||||
this.objId = objId;
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue