Merge branch 'Development' into hot_fix2

This commit is contained in:
polten0 2024-08-17 03:09:04 +03:00 committed by GitHub
commit bd9842cc8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 284 additions and 102 deletions

View file

@ -21,6 +21,9 @@ namespace MonogameLibrary.UI.Elements
public int indentation = 5; public int indentation = 5;
Texture2D texture2; Texture2D texture2;
/// <summary>
/// ректенгл ползунка
/// </summary>
public Rectangle sliderRect = new Rectangle(0, 0, 40, 40); public Rectangle sliderRect = new Rectangle(0, 0, 40, 40);
private float sliderValue = 0; private float sliderValue = 0;
private float minValue = 0, maxValue = 1; private float minValue = 0, maxValue = 1;

View file

@ -103,6 +103,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/background/base.png /build:Textures/GUI/background/base.png
#begin Textures/GUI/background/endGame.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/background/endGame.png
#begin Textures/GUI/background/join.png #begin Textures/GUI/background/join.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -115,6 +127,30 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/background/join.png /build:Textures/GUI/background/join.png
#begin Textures/GUI/background/mainMenu.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/background/mainMenu.png
#begin Textures/GUI/background/options.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/GUI/background/options.png
#begin Textures/GUI/background/selectMode.png #begin Textures/GUI/background/selectMode.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 KiB

After

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

After

Width:  |  Height:  |  Size: 5.8 MiB

View file

@ -28,17 +28,11 @@ namespace ZoFo.GameCore
public void OnDataSend(string data) public void OnDataSend(string data)
{ {
List<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data); List<UpdateData> updateDatas = JsonSerializer.Deserialize<List<UpdateData>>(data);
// тут будет switch // тут будет switch
foreach (var item in updateDatas) foreach (var item in updateDatas)
{ {
/* switch (item.UpdateType) Здесь нужно отлавливать и регистрировать GotData(item);
{
case "Tile":
MapObject map = new MapObject();
break;
}*/
} }
} }
@ -66,7 +60,7 @@ namespace ZoFo.GameCore
} }
} }
internal void GotData(IUpdateData update) internal void GotData(UpdateData update)
{ {
if (update is UpdateTileCreated) if (update is UpdateTileCreated)
{ {

View file

@ -13,13 +13,7 @@ using MonogameLibrary.UI.Elements;
namespace ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GUI;
public class HUD : AbstractGUI public class HUD : AbstractGUI
{ {
protected UIManager Manager = new();
protected List<DrawableUIElement> Elements = new();
private List<DrawableUIElement> ActiveElements;
protected DrawableUIElement SelectedElement;
private bool isStartedPrint = false;
private bool isPressed = false;
private GraphicsDevice graphicsDevice; private GraphicsDevice graphicsDevice;
public virtual void Initialize() public virtual void Initialize()

View file

@ -21,15 +21,15 @@ public class MainMenuGUI : AbstractGUI
{ {
int width = AppManager.Instance.CurentScreenResolution.X; int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y; int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\MenuBackground" }; menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\mainMenu" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "ZoFo", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font" }); Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "ZoFo", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"});
Button playButton = new Button(Manager) Button playButton = new Button(Manager)
{ {
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + height / 20 + height / 40, (int)(width / 5), (int)(height / 20)), rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + height / 20 + height / 40, (int)(width / 5), (int)(height / 20)),
text = "Play", text = "Play",

View file

@ -21,56 +21,76 @@ public class OptionsGUI : AbstractGUI
int width = AppManager.Instance.CurentScreenResolution.X; int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y; int height = AppManager.Instance.CurentScreenResolution.Y;
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\MenuBackground" }; menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\options" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "Options", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "Options", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"});
Label label_OverallVolume = new Label(Manager) Label label_OverallVolume = new Label(Manager)
{ fontName = "Fonts\\Font", scale = 0.2f, text = "All Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; { fontName = "Fonts\\Font", scale = 0.2f, text = "All Volume", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_OverallVolume); Elements.Add(label_OverallVolume);
Label label_OverallVolume_Percent = new Label(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "", fontColor = Color.Black, rectangle = new Rectangle(width / 2 + width / 10, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_OverallVolume_Percent);
var slider_OverallVolume = new Slider(Manager) var slider_OverallVolume = new Slider(Manager)
{ rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; { rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 7, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
slider_OverallVolume.SetValue(AppManager.Instance.SettingsManager.MainVolume); slider_OverallVolume.SetValue(AppManager.Instance.SettingsManager.MainVolume);
slider_OverallVolume.SliderChanged += (newVal) => slider_OverallVolume.SliderChanged += (newVal) =>
{ {
label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%";
AppManager.Instance.SettingsManager.SetMainVolume(newVal); AppManager.Instance.SettingsManager.SetMainVolume(newVal);
}; };
Elements.Add(slider_OverallVolume); Elements.Add(slider_OverallVolume);
//--------------------------------------
Label label_MusicVolume = new Label(Manager) Label label_MusicVolume = new Label(Manager)
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Music Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; { fontName = "Fonts\\Font", scale = 0.2f, text = "Music Volume", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_MusicVolume); Elements.Add(label_MusicVolume);
Label label_MusicVolume_Percent = new Label(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "", fontColor = Color.Black, rectangle = new Rectangle(width / 2 + width / 10, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_MusicVolume_Percent);
var slider_MusicVolume = new Slider(Manager) var slider_MusicVolume = new Slider(Manager)
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 7, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
slider_MusicVolume.SetValue(AppManager.Instance.SettingsManager.MusicVolume); slider_MusicVolume.SetValue(AppManager.Instance.SettingsManager.MusicVolume);
slider_MusicVolume.SliderChanged += (newVal) => slider_MusicVolume.SliderChanged += (newVal) =>
{ {
label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%";
AppManager.Instance.SettingsManager.SetMusicVolume(newVal); AppManager.Instance.SettingsManager.SetMusicVolume(newVal);
}; };
Elements.Add(slider_MusicVolume); Elements.Add(slider_MusicVolume);
//--------------------------------------
Label label_EffectsVolume = new Label(Manager) Label label_EffectsVolume = new Label(Manager)
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Effects Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; { fontName = "Fonts\\Font", scale = 0.2f, text = "Effects Volume", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_EffectsVolume); Elements.Add(label_EffectsVolume);
Label label_EffectsVolume_Percent = new Label(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "", fontColor = Color.Black, rectangle = new Rectangle(width / 2 + width / 10, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_EffectsVolume_Percent);
var slider_EffectsVolume = new Slider(Manager) var slider_EffectsVolume = new Slider(Manager)
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 }; { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 7, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
slider_EffectsVolume.SetValue(AppManager.Instance.SettingsManager.SoundEffectsVolume); slider_EffectsVolume.SetValue(AppManager.Instance.SettingsManager.SoundEffectsVolume);
slider_EffectsVolume.SliderChanged += (newVal) => slider_EffectsVolume.SliderChanged += (newVal) =>
{ {
label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%";
AppManager.Instance.SettingsManager.SetSoundEffectsVolume(newVal); AppManager.Instance.SettingsManager.SetSoundEffectsVolume(newVal);
}; };
Elements.Add(slider_EffectsVolume); Elements.Add(slider_EffectsVolume);
//--------------------------------------
Label lblSwitchMode = new Label(Manager) Label lblSwitchMode = new Label(Manager)
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Resolution set", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; { fontName = "Fonts\\Font", scale = 0.2f, text = "Resolution set", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(lblSwitchMode); Elements.Add(lblSwitchMode);
//var button_left_right_mode = new CheckBox(Manager) { rectangle = new Rectangle(rightBorder - checkboxlength, lblSwitchMode.rectangle.Y - 12, checkboxlength, checkboxlength) }; //var button_left_right_mode = new CheckBox(Manager) { rectangle = new Rectangle(rightBorder - checkboxlength, lblSwitchMode.rectangle.Y - 12, checkboxlength, checkboxlength) };
@ -79,7 +99,7 @@ public class OptionsGUI : AbstractGUI
Label label_IsFullScreen = new Label(Manager) Label label_IsFullScreen = new Label(Manager)
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Full Screen", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left }; { fontName = "Fonts\\Font", scale = 0.2f, text = "Full Screen", fontColor = Color.Black, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
Elements.Add(label_IsFullScreen); Elements.Add(label_IsFullScreen);
var button_FullScreen = new CheckBox(Manager) { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40) }; var button_FullScreen = new CheckBox(Manager) { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40) };
@ -90,7 +110,8 @@ public class OptionsGUI : AbstractGUI
}; };
Elements.Add(button_FullScreen); Elements.Add(button_FullScreen);
//--------------------------------------
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"}; { fontName = "Fonts\\Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
Elements.Add(bTExit); Elements.Add(bTExit);

View file

@ -39,8 +39,11 @@ public class SelectModeMenu : AbstractGUI
singleButton.LeftButtonPressed += () => singleButton.LeftButtonPressed += () =>
{ {
// single // single
Server server = new Server(); //Server Logic SinglePlayer Server server = new Server();
Client client = new Client(); Client client = new Client();
server.CreateRoom(1);
client.JoinYourself();
AppManager.Instance.SetServer(server); AppManager.Instance.SetServer(server);
AppManager.Instance.SetClient(client); AppManager.Instance.SetClient(client);
AppManager.Instance.ChangeState(GameState.HostPlaying); AppManager.Instance.ChangeState(GameState.HostPlaying);

View file

@ -17,7 +17,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
public List<CollisionComponent> CollisionComponent; public List<CollisionComponent> CollisionComponent;
public List<CollisionComponent> TriggerComponent; public List<CollisionComponent> TriggerComponent;
public void RegisterComponent()
{
}
public static bool CheckComponentCollision(List<CollisionComponent> collisionComponents, CollisionComponent component) public static bool CheckComponentCollision(List<CollisionComponent> collisionComponents, CollisionComponent component)
{ {

View file

@ -11,6 +11,7 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers namespace ZoFo.GameCore.GameManagers
{ {
public enum ScopeState { Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight } public enum ScopeState { Left, Right, Straight, Back, StraightLeft, StraightRight, BackLeft, BackRight }
public class InputManager public class InputManager
{ {
public delegate void Delegat(); public delegate void Delegat();

View file

@ -37,9 +37,9 @@ namespace ZoFo.GameCore.GameManagers.MapManager
// Загрузка TileSet-ов по TileSetInfo // Загрузка TileSet-ов по TileSetInfo
List<TileSet> tileSets = new List<TileSet>(); List<TileSet> tileSets = new List<TileSet>();
foreach (TileSetInfo tileSetInfo in tileMap.TileSets) foreach (TileSetInfo tileSetInfo in tileMap.TileSets)
{ {
TileSet tileSet = LoadTileSet("Content/MapData/TileMaps/" + tileSetInfo.Source); TileSet tileSet = LoadTileSet(Path.Combine("Content", "MapData", "TileMaps", tileSetInfo.Source));
tileSet.FirstGid = tileSetInfo.FirstGid; tileSet.FirstGid = tileSetInfo.FirstGid;
tileSets.Add(tileSet); tileSets.Add(tileSet);
} }

View file

@ -18,7 +18,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
private int port = 7632; private int port = 7632;
private EndPoint endPoint; private EndPoint endPoint;
private Socket socket; private Socket socket;
List<IUpdateData> updates = new List<IUpdateData>(); List<UpdateData> updates = new List<UpdateData>();
public delegate void OnDataSent(string Data); public delegate void OnDataSent(string Data);
public event OnDataSent GetDataSent; // event public event OnDataSent GetDataSent; // event
public bool IsConnected { get { return socket.Connected; } } public bool IsConnected { get { return socket.Connected; } }
@ -28,6 +28,11 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
Init(); Init();
} }
public bool SocketConnected()
{
return socket.Connected;
}
public void Init() //create endPoint, socket public void Init() //create endPoint, socket
{ {
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@ -39,7 +44,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
socket.Send(bytes); socket.Send(bytes);
} }
public void AddData(IUpdateData UpdateData) public void AddData(UpdateData UpdateData)
{ {
updates.Add(UpdateData); updates.Add(UpdateData);
} }

View file

@ -1,9 +1,11 @@
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Graphics.PackedVector; using Microsoft.Xna.Framework.Graphics.PackedVector;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -21,7 +23,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
private IPEndPoint endPoint; private IPEndPoint endPoint;
private Socket socket; private Socket socket;
private List<Socket> clients; private List<Socket> clients;
public List<IUpdateData> updates; public List<UpdateData> updates;
public delegate void OnDataSend(string data); public delegate void OnDataSend(string data);
public event OnDataSend GetDataSend; // event public event OnDataSend GetDataSend; // event
Dictionary<Socket, Thread> managerThread; Dictionary<Socket, Thread> managerThread;
@ -38,7 +40,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
managerThread = new Dictionary<Socket, Thread>(); managerThread = new Dictionary<Socket, Thread>();
clients = new List<Socket>(); clients = new List<Socket>();
updates = new List<IUpdateData>(); updates = new List<UpdateData>();
managerThread = new Dictionary<Socket, Thread>(); managerThread = new Dictionary<Socket, Thread>();
socket.Bind(endPoint); socket.Bind(endPoint);
} }
@ -56,19 +58,25 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
updates.Clear(); updates.Clear();
return; //TODO TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK return; //TODO TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK TODO REMOVE TO ADD NETWORK
string data = JsonSerializer.Serialize(updates); //по 10 паков за раз TODO FIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXIT
List<UpdateData> datasToSend = new List<UpdateData>();
for (int i = 0; i < 5 && i<updates.Count; i++)
datasToSend.Add(updates[i]);
string data = JsonSerializer.Serialize(datasToSend);
var databytes = Encoding.UTF8.GetBytes(data); var databytes = Encoding.UTF8.GetBytes(data);
foreach (var item in clients) foreach (var item in clients)
{ {
item.SendAsync(databytes); item.SendAsync(databytes);
} }
for (int i = 0; i < 5 && i< datasToSend.Count; i++)
updates.RemoveAt(0);
} }
/// <summary> /// <summary>
/// добавляет в лист updates новую data /// добавляет в лист updates новую data
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
public void AddData(IUpdateData data) public void AddData(UpdateData data)
{ {
updates.Add(data); updates.Add(data);
} }

View file

@ -6,9 +6,12 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
{ {
public class UpdateInput :IUpdateData public class UpdateInput :UpdateData
{ {
public int IdEntity { get; set; } // public int IdEntity { get; set; }
public string UpdateType { get; set; } public UpdateInput()
{
UpdateType = "UpdateInput";
}
} }
} }

View file

@ -6,9 +6,8 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
{ {
public class UpdatePlayerExit : IUpdateData public class UpdatePlayerExit : UpdateData
{ {
public int IdEntity { get; set; } public UpdatePlayerExit() { UpdateType = "UpdatePlayerExit"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateAnimation : IUpdateData //хранит новую анимации /// <summary>
/// Хранит новое сосотяние анимации
/// </summary>
public class UpdateAnimation : UpdateData
{ {
public int IdEntity { get; set; } public UpdateAnimation() { UpdateType = "UpdateAnimation"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateEntityHealth : IUpdateData//хранит новое хп entity /// <summary>
/// Обнивляет хп сущности
/// </summary>
public class UpdateEntityHealth : UpdateData
{ {
public int IdEntity { get; set; } public UpdateEntityHealth() { UpdateType = "UpdateEntityHealth"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateGameEnded : IUpdateData //хранит полученый лут и уведомляет о конце игры /// <summary>
/// Хранит полученый лут и уведомляет о конце игры
/// </summary>
public class UpdateGameEnded : UpdateData
{ {
public int IdEntity { get; set; } public UpdateGameEnded() { UpdateType = "UpdateGameEnded"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateGameObjectCreated : IUpdateData //Хранит объект, который только отправили /// <summary>
/// Хранит объект, который только отправили
/// </summary>
public class UpdateGameObjectCreated : UpdateData
{ {
public int IdEntity { get; set; } public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
/// <summary>
/// Хранит объект, который надо удлить
/// </summary>
public class UpdateGameObjectDeleted : UpdateData
{
public UpdateGameObjectDeleted() { UpdateType = "UpdateGameObjectDeleted"; }
}
}

View file

@ -0,0 +1,10 @@
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
/// <summary>
/// При попытке взаимодействия с объектом
/// </summary>
public class UpdateInteraction : UpdateData
{
public int IdEntity { get; set; }
public string UpdateType { get; set; }
}

View file

@ -0,0 +1,14 @@
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
/// <summary>
/// При изменении возможности повзаимодействовать с объектом
/// </summary>
/// <param name="idEntity"></param>
/// <param name="isReady"></param>
public class UpdateInteractionReady(int idEntity, bool isReady)
: UpdateData
{
public int IdEntity { get; set; } = idEntity;
public string UpdateType { get; set; }
public bool IsReady { get; set; } = isReady;
}

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateLoot : IUpdateData //Хранит лут /// <summary>
/// Хранит лут
/// </summary>
public class UpdateLoot : UpdateData
{ {
public int IdEntity { get; set; } public UpdateLoot() { UpdateType = "UpdateLoot"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdatePlayerParametrs : IUpdateData //Хранит хп, радиацию /// <summary>
/// Хранит хп, радиацию
/// </summary>
public class UpdatePlayerParametrs : UpdateData
{ {
public int IdEntity { get; set; } public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -6,9 +6,11 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdatePosition : IUpdateData //Хранит новую позицию /// <summary>
/// Хранит новую позицию
/// </summary>
public class UpdatePosition : UpdateData
{ {
public int IdEntity { get; set; } public UpdatePosition() { UpdateType = "UpdatePosition"; }
public string UpdateType { get; set; }
} }
} }

View file

@ -10,11 +10,13 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{ {
public class UpdateTileCreated : IUpdateData /// <summary>
/// При создании тайла
/// </summary>
public class UpdateTileCreated : UpdateData
{ {
public int IdEntity { get; set; } public UpdateTileCreated() { UpdateType = "UpdateTileCreated"; }
public string UpdateType { get; set; }
public Texture2D TextureTile { get; set; } public Texture2D TextureTile { get; set; }
public Vector2 Position { get; set; } public Vector2 Position { get; set; }
public Point Size { get; set; } public Point Size { get; set; }

View file

@ -14,16 +14,19 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates
[JsonDerivedType(typeof(UpdateEntityHealth))] [JsonDerivedType(typeof(UpdateEntityHealth))]
[JsonDerivedType(typeof(UpdateGameEnded))] [JsonDerivedType(typeof(UpdateGameEnded))]
[JsonDerivedType(typeof(UpdateGameObjectCreated))] [JsonDerivedType(typeof(UpdateGameObjectCreated))]
[JsonDerivedType(typeof(UpdateGameObjectDeleted))]
[JsonDerivedType(typeof(UpdateLoot))] [JsonDerivedType(typeof(UpdateLoot))]
[JsonDerivedType(typeof(UpdatePlayerParametrs))] [JsonDerivedType(typeof(UpdatePlayerParametrs))]
[JsonDerivedType(typeof(UpdatePosition))] [JsonDerivedType(typeof(UpdatePosition))]
[JsonDerivedType(typeof(UpdateTileCreated))] [JsonDerivedType(typeof(UpdateTileCreated))]
[JsonDerivedType(typeof(UpdateInput))] [JsonDerivedType(typeof(UpdateInput))]
[JsonDerivedType(typeof(UpdatePlayerExit))] [JsonDerivedType(typeof(UpdatePlayerExit))]
[JsonDerivedType(typeof(UpdateInteractionReady))]
public interface IUpdateData [JsonDerivedType(typeof(UpdateInteraction))]
public class UpdateData
{ {
public int IdEntity { get; set; } //Id объекта public int IdEntity { get; set; } //Id объекта
public string UpdateType { get; set; } //тип обновления public string UpdateType { get; protected set; } //тип обновления
} }
} }

View file

@ -16,8 +16,10 @@ namespace ZoFo.GameCore.GameObjects.Entities
protected Entity(Vector2 position) : base(position) protected Entity(Vector2 position) : base(position)
{ {
} }
public virtual void Update()
{
}
} }
} }

View file

@ -2,7 +2,7 @@
using System; using System;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
public class Collectable : Entity public class Collectable : Interactable
{ {
public Collectable(Vector2 position) : base(position) public Collectable(Vector2 position) : base(position)
{ {

View file

@ -0,0 +1,8 @@
namespace ZoFo.GameCore.GameObjects.Entities.Interactables;
public class Door
{
public bool isOpened;
}

View file

@ -0,0 +1,26 @@
using Microsoft.Xna.Framework;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables;
public class Interactable : Entity
{
public Interactable(Vector2 position) : base(position)
{
collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true);
collisionComponent.OnTriggerExit += (sender, e) => ChangeInteraction(sender, e, false);
}
private void ChangeInteraction(object sender, CollisionComponent e, bool isReady)
{
AppManager.Instance.server.AddData(new UpdateInteractionReady((sender as Player).Id, isReady));
}
public void OnInteraction()
{
}
}

View file

@ -3,20 +3,26 @@ using Microsoft.Xna.Framework.Graphics;
using System; using System;
using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.GameObjects.Entities;
using ZoFo.GameCore.ZoFo_graphics; using ZoFo.GameCore.ZoFo_graphics;
using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities;
public class LivingEntity : Entity public class LivingEntity : Entity
{ {
public Vector2 velocity; public Vector2 velocity;
private InputManager inputManager;
public LivingEntity(Vector2 position) : base(position) public LivingEntity(Vector2 position) : base(position)
{ {
inputManager = new InputManager();
} }
public void TextureLoad(SpriteBatch spriteBatch) #region Server side
/*public override void Update()
{ {
} }*/
#endregion
} }

View file

@ -1,25 +1,27 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
public class Player : LivingEntity public class Player : LivingEntity
{ {
public Vector2 InputWeaponRotation{ get; set; }
public Vector2 InputPlayerRotation{ get; set;}
public bool IsTryingToShoot{get;set;}
Texture2D texture;
private float speed;
private int health; private int health;
Server server = new Server();
public Player(Vector2 position) : base(position) public Player(Vector2 position) : base(position)
{ {
//InputWeaponRotation = new Vector2(0, 0);
//InputPlayerRotation = new Vector2(0, 0);
} }
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
{ {
// server.AddData();
}
public void TextureLoad(SpriteBatch spriteBatch)
{
} }
} }

View file

@ -4,19 +4,21 @@ using Microsoft.Xna.Framework.Graphics;
using System; using System;
using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.ZoFo_graphics; using ZoFo.GameCore.ZoFo_graphics;
using ZoFo.GameCore;
namespace ZoFo.GameCore.GameObjects; namespace ZoFo.GameCore.GameObjects;
public abstract class GameObject public abstract class GameObject
{ {
public Vector2 position; public Vector2 position;
public Vector2 rotation; //вектор направления объекта public Vector2 rotation; //вектор направления объекта
public abstract GraphicsComponent graphicsComponent { get; } public abstract GraphicsComponent graphicsComponent { get; }
#region ServerSide #region ServerSide
public GameObject(Vector2 position) public GameObject(Vector2 position)
{ {
this.position = position; this.position = position;
graphicsComponent.LoadContent(); graphicsComponent.LoadContent();
} }

View file

@ -15,12 +15,19 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
public class MapObject : GameObject public class MapObject : GameObject
{ {
public virtual bool IsColliderOn { get; protected set; } = true;//Who added that? public virtual bool IsColliderOn { get; protected set; } = true;//Who added that?
public Rectangle _sourceRectangle; public Rectangle sourceRectangle;
public override GraphicsComponent graphicsComponent { get; } = new(); public override GraphicsComponent graphicsComponent { get; } = new();
/// <summary>
/// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры
/// </summary>
/// <param name="position"></param>
/// <param name="size"></param>
/// <param name="sourceRectangle"></param>
/// <param name="textureName"></param>
public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position) public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName) : base(position)
{ {
_sourceRectangle = sourceRectangle; this.sourceRectangle = sourceRectangle;
graphicsComponent.ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); graphicsComponent.ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
graphicsComponent.BuildComponent(textureName); graphicsComponent.BuildComponent(textureName);
graphicsComponent.LoadContent(); graphicsComponent.LoadContent();
@ -28,7 +35,7 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch, _sourceRectangle); graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch, sourceRectangle);
} }
} }

View file

@ -29,7 +29,7 @@ namespace ZoFo.GameCore
//TODO Comment pls //TODO Comment pls
public void OnDataSend(string data) public void OnDataSend(string data)
{ {
List<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data); List<UpdateData> updateDatas = JsonSerializer.Deserialize<List<UpdateData>>(data);
for (int i = 0; i < updateDatas.Count; i++) for (int i = 0; i < updateDatas.Count; i++)
{ {
ProcessIUpdateData(updateDatas[i]); ProcessIUpdateData(updateDatas[i]);
@ -39,7 +39,7 @@ namespace ZoFo.GameCore
/// Обработка апдейтсов, которые нам прислал клиент /// Обработка апдейтсов, которые нам прислал клиент
/// </summary> /// </summary>
/// <param name="updateData"></param> /// <param name="updateData"></param>
public void ProcessIUpdateData(IUpdateData updateData) public void ProcessIUpdateData(UpdateData updateData)
{ {
//ТУТ Switch case будет честное слово //ТУТ Switch case будет честное слово
@ -50,7 +50,7 @@ namespace ZoFo.GameCore
/// добавляет в лист updates новую data /// добавляет в лист updates новую data
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
public void AddData(IUpdateData data) public void AddData(UpdateData data)//добавляет в лист updates новую data
{ {
networkManager.AddData(data); networkManager.AddData(data);
} }
@ -87,8 +87,7 @@ namespace ZoFo.GameCore
networkManager.AddData(gameEnded); networkManager.AddData(gameEnded);
networkManager.CloseConnection(); networkManager.CloseConnection();
} }
#endregion private List<GameObject> gameObjects = new List<GameObject>();
private List<GameObject> gameObjects;
private List<Entity> entities; //entity private List<Entity> entities; //entity
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
{ {
@ -118,11 +117,12 @@ namespace ZoFo.GameCore
AddData(new UpdateTileCreated() AddData(new UpdateTileCreated()
{ {
Position = (gameObject as MapObject).position, Position = (gameObject as MapObject).position,
sourceRectangle = (gameObject as MapObject)._sourceRectangle, sourceRectangle = (gameObject as MapObject).sourceRectangle,
Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size, Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size,
tileSetName = (gameObject as MapObject).graphicsComponent.mainTextureName tileSetName = (gameObject as MapObject).graphicsComponent.mainTextureName
});//TODO });//TODO
} }
} }
} }
#endregion
} }