Merge branch 'MapLoader' of https://github.com/progtime-net/ZoFo into MapLoader
This commit is contained in:
commit
c8fee7dade
62 changed files with 1883 additions and 21 deletions
0
Install-Package
Normal file
0
Install-Package
Normal file
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
@ -13,3 +13,22 @@
|
||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
|
#begin Font/Font.spritefont
|
||||||
|
/importer:FontDescriptionImporter
|
||||||
|
/processor:FontDescriptionProcessor
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:TextureFormat=Compressed
|
||||||
|
/build:Font/Font.spritefont
|
||||||
|
|
||||||
|
#begin Texture/GUI/MenuBackground.jpg
|
||||||
|
/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:Texture/GUI/MenuBackground.jpg
|
||||||
|
|
||||||
|
|
BIN
ZoFo/Content/Font/Debrosee-ALPnL.ttf
Normal file
BIN
ZoFo/Content/Font/Debrosee-ALPnL.ttf
Normal file
Binary file not shown.
60
ZoFo/Content/Font/Font.spritefont
Normal file
60
ZoFo/Content/Font/Font.spritefont
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file contains an xml description of a font, and will be read by the XNA
|
||||||
|
Framework Content Pipeline. Follow the comments to customize the appearance
|
||||||
|
of the font in your game, and to change the characters which are available to draw
|
||||||
|
with.
|
||||||
|
-->
|
||||||
|
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
|
||||||
|
<Asset Type="Graphics:FontDescription">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Modify this string to change the font that will be imported.
|
||||||
|
-->
|
||||||
|
<FontName>Debrosee-ALPnL.ttf</FontName>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Size is a float value, measured in points. Modify this value to change
|
||||||
|
the size of the font.
|
||||||
|
-->
|
||||||
|
<Size>12</Size>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Spacing is a float value, measured in pixels. Modify this value to change
|
||||||
|
the amount of spacing in between characters.
|
||||||
|
-->
|
||||||
|
<Spacing>0</Spacing>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
UseKerning controls the layout of the font. If this value is true, kerning information
|
||||||
|
will be used when placing characters.
|
||||||
|
-->
|
||||||
|
<UseKerning>true</UseKerning>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
|
||||||
|
and "Bold, Italic", and are case sensitive.
|
||||||
|
-->
|
||||||
|
<Style>Regular</Style>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
If you uncomment this line, the default character will be substituted if you draw
|
||||||
|
or measure text that contains characters which were not included in the font.
|
||||||
|
-->
|
||||||
|
<!-- <DefaultCharacter>*</DefaultCharacter> -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
CharacterRegions control what letters are available in the font. Every
|
||||||
|
character from Start to End will be built and made available for drawing. The
|
||||||
|
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
|
||||||
|
character set. The characters are ordered according to the Unicode standard.
|
||||||
|
See the documentation for more information.
|
||||||
|
-->
|
||||||
|
<CharacterRegions>
|
||||||
|
<CharacterRegion>
|
||||||
|
<Start> </Start>
|
||||||
|
<End>~</End>
|
||||||
|
</CharacterRegion>
|
||||||
|
</CharacterRegions>
|
||||||
|
</Asset>
|
||||||
|
</XnaContent>
|
BIN
ZoFo/Content/Texture/GUI/MenuBackground.jpg
Normal file
BIN
ZoFo/Content/Texture/GUI/MenuBackground.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 592 KiB |
42
ZoFo/GameCore/Client.cs
Normal file
42
ZoFo/GameCore/Client.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||||
|
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore
|
||||||
|
{
|
||||||
|
public class Client
|
||||||
|
{
|
||||||
|
ClientNetworkManager networkManager;
|
||||||
|
public Client()
|
||||||
|
{
|
||||||
|
networkManager = new ClientNetworkManager();
|
||||||
|
networkManager.GetDataSent += OnDataSend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDataSend(string data)
|
||||||
|
{
|
||||||
|
List<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data);
|
||||||
|
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> switch
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GameEndedUnexpectedly(){ }
|
||||||
|
|
||||||
|
public void JoinRoom(){ }
|
||||||
|
|
||||||
|
public void JoinYourself(){ }
|
||||||
|
|
||||||
|
internal void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,56 @@
|
||||||
namespace ZoFo.GameCore.GUI;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using ZoFo.GameCore.GameManagers;
|
||||||
|
|
||||||
public class AbstractGUI
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public abstract class 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;
|
||||||
|
|
||||||
|
public AbstractGUI()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void CreateUI();
|
||||||
|
private GraphicsDevice graphicsDevice;
|
||||||
|
public virtual void Initialize()
|
||||||
|
{
|
||||||
|
Manager.Initialize(AppManager.Instance.GraphicsDevice);
|
||||||
|
CreateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void LoadContent()
|
||||||
|
{
|
||||||
|
Manager.LoadContent(AppManager.Instance.Content, "Font");
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
Manager.Draw(spriteBatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void ResolutioChenges()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
28
ZoFo/GameCore/GUI/BaseGUI.cs
Normal file
28
ZoFo/GameCore/GUI/BaseGUI.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class BaseGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
6
ZoFo/GameCore/GUI/DebugHUD.cs
Normal file
6
ZoFo/GameCore/GUI/DebugHUD.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class DebugHUD
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
27
ZoFo/GameCore/GUI/GameEndedGUI.cs
Normal file
27
ZoFo/GameCore/GUI/GameEndedGUI.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class GameEndedGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
44
ZoFo/GameCore/GUI/HUD.cs
Normal file
44
ZoFo/GameCore/GUI/HUD.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class HUD
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
public virtual void Initialize()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void LoadContent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
Manager.Draw(spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
27
ZoFo/GameCore/GUI/InventoryGUI.cs
Normal file
27
ZoFo/GameCore/GUI/InventoryGUI.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class InventoryGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
33
ZoFo/GameCore/GUI/MainMenuGUI.cs
Normal file
33
ZoFo/GameCore/GUI/MainMenuGUI.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using ZoFo.GameCore.GameManagers;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class MainMenuGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
DrawableUIElement menuBackground;
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
int width = AppManager.Instance.CurentScreenResolution.X;
|
||||||
|
int height = AppManager.Instance.CurentScreenResolution.Y;
|
||||||
|
|
||||||
|
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), textureName = "Texture\\GUI\\MenuBackground" };
|
||||||
|
Elements.Add(menuBackground);
|
||||||
|
menuBackground.LoadTexture(AppManager.Instance.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
ZoFo/GameCore/GUI/OptionsGUI.cs
Normal file
27
ZoFo/GameCore/GUI/OptionsGUI.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class OptionsGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
ZoFo/GameCore/GUI/SelectModeMenu.cs
Normal file
27
ZoFo/GameCore/GUI/SelectModeMenu.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class SelectModeMenu : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
ZoFo/GameCore/GUI/SelectingServerGUI.cs
Normal file
27
ZoFo/GameCore/GUI/SelectingServerGUI.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class SelectingServerGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs
Normal file
27
ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
|
public class WaitingForPlayersGUI : AbstractGUI
|
||||||
|
{
|
||||||
|
protected override void CreateUI()
|
||||||
|
{
|
||||||
|
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
||||||
|
// int height = AppManager.Instance.inGameHUDHelperResolution.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
131
ZoFo/GameCore/GameManagers/AppManager.cs
Normal file
131
ZoFo/GameCore/GameManagers/AppManager.cs
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DangerousD.GameCore.Graphics;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using ZoFo.GameCore.GameManagers.ItemManager;
|
||||||
|
using ZoFo.GameCore.GUI;
|
||||||
|
using static System.Collections.Specialized.BitVector32;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers
|
||||||
|
{
|
||||||
|
public enum GameState { NotPlaying, HostPlaying, ClientPlaying }
|
||||||
|
public class AppManager : Game
|
||||||
|
{
|
||||||
|
private GraphicsDeviceManager _graphics;
|
||||||
|
private SpriteBatch _spriteBatch;
|
||||||
|
|
||||||
|
|
||||||
|
public static AppManager Instance { get; private set; }
|
||||||
|
public GameState gamestate;
|
||||||
|
public AbstractGUI currentGUI;
|
||||||
|
public Point CurentScreenResolution = new Point(1920, 1080);
|
||||||
|
public Client client;
|
||||||
|
public Server server;
|
||||||
|
|
||||||
|
|
||||||
|
#region Managers
|
||||||
|
|
||||||
|
public InputManager InputManager;
|
||||||
|
public ItemManager.ItemManager ItemManager;
|
||||||
|
|
||||||
|
public AnimationBuilder animationBuilder{get;set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public AppManager()
|
||||||
|
{
|
||||||
|
_graphics = new GraphicsDeviceManager(this);
|
||||||
|
Content.RootDirectory = "Content";
|
||||||
|
IsMouseVisible = true;
|
||||||
|
|
||||||
|
Instance = this;
|
||||||
|
InputManager = new InputManager();
|
||||||
|
|
||||||
|
currentGUI = new MainMenuGUI();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Initialize()
|
||||||
|
{
|
||||||
|
currentGUI.Initialize();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
base.Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadContent()
|
||||||
|
{
|
||||||
|
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
|
||||||
|
Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||||
|
Exit();
|
||||||
|
|
||||||
|
InputManager.Update();
|
||||||
|
currentGUI.Update(gameTime);
|
||||||
|
switch (gamestate)
|
||||||
|
{
|
||||||
|
case GameState.NotPlaying:
|
||||||
|
break;
|
||||||
|
case GameState.HostPlaying:
|
||||||
|
server.Update(gameTime);
|
||||||
|
client.Update(gameTime);
|
||||||
|
break;
|
||||||
|
case GameState.ClientPlaying:
|
||||||
|
server.Update(gameTime);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Update(gameTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Draw(GameTime gameTime)
|
||||||
|
{
|
||||||
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
|
||||||
|
|
||||||
|
currentGUI.Draw(_spriteBatch);
|
||||||
|
switch (gamestate)
|
||||||
|
{
|
||||||
|
case GameState.ClientPlaying:
|
||||||
|
case GameState.HostPlaying:
|
||||||
|
client.Draw(_spriteBatch);
|
||||||
|
break;
|
||||||
|
case GameState.NotPlaying:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Draw(gameTime);
|
||||||
|
}
|
||||||
|
public void ChangeState(GameState gameState)
|
||||||
|
{
|
||||||
|
this.gamestate = gameState;
|
||||||
|
}
|
||||||
|
public void SetGUI(AbstractGUI gui)
|
||||||
|
{
|
||||||
|
currentGUI = gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GameEnded(Dictionary<string, int> lootIGot)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||||
|
{
|
||||||
|
public class CollisionComponent
|
||||||
|
{
|
||||||
|
//остановлен ли перс
|
||||||
|
bool doesStop;
|
||||||
|
Rectangle stopRectangle;
|
||||||
|
|
||||||
|
// triggers for rectangle
|
||||||
|
bool isTrigger;
|
||||||
|
Rectangle triggerRectangle;
|
||||||
|
|
||||||
|
//delegate
|
||||||
|
public delegate void EventHandler(object sender, EventArgs e);
|
||||||
|
|
||||||
|
|
||||||
|
//events
|
||||||
|
public event EventHandler<CollisionComponent> OnTriggerEnter;
|
||||||
|
public event EventHandler<CollisionComponent> OnTriggerZone;
|
||||||
|
public event EventHandler<CollisionComponent> OnTriggerExit;
|
||||||
|
|
||||||
|
// methods-event
|
||||||
|
public void TriggerEnter(object component, ///<Player player>,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void TriggerZone(object component,///<Player player>,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void TriggerExit(object component,///<Player player>,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||||
|
{
|
||||||
|
public class CollisionManager
|
||||||
|
{
|
||||||
|
public List<CollisionComponent> CollisionComponent;
|
||||||
|
public List<CollisionComponent> TriggerComponent;
|
||||||
|
|
||||||
|
public void UpdatePositions()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetObjectInArea(Rectangle area)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Register(Rectangle rectangle)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
229
ZoFo/GameCore/GameManagers/InputManager.cs
Normal file
229
ZoFo/GameCore/GameManagers/InputManager.cs
Normal file
|
@ -0,0 +1,229 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers
|
||||||
|
{
|
||||||
|
public enum ScopeState { Up, Middle, Down }
|
||||||
|
public enum ControlsState { Gamepad, Keyboard }
|
||||||
|
public class InputManager
|
||||||
|
{
|
||||||
|
public delegate void Delegat();
|
||||||
|
public event Delegat MovEventJump;
|
||||||
|
public event Delegat MovEventDown;
|
||||||
|
public event Delegat ShootEvent;
|
||||||
|
|
||||||
|
Vector2 vectorMovementDirection;
|
||||||
|
ScopeState scopeState; // Положение оружия. Up, Middle, Down.
|
||||||
|
ControlsState controlsState;
|
||||||
|
private bool _overrideControls = false;
|
||||||
|
private bool _cheatsEnabled = false;
|
||||||
|
public bool InvincibilityCheat { get; private set; } = false;
|
||||||
|
public bool CollisionsCheat { get; private set; } = false;
|
||||||
|
public bool InfiniteAmmoCheat { get; private set; } = false;
|
||||||
|
|
||||||
|
private bool isJumpDown; // Блокирует физическое нажатие прыжка и спуска
|
||||||
|
private bool isShoot;
|
||||||
|
|
||||||
|
private KeyboardState lastKeyboardState;
|
||||||
|
private GamePadState lastGamePadState;
|
||||||
|
|
||||||
|
|
||||||
|
public Vector2 VectorMovementDirection { get => vectorMovementDirection; }
|
||||||
|
public ScopeState ScopeState { get => scopeState; }
|
||||||
|
public string currentControlsState;
|
||||||
|
|
||||||
|
public InputManager()
|
||||||
|
{
|
||||||
|
this.isJumpDown = false;
|
||||||
|
this.isShoot = false;
|
||||||
|
scopeState = ScopeState.Middle;
|
||||||
|
controlsState = ControlsState.Keyboard;
|
||||||
|
vectorMovementDirection = new Vector2(0, 0);
|
||||||
|
}
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (_cheatsEnabled)
|
||||||
|
{
|
||||||
|
//AppManager.Instance.DebugHUD.Set("cheats", _cheatsEnabled.ToString());
|
||||||
|
//AppManager.Instance.DebugHUD.Set("invincible", InvincibilityCheat.ToString());
|
||||||
|
//AppManager.Instance.DebugHUD.Set("infinite ammo", InfiniteAmmoCheat.ToString()); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Работа с GamePad
|
||||||
|
if (_overrideControls ? controlsState == ControlsState.Gamepad : GamePad.GetState(0).IsConnected)
|
||||||
|
{
|
||||||
|
controlsState = ControlsState.Gamepad;
|
||||||
|
|
||||||
|
#region Обработка гейм-пада. Задает Vector2 vectorMovementDirection являющийся вектором отклонения левого стика.
|
||||||
|
GamePadState gamePadState = GamePad.GetState(0);
|
||||||
|
vectorMovementDirection = gamePadState.ThumbSticks.Left;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region читы
|
||||||
|
if (gamePadState.Triggers.Left >= 0.9 && gamePadState.Triggers.Right >= 0.9)
|
||||||
|
_cheatsEnabled = true;
|
||||||
|
if (_cheatsEnabled)
|
||||||
|
{
|
||||||
|
if (gamePadState.Buttons.Y == ButtonState.Pressed && lastGamePadState.Buttons.Y == ButtonState.Released)
|
||||||
|
InvincibilityCheat = !InvincibilityCheat;
|
||||||
|
if (gamePadState.Buttons.B == ButtonState.Pressed && lastGamePadState.Buttons.B == ButtonState.Released)
|
||||||
|
CollisionsCheat = !CollisionsCheat;
|
||||||
|
//TODO: infinite ammo cheat by gamepad
|
||||||
|
}
|
||||||
|
#endregion // Cheats
|
||||||
|
|
||||||
|
#region Обработка нажатия прыжка и спуска. Вызывает события MovEvent.
|
||||||
|
if (vectorMovementDirection.Y < -0.2 && gamePadState.Buttons.A == ButtonState.Pressed && !isJumpDown)
|
||||||
|
{
|
||||||
|
isJumpDown = true;
|
||||||
|
MovEventDown?.Invoke();
|
||||||
|
Debug.WriteLine("Спуск");
|
||||||
|
}
|
||||||
|
else if (gamePadState.Buttons.A == ButtonState.Pressed && lastGamePadState.Buttons.A == ButtonState.Released)
|
||||||
|
{
|
||||||
|
MovEventJump?.Invoke();
|
||||||
|
Debug.WriteLine("Прыжок");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Обработка положения оружия. Задает значение полю scopeState.
|
||||||
|
if (vectorMovementDirection.Y >= 0.7)
|
||||||
|
{
|
||||||
|
scopeState = ScopeState.Up;
|
||||||
|
}
|
||||||
|
else if (vectorMovementDirection.Y <= -0.7 && !isJumpDown)
|
||||||
|
{
|
||||||
|
scopeState = ScopeState.Down;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scopeState = ScopeState.Middle;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Обработка нажатия выстрела. Вызывает событие ShootEvent
|
||||||
|
if (gamePadState.Buttons.X == ButtonState.Pressed && !isJumpDown && !isShoot)
|
||||||
|
{
|
||||||
|
isShoot = true;
|
||||||
|
ShootEvent?.Invoke();
|
||||||
|
Debug.WriteLine("Выстрел");
|
||||||
|
}
|
||||||
|
else if (gamePadState.Buttons.X == ButtonState.Released && !isJumpDown)
|
||||||
|
{
|
||||||
|
isShoot = false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
lastGamePadState = gamePadState;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Работа с KeyBoard
|
||||||
|
else
|
||||||
|
{
|
||||||
|
controlsState = ControlsState.Keyboard;
|
||||||
|
|
||||||
|
#region Состояние клавиатуры
|
||||||
|
KeyboardState keyBoardState = Keyboard.GetState(); // Состояние клавиатуры
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region читы
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.LeftShift) && keyBoardState.IsKeyDown(Keys.RightShift))
|
||||||
|
_cheatsEnabled = true;
|
||||||
|
if (_cheatsEnabled)
|
||||||
|
{
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.I) && lastKeyboardState.IsKeyUp(Keys.I))
|
||||||
|
InvincibilityCheat = !InvincibilityCheat;
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.C) && lastKeyboardState.IsKeyUp(Keys.C))
|
||||||
|
CollisionsCheat = !CollisionsCheat;
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.N) && lastKeyboardState.IsKeyUp(Keys.N))
|
||||||
|
InfiniteAmmoCheat = !InfiniteAmmoCheat;
|
||||||
|
|
||||||
|
List<Keys> lvls = new List<Keys>() { Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9 };
|
||||||
|
|
||||||
|
for (int i = 0; i < lvls.Count; i++)
|
||||||
|
{
|
||||||
|
//if (keyBoardState.IsKeyDown(lvls[i]) && lastKeyboardState.IsKeyUp(lvls[i])) //TODO
|
||||||
|
// AppManager.Instance.Restart($"lvl{i}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion // Cheats
|
||||||
|
|
||||||
|
#region Обработка движения вправо-влево. Меняет у вектора vectorMovementDirection значение X на -1/0/1.
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.Left))
|
||||||
|
{
|
||||||
|
vectorMovementDirection.X = -1;
|
||||||
|
}
|
||||||
|
else if (keyBoardState.IsKeyDown(Keys.Right))
|
||||||
|
{
|
||||||
|
vectorMovementDirection.X = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vectorMovementDirection.X = 0;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Обработка прыжка и спуска. Вызываются события MovEvent.
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.LeftShift) && !isJumpDown && keyBoardState.IsKeyDown(Keys.Down))
|
||||||
|
{
|
||||||
|
isJumpDown = true;
|
||||||
|
MovEventDown?.Invoke();
|
||||||
|
Debug.WriteLine("Спуск");
|
||||||
|
}
|
||||||
|
else if (keyBoardState.IsKeyDown(Keys.LeftShift) && !isJumpDown)
|
||||||
|
{
|
||||||
|
isJumpDown = true;
|
||||||
|
MovEventJump?.Invoke();
|
||||||
|
Debug.WriteLine("Прыжок");
|
||||||
|
}
|
||||||
|
else if (keyBoardState.IsKeyUp(Keys.LeftShift))
|
||||||
|
{
|
||||||
|
isJumpDown = false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Обработка положения оружия. Задает значение полю scopeState.
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.Up))
|
||||||
|
{
|
||||||
|
scopeState = ScopeState.Up;
|
||||||
|
}
|
||||||
|
else if (keyBoardState.IsKeyDown(Keys.Down) && !isJumpDown)
|
||||||
|
{
|
||||||
|
scopeState = ScopeState.Down;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scopeState = ScopeState.Middle;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Обработка нажатия выстрела. Вызывает событие ShootEvent
|
||||||
|
if (keyBoardState.IsKeyDown(Keys.X) && !isJumpDown && !isShoot)
|
||||||
|
{
|
||||||
|
isShoot = true;
|
||||||
|
ShootEvent?.Invoke();
|
||||||
|
Debug.WriteLine("Выстрел");
|
||||||
|
}
|
||||||
|
else if (keyBoardState.IsKeyUp(Keys.X) && !isJumpDown)
|
||||||
|
{
|
||||||
|
isShoot = false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
SetState(ControlsState.Keyboard);
|
||||||
|
lastKeyboardState = keyBoardState;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
public void SetState(ControlsState controlsState)
|
||||||
|
{
|
||||||
|
currentControlsState = controlsState.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs
Normal file
37
ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.ItemManager
|
||||||
|
{
|
||||||
|
class ItemInfo
|
||||||
|
{
|
||||||
|
//поля
|
||||||
|
string tag;
|
||||||
|
string textureName;
|
||||||
|
Texture2D itemTexture;
|
||||||
|
bool isCraftable;
|
||||||
|
Dictionary<string, int> resourcesNeededToCraft;
|
||||||
|
public ItemInfo (string tag)
|
||||||
|
{
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
public ItemInfo(string tag,string textureName,bool isCraftable, Dictionary<string, int> resourcesNeededToCraft)
|
||||||
|
{
|
||||||
|
this.tag = tag;
|
||||||
|
this.textureName = textureName;
|
||||||
|
|
||||||
|
this.isCraftable = isCraftable;
|
||||||
|
this.resourcesNeededToCraft = resourcesNeededToCraft;
|
||||||
|
}
|
||||||
|
//методы
|
||||||
|
public void LoadTexture()
|
||||||
|
{
|
||||||
|
//я что-то хз как это
|
||||||
|
itemTexture=AppManager.Instance.Content.Load<Texture2D>(textureName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs
Normal file
33
ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.ItemManager
|
||||||
|
{
|
||||||
|
public class ItemManager
|
||||||
|
{
|
||||||
|
//поля
|
||||||
|
Dictionary<string, ItemInfo> tagItemPairs;
|
||||||
|
//методы
|
||||||
|
ItemInfo GetItemInfo(string tag)
|
||||||
|
{
|
||||||
|
return tagItemPairs.GetValueOrDefault(tag);
|
||||||
|
}
|
||||||
|
void LoadItemTextures()
|
||||||
|
{
|
||||||
|
foreach (var item in tagItemPairs)
|
||||||
|
{
|
||||||
|
item.Value.LoadTexture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Initialize()
|
||||||
|
{
|
||||||
|
tagItemPairs.Add("wood", new ItemInfo("wood","wood",false,null));
|
||||||
|
tagItemPairs.Add("rock", new ItemInfo("rock", "rock", false, null));
|
||||||
|
tagItemPairs.Add("steel", new ItemInfo("steel", "steel", false, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
24
ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs
Normal file
24
ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.ItemManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс хранит информацю о количестве ресурсов у игрока
|
||||||
|
/// </summary>
|
||||||
|
internal class PlayerData
|
||||||
|
{
|
||||||
|
Dictionary<string, int> items;
|
||||||
|
/// <summary>
|
||||||
|
/// Принимает тэг и крафтит этот объект
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemTag"></param>
|
||||||
|
public void CraftItem(string itemTag)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs
Normal file
14
ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.ItemManager
|
||||||
|
{
|
||||||
|
class WeaponItemInfo:ItemInfo
|
||||||
|
{
|
||||||
|
//поля
|
||||||
|
float damage;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
using System;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
|
{
|
||||||
|
public class ClientNetworkManager
|
||||||
|
{
|
||||||
|
private IPAddress iPAddress = IPAddress.Any;
|
||||||
|
private int port = 7632;
|
||||||
|
private EndPoint endPoint;
|
||||||
|
private Socket socket;
|
||||||
|
public delegate void OnDataSent(string Data);
|
||||||
|
public event OnDataSent GetDataSent; // event
|
||||||
|
public void Init() //create endPoint, socket
|
||||||
|
{
|
||||||
|
endPoint = new IPEndPoint(iPAddress, port);
|
||||||
|
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendData()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopConnection()
|
||||||
|
{
|
||||||
|
socket.Shutdown(SocketShutdown.Both);
|
||||||
|
socket.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void JoinRoom() // multyplayer
|
||||||
|
{
|
||||||
|
SendData();
|
||||||
|
StartListening();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void JoinYourself() // single player
|
||||||
|
{
|
||||||
|
SendData();
|
||||||
|
StartListening();
|
||||||
|
}
|
||||||
|
|
||||||
|
//поток 2
|
||||||
|
public void StartListening()
|
||||||
|
{
|
||||||
|
socket.Connect(endPoint);
|
||||||
|
|
||||||
|
while(socket.Connected)
|
||||||
|
{
|
||||||
|
byte[] bytes = new byte[2048];
|
||||||
|
var countAnsw = socket.Receive(bytes);
|
||||||
|
string update = Encoding.UTF8.GetString(bytes, 0, countAnsw); // обновление отосланные сервером
|
||||||
|
GetDataSent(update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,100 @@
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Graphics.PackedVector;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
|
{
|
||||||
|
public class ServerNetworkManager
|
||||||
|
{
|
||||||
|
private IPAddress ip = IPAddress.Any;
|
||||||
|
private int port = 7632;
|
||||||
|
private IPEndPoint endPoint;
|
||||||
|
private Socket socket;
|
||||||
|
private List<Socket> clients;
|
||||||
|
private List<IUpdateData> updates;
|
||||||
|
public delegate void OnDataSend(string data);
|
||||||
|
public event OnDataSend GetDataSend; // event
|
||||||
|
Dictionary<Socket, Thread> managerThread;
|
||||||
|
|
||||||
|
|
||||||
|
public void Init() //create Socket
|
||||||
|
{
|
||||||
|
endPoint = new IPEndPoint(ip, port);
|
||||||
|
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
managerThread = new Dictionary<Socket, Thread>();
|
||||||
|
}
|
||||||
|
public void SendData() //отправляет клиенту Data
|
||||||
|
{
|
||||||
|
string data = JsonSerializer.Serialize(updates);
|
||||||
|
var databytes = Encoding.UTF8.GetBytes(data);
|
||||||
|
foreach (var item in clients)
|
||||||
|
{
|
||||||
|
item.SendAsync(databytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void AddData(IUpdateData data)//добавляет в лист updates новую data
|
||||||
|
{
|
||||||
|
updates.Add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloseConnection()
|
||||||
|
{
|
||||||
|
foreach (var item in clients)
|
||||||
|
{
|
||||||
|
item.Shutdown(SocketShutdown.Both);
|
||||||
|
item.Close();
|
||||||
|
}
|
||||||
|
foreach (var item in managerThread)
|
||||||
|
{
|
||||||
|
foreach (var socket in clients)
|
||||||
|
{
|
||||||
|
managerThread[socket].Interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
managerThread.Clear();
|
||||||
|
clients.Clear();
|
||||||
|
}
|
||||||
|
//Поток 2
|
||||||
|
|
||||||
|
public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться
|
||||||
|
{
|
||||||
|
int playNumber = (int)players;
|
||||||
|
socket.Bind(endPoint);
|
||||||
|
socket.Listen(playNumber);
|
||||||
|
for (int i = 0; i < playNumber; i++)
|
||||||
|
{
|
||||||
|
Socket client = socket.Accept();
|
||||||
|
Thread thread = new Thread(StartListening);
|
||||||
|
thread.Start(client);
|
||||||
|
managerThread.Add(client, thread);
|
||||||
|
clients.Add(client); //добавляем клиентов в лист
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartListening(object socket)//начать слушать клиентов в самой игре активируют Ивент
|
||||||
|
{
|
||||||
|
// obj to Socket
|
||||||
|
Socket client = (Socket)socket;
|
||||||
|
while (client.Connected)
|
||||||
|
{
|
||||||
|
var buff = new byte[1024];
|
||||||
|
var answ = client.Receive(buff);
|
||||||
|
string response = Encoding.UTF8.GetString(buff, 0, answ);
|
||||||
|
GetDataSend(response);
|
||||||
|
}
|
||||||
|
Thread.Sleep(-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
|
||||||
|
{
|
||||||
|
public class UpdateInput :IUpdateData
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
|
||||||
|
{
|
||||||
|
public class UpdatePlayerExit : IUpdateData
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates
|
||||||
|
{
|
||||||
|
public interface IUpdateData
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; } //Id объекта
|
||||||
|
public string UpdateType { get; set; } //тип обновления
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdateAnimation : IUpdateData //хранит новую анимации
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdateEntityHealth : IUpdateData//хранит новое хп entity
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdateGameEnded : IUpdateData //хранит полученый лут и уведомляет о конце игры
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdateGameObjectCreated : IUpdateData //Хранит объект, который только отправили
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdateLoot : IUpdateData //Хранит лут
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdatePlayerParametrs : IUpdateData //Хранит хп, радиацию
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
public class UpdatePosition : IUpdateData //Хранит новую позицию
|
||||||
|
{
|
||||||
|
public int IdEntity { get; set; }
|
||||||
|
public string UpdateType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
|
||||||
|
|
||||||
public class Update
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
7
ZoFo/GameCore/GameObjects/Bullet.cs
Normal file
7
ZoFo/GameCore/GameObjects/Bullet.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Bullet : Projectile
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
7
ZoFo/GameCore/GameObjects/Collectable.cs
Normal file
7
ZoFo/GameCore/GameObjects/Collectable.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Collectable : Entity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
11
ZoFo/GameCore/GameObjects/Enemy.cs
Normal file
11
ZoFo/GameCore/GameObjects/Enemy.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Enemy : LivingEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
29
ZoFo/GameCore/GameObjects/Entity.cs
Normal file
29
ZoFo/GameCore/GameObjects/Entity.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using ZoFo.GameCore.GameObjects;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Entity : GameObject
|
||||||
|
{
|
||||||
|
public int Id{ get; set; }
|
||||||
|
//public CollisionComponent collisionComponents{ get; set; }
|
||||||
|
//public AnimationComponent animationComponent{ get; set; }
|
||||||
|
|
||||||
|
// в апдейте может заявляет изменения позиции
|
||||||
|
public void UpdateLogic()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Методы для клиента
|
||||||
|
public void UpdateAnimation()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void Draw(ContentManager manager)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
ZoFo/GameCore/GameObjects/GunAttack.cs
Normal file
13
ZoFo/GameCore/GameObjects/GunAttack.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects
|
||||||
|
{
|
||||||
|
internal class GunAttack:IPlayerWeaponAttack
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
ZoFo/GameCore/GameObjects/HandAttack.cs
Normal file
13
ZoFo/GameCore/GameObjects/HandAttack.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects
|
||||||
|
{
|
||||||
|
internal class HandAttack:IPlayerWeaponAttack
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs
Normal file
13
ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects
|
||||||
|
{
|
||||||
|
internal interface IPlayerWeaponAttack
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
ZoFo/GameCore/GameObjects/LivingEntity.cs
Normal file
7
ZoFo/GameCore/GameObjects/LivingEntity.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class LivingEntity : Entity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
17
ZoFo/GameCore/GameObjects/LootData.cs
Normal file
17
ZoFo/GameCore/GameObjects/LootData.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects
|
||||||
|
{
|
||||||
|
internal class LootData
|
||||||
|
{
|
||||||
|
public Dictionary<string, int> loots;
|
||||||
|
public void AddLoot(object lootObject, int quantity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
ZoFo/GameCore/GameObjects/Player.cs
Normal file
7
ZoFo/GameCore/GameObjects/Player.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Player : LivingEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
7
ZoFo/GameCore/GameObjects/Projectile.cs
Normal file
7
ZoFo/GameCore/GameObjects/Projectile.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Projectile : LivingEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
7
ZoFo/GameCore/GameObjects/Rock.cs
Normal file
7
ZoFo/GameCore/GameObjects/Rock.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
public class Rock : Projectile
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
8
ZoFo/GameCore/GameObjects/StopObject.cs
Normal file
8
ZoFo/GameCore/GameObjects/StopObject.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
|
||||||
|
public class StopObject
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
13
ZoFo/GameCore/GameObjects/SwordAttack.cs
Normal file
13
ZoFo/GameCore/GameObjects/SwordAttack.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects
|
||||||
|
{
|
||||||
|
internal class SwordAttack:IPlayerWeaponAttack
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
8
ZoFo/GameCore/GameObjects/Tile.cs
Normal file
8
ZoFo/GameCore/GameObjects/Tile.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
|
||||||
|
public class Tile
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
44
ZoFo/GameCore/Server.cs
Normal file
44
ZoFo/GameCore/Server.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
|
||||||
|
using ZoFo.GameCore.GameObjects;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore
|
||||||
|
{
|
||||||
|
public class Server
|
||||||
|
{
|
||||||
|
private List<GameObject> gameObjects;
|
||||||
|
private ServerNetworkManager networkManager;
|
||||||
|
// private List<> entity; //entity
|
||||||
|
public Server()
|
||||||
|
{
|
||||||
|
networkManager = new ServerNetworkManager();
|
||||||
|
networkManager.GetDataSend += OnDataSend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDataSend(string data)
|
||||||
|
{
|
||||||
|
List<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data);
|
||||||
|
//ТУТ Switch case будет честное слово
|
||||||
|
}
|
||||||
|
public void CreateRoom(int players) {
|
||||||
|
networkManager.StartWaitingForPlayers(players);
|
||||||
|
}
|
||||||
|
// public void StartGame() { } принудительный запуск
|
||||||
|
public void EndGame() {
|
||||||
|
UpdateGameEnded gameEnded = new UpdateGameEnded();
|
||||||
|
networkManager.AddData(gameEnded);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs
Normal file
30
ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Zofo.GameCore.ZoFo_grafics;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore.Graphics
|
||||||
|
{
|
||||||
|
public class AnimationBuilder
|
||||||
|
{
|
||||||
|
public List<AnimationContainer> Animations { get; private set; }
|
||||||
|
public void LoadAnimations()
|
||||||
|
{
|
||||||
|
Animations = new List<AnimationContainer>();
|
||||||
|
string[] animationFilesNames = Directory.GetFiles("../../../Content/animations");
|
||||||
|
|
||||||
|
StreamReader reader;
|
||||||
|
foreach (var fileName in animationFilesNames)
|
||||||
|
{
|
||||||
|
reader = new StreamReader(fileName);
|
||||||
|
string json = reader.ReadToEnd();
|
||||||
|
AnimationContainer animation = JsonConvert.DeserializeObject<AnimationContainer>(json);
|
||||||
|
Animations.Add(animation);
|
||||||
|
reader.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs
Normal file
32
ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Zofo.GameCore.ZoFo_grafics
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class AnimationContainer
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
[JsonProperty("textureName")]
|
||||||
|
public string TextureName { get; set; }
|
||||||
|
[JsonProperty("startSpriteRectangle")]
|
||||||
|
public Rectangle StartSpriteRectangle { get; set; }
|
||||||
|
[JsonProperty("frameSecond")]
|
||||||
|
public List<Tuple<int, int>> FrameTime { get; set; }
|
||||||
|
[JsonProperty("textureFrameInterval")]
|
||||||
|
public int TextureFrameInterval { get; set; }
|
||||||
|
[JsonProperty("framesCount")]
|
||||||
|
public int FramesCount { get; set; }
|
||||||
|
[JsonProperty("isCycle")]
|
||||||
|
public bool IsCycle { get; set; }
|
||||||
|
[JsonProperty("offset")]
|
||||||
|
public Vector2 Offset { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
282
ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs
Normal file
282
ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs
Normal file
|
@ -0,0 +1,282 @@
|
||||||
|
using ZoFo.GameCore.GameObjects;
|
||||||
|
using ZoFo.GameCore.GameManagers;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text;
|
||||||
|
using Zofo.GameCore.ZoFo_grafics;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
|
{
|
||||||
|
|
||||||
|
public class GraphicsComponent
|
||||||
|
{
|
||||||
|
public event Action<string> actionOfAnimationEnd;
|
||||||
|
private List<AnimationContainer> animations;
|
||||||
|
private List<Texture2D> textures;
|
||||||
|
private List<string> texturesNames;
|
||||||
|
private AnimationContainer currentAnimation;
|
||||||
|
static public int scaling = 4;
|
||||||
|
public int parentId;
|
||||||
|
public AnimationContainer CurrentAnimation
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return currentAnimation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string LastAnimation { get; set; }
|
||||||
|
public string GetCurrentAnimation
|
||||||
|
{
|
||||||
|
get { return currentAnimation.Id; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private AnimationContainer neitralAnimation;
|
||||||
|
//private SpriteBatch _spriteBatch;
|
||||||
|
|
||||||
|
private int currentFrame;
|
||||||
|
public int CurrentFrame
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return currentFrame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private int interval;
|
||||||
|
private int lastInterval;
|
||||||
|
private Rectangle sourceRectangle;
|
||||||
|
public GraphicsComponent(List<string> animationsId, string neitralAnimationId)
|
||||||
|
{
|
||||||
|
//this._spriteBatch = _spriteBatch;
|
||||||
|
currentFrame = 0;
|
||||||
|
lastInterval = 1;
|
||||||
|
LoadAnimations(animationsId, neitralAnimationId);
|
||||||
|
currentAnimation = neitralAnimation;
|
||||||
|
SetInterval();
|
||||||
|
buildSourceRectangle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraphicsComponent(string textureName)
|
||||||
|
{
|
||||||
|
animations = new List<AnimationContainer>();
|
||||||
|
textures = new List<Texture2D>();
|
||||||
|
var texture = AppManager.Instance.Content.Load<Texture2D>(textureName);
|
||||||
|
textures.Add(texture);
|
||||||
|
AnimationContainer animationContainer = new AnimationContainer();
|
||||||
|
animationContainer.StartSpriteRectangle = new Rectangle(0, 0, texture.Width, texture.Height);
|
||||||
|
animationContainer.TextureFrameInterval = 0;
|
||||||
|
animationContainer.TextureName = texture.Name;
|
||||||
|
animationContainer.IsCycle = true;
|
||||||
|
animationContainer.FramesCount = 1;
|
||||||
|
animationContainer.FrameTime = new List<Tuple<int, int>>() { new Tuple<int, int>(0, 10) };
|
||||||
|
animationContainer.Id = texture.Name;
|
||||||
|
currentAnimation = animationContainer;
|
||||||
|
neitralAnimation = animationContainer;
|
||||||
|
animations.Add(animationContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadAnimations(List<string> animationsId, string neitralAnimationId)
|
||||||
|
{
|
||||||
|
animations = new List<AnimationContainer>();
|
||||||
|
foreach (var id in animationsId)
|
||||||
|
{
|
||||||
|
animations.Add(AppManager.Instance.animationBuilder.Animations.Find(x => x.Id == id));
|
||||||
|
if (id == neitralAnimationId)
|
||||||
|
{
|
||||||
|
neitralAnimation = animations.Last();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadContent()
|
||||||
|
{
|
||||||
|
textures = new List<Texture2D>();
|
||||||
|
texturesNames = new List<string>();
|
||||||
|
|
||||||
|
foreach (var animation in animations)
|
||||||
|
{
|
||||||
|
if (!texturesNames.Contains(animation.TextureName))
|
||||||
|
{
|
||||||
|
texturesNames.Add(animation.TextureName);
|
||||||
|
textures.Add(AppManager.Instance.Content.Load<Texture2D>(animation.TextureName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartAnimation(string startedanimationId)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer)
|
||||||
|
{
|
||||||
|
LivingEntity entity = AppManager.Instance.GameManager.livingEntities.Find(x => x.id == parentId);
|
||||||
|
if (((entity is Player) || AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Host) && startedanimationId != GetCurrentAnimation)
|
||||||
|
{
|
||||||
|
AppManager.Instance.NetworkTasks.Add(new NetworkTask(parentId, startedanimationId, Vector2.Zero));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
currentFrame = 0;
|
||||||
|
currentAnimation = animations.Find(x => x.Id == startedanimationId);
|
||||||
|
|
||||||
|
buildSourceRectangle();
|
||||||
|
SetInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopAnimation()
|
||||||
|
{
|
||||||
|
currentFrame = 0;
|
||||||
|
interval = 0;
|
||||||
|
currentAnimation = neitralAnimation;
|
||||||
|
buildSourceRectangle();
|
||||||
|
SetInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (interval == 0)
|
||||||
|
{
|
||||||
|
currentFrame++;
|
||||||
|
if (currentAnimation.FramesCount <= currentFrame)
|
||||||
|
{
|
||||||
|
if (!currentAnimation.IsCycle)
|
||||||
|
{
|
||||||
|
if (actionOfAnimationEnd != null)
|
||||||
|
{
|
||||||
|
actionOfAnimationEnd(currentAnimation.Id);
|
||||||
|
}
|
||||||
|
currentAnimation = neitralAnimation;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFrame = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
buildSourceRectangle();
|
||||||
|
SetInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
interval--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
|
||||||
|
float scale;
|
||||||
|
if (currentAnimation.Offset.X != 0)
|
||||||
|
{
|
||||||
|
destinationRectangle.X -= (int)currentAnimation.Offset.X;
|
||||||
|
scale = destinationRectangle.Height / sourceRectangle.Height;
|
||||||
|
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (currentAnimation.Offset.Y != 0)
|
||||||
|
{
|
||||||
|
destinationRectangle.Y -= (int)currentAnimation.Offset.Y;
|
||||||
|
scale = destinationRectangle.Width / sourceRectangle.Width;
|
||||||
|
destinationRectangle.Height = (int)(sourceRectangle.Height * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
destinationRectangle.X -= CameraPosition.X;
|
||||||
|
destinationRectangle.Y -= CameraPosition.Y;
|
||||||
|
|
||||||
|
destinationRectangle = Scaling(destinationRectangle);
|
||||||
|
_spriteBatch.Draw(texture,
|
||||||
|
destinationRectangle, sourceRectangle, Color.White);
|
||||||
|
}
|
||||||
|
public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle)
|
||||||
|
{
|
||||||
|
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
|
||||||
|
float scale;
|
||||||
|
if (currentAnimation.Offset.X != 0)
|
||||||
|
{
|
||||||
|
destinationRectangle.X -= (int)currentAnimation.Offset.X;
|
||||||
|
scale = destinationRectangle.Height / sourceRectangle.Height;
|
||||||
|
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (currentAnimation.Offset.Y != 0)
|
||||||
|
{
|
||||||
|
destinationRectangle.Y -= (int)currentAnimation.Offset.Y;
|
||||||
|
scale = destinationRectangle.Width / sourceRectangle.Width;
|
||||||
|
destinationRectangle.Height = (int)(sourceRectangle.Height * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
destinationRectangle.X -= CameraPosition.X;
|
||||||
|
destinationRectangle.Y -= CameraPosition.Y;
|
||||||
|
|
||||||
|
destinationRectangle = Scaling(destinationRectangle);
|
||||||
|
_spriteBatch.Draw(texture,
|
||||||
|
destinationRectangle, sourceRectangle, Color.White);
|
||||||
|
}
|
||||||
|
private Rectangle Scaling(Rectangle destinationRectangle)
|
||||||
|
{
|
||||||
|
destinationRectangle.X *= scaling;
|
||||||
|
destinationRectangle.Y *= scaling;
|
||||||
|
destinationRectangle.Width *= scaling;
|
||||||
|
destinationRectangle.Height *= scaling;
|
||||||
|
return destinationRectangle;
|
||||||
|
}
|
||||||
|
private void buildSourceRectangle()
|
||||||
|
{
|
||||||
|
sourceRectangle = new Rectangle();
|
||||||
|
if (currentAnimation == null)
|
||||||
|
{
|
||||||
|
currentAnimation = neitralAnimation;
|
||||||
|
}
|
||||||
|
sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame *
|
||||||
|
(currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval);
|
||||||
|
sourceRectangle.Y = currentAnimation.StartSpriteRectangle.Y;
|
||||||
|
sourceRectangle.Height = currentAnimation.StartSpriteRectangle.Height;
|
||||||
|
sourceRectangle.Width = currentAnimation.StartSpriteRectangle.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetInterval()
|
||||||
|
{
|
||||||
|
Tuple<int, int> i = currentAnimation.FrameTime.Find(x => x.Item1 == currentFrame);
|
||||||
|
if (i != null)
|
||||||
|
{
|
||||||
|
interval = i.Item2;
|
||||||
|
lastInterval = interval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
interval = lastInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void SetCameraPosition(Vector2 playerPosition)
|
||||||
|
{
|
||||||
|
CameraPosition = (playerPosition).ToPoint();
|
||||||
|
CameraPosition.X -= 200;
|
||||||
|
CameraPosition.Y -= 120;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
/*
|
||||||
|
if (CameraPosition.X > AppManager.Instance.GameManager.CameraBorder.Y - 460)
|
||||||
|
{
|
||||||
|
CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.Y - 460;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CameraPosition.Y < AppManager.Instance.GameManager.CameraBorder.Z)
|
||||||
|
{
|
||||||
|
CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.Z;
|
||||||
|
}
|
||||||
|
if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X)
|
||||||
|
{
|
||||||
|
CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X;
|
||||||
|
}
|
||||||
|
if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 240)
|
||||||
|
{
|
||||||
|
CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 240;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}");
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
public static Point CameraPosition = new Point(-700, 300);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,2 @@
|
||||||
using var game = new ZoFo.Game1();
|
using var game = new ZoFo.GameCore.GameManagers.AppManager();
|
||||||
game.Run();
|
game.Run();
|
|
@ -11,22 +11,26 @@
|
||||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="Icon.ico"/>
|
<None Remove="Icon.ico" />
|
||||||
<None Remove="Icon.bmp"/>
|
<None Remove="Icon.bmp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Icon.ico"/>
|
<EmbeddedResource Include="Icon.ico" />
|
||||||
<EmbeddedResource Include="Icon.bmp"/>
|
<EmbeddedResource Include="Icon.bmp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303"/>
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
|
||||||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303"/>
|
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\MonogameLibrary\MonogameLibrary.csproj" />
|
<ProjectReference Include="..\MonogameLibrary\MonogameLibrary.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Content\Texture\GUI\" />
|
||||||
|
</ItemGroup>
|
||||||
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
|
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
|
||||||
<Message Text="Restoring dotnet tools" Importance="High"/>
|
<Message Text="Restoring dotnet tools" Importance="High" />
|
||||||
<Exec Command="dotnet tool restore"/>
|
<Exec Command="dotnet tool restore" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
11
macos-fix-mgcb.sh
Executable file
11
macos-fix-mgcb.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
brew install freetype
|
||||||
|
brew install freeimage
|
||||||
|
mgcb_ver=$(ls ~/.nuget/packages/dotnet-mgcb/)
|
||||||
|
mgcb_path=~/.nuget/packages/dotnet-mgcb/$mgcb_ver/tools/net6.0/any/
|
||||||
|
|
||||||
|
rm $mgcb_path/libfreetype6.dylib $mgcb_path/libFreeImage.dylib
|
||||||
|
|
||||||
|
ln -s /opt/homebrew/lib/libfreetype.dylib $mgcb_path/libfreetype6.dylib
|
||||||
|
ln -s /opt/homebrew/lib/libfreeimage.dylib $mgcb_path/libFreeImage.dylib
|
Loading…
Add table
Reference in a new issue