Merge branch 'Development' into UpgradeInputManager
17
AnimationsFileCreator/AnimationsFileCreator.csproj
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ZoFo\ZoFo.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NativeFileDialogSharp" Version="0.6.0-alpha" />
|
||||||
|
<PackageReference Include="SharpZipLib" Version="1.4.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
72
AnimationsFileCreator/Program.cs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
using DangerousD.GameCore.Graphics;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using NativeFileDialogSharp;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata;
|
||||||
|
using Zofo.GameCore.ZoFo_grafics;
|
||||||
|
|
||||||
|
namespace AnimationsFileCreator
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
[STAThread]
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Добро пожаловать в костыльную программу по созданию файлов анимации для игры DungerousD");
|
||||||
|
Console.Write("Введите название текстуры (нажмите enter, чтобы выбрать файл во всплывающем окошке): ");
|
||||||
|
string textureName = Console.ReadLine();
|
||||||
|
if (textureName == "")
|
||||||
|
{
|
||||||
|
|
||||||
|
DialogResult result = Dialog.FileOpen();
|
||||||
|
textureName = result.Path.Split('\\').Last();
|
||||||
|
textureName = textureName.Split('.')[0];
|
||||||
|
}
|
||||||
|
Console.WriteLine("Введите количество кадров анимации: ");
|
||||||
|
int framesCount = int.Parse(Console.ReadLine());
|
||||||
|
Console.WriteLine("Введите длительность кадра в анимации: ");
|
||||||
|
int interval = int.Parse(Console.ReadLine());
|
||||||
|
Console.WriteLine("Введите начальную позицию X ректенгла анимации: ");
|
||||||
|
Rectangle rectangle = new Rectangle();
|
||||||
|
rectangle.X = int.Parse(Console.ReadLine());
|
||||||
|
Console.WriteLine("Введите начальную позицию Y ректенгла анимации: ");
|
||||||
|
rectangle.Y = int.Parse(Console.ReadLine());
|
||||||
|
Console.WriteLine("Введите начальную позицию Width ректенгла анимации: ");
|
||||||
|
rectangle.Width = int.Parse(Console.ReadLine());
|
||||||
|
Console.WriteLine("Введите начальную позицию Height ректенгла анимации: ");
|
||||||
|
rectangle.Height = int.Parse(Console.ReadLine());
|
||||||
|
Console.WriteLine("Введите название для этого файла - id анимации");
|
||||||
|
string id = Console.ReadLine();
|
||||||
|
Console.WriteLine("Введите 1 если анимация зациклена, и 0 если нет");
|
||||||
|
AnimationContainer container = new AnimationContainer();
|
||||||
|
|
||||||
|
int a = int.Parse(Console.ReadLine());
|
||||||
|
if (a==1)
|
||||||
|
{
|
||||||
|
container.IsCycle = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
container.IsCycle = false;
|
||||||
|
}
|
||||||
|
Console.WriteLine("Введите отклонение анимации от стандартной (сначала X, потом enter, потом Y): ");
|
||||||
|
int otklx = int.Parse(Console.ReadLine());
|
||||||
|
int otkly = int.Parse(Console.ReadLine());
|
||||||
|
container.Offset =new Vector2(otklx,otkly);
|
||||||
|
container.FramesCount = framesCount;
|
||||||
|
container.FrameTime = new System.Collections.Generic.List<Tuple<int, int>>();
|
||||||
|
container.FrameTime.Add(new Tuple<int, int>(0, interval));
|
||||||
|
container.StartSpriteRectangle = rectangle;
|
||||||
|
container.TextureName = textureName;
|
||||||
|
container.TextureFrameInterval = 1;
|
||||||
|
container.Id = id;
|
||||||
|
string json = JsonConvert.SerializeObject(container);
|
||||||
|
StreamWriter writer = new StreamWriter("../../../../ZoFo/Content/animations/"+id);
|
||||||
|
writer.WriteLine(json);
|
||||||
|
writer.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ namespace MonogameLibrary.UI.Elements
|
||||||
public int indentation = 5;
|
public int indentation = 5;
|
||||||
|
|
||||||
Texture2D texture2;
|
Texture2D texture2;
|
||||||
public Rectangle sliderRect = new Rectangle(0, 0, 30, 30);
|
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;
|
||||||
SliderState sliderState = SliderState.None;
|
SliderState sliderState = SliderState.None;
|
||||||
|
@ -56,7 +56,7 @@ namespace MonogameLibrary.UI.Elements
|
||||||
|
|
||||||
public override void LoadTexture(ContentManager content)
|
public override void LoadTexture(ContentManager content)
|
||||||
{
|
{
|
||||||
texture2 = content.Load<Texture2D>("Textures\\GUI\\checkboxs_off");
|
texture2 = content.Load<Texture2D>("Textures\\GUI\\switch");
|
||||||
base.LoadTexture(content);
|
base.LoadTexture(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,11 +73,11 @@ namespace MonogameLibrary.UI.Elements
|
||||||
sliderRect.X += (int)(sliderValue * (rectangle.Width - sliderRect.Width - indentation * 2) + indentation);
|
sliderRect.X += (int)(sliderValue * (rectangle.Width - sliderRect.Width - indentation * 2) + indentation);
|
||||||
sliderRect.Y -= sliderRect.Height / 2 - rectangle.Height / 2;
|
sliderRect.Y -= sliderRect.Height / 2 - rectangle.Height / 2;
|
||||||
if (sliderState == SliderState.Moving)
|
if (sliderState == SliderState.Moving)
|
||||||
_spriteBatch.Draw(texture2, sliderRect, Color.DarkRed);
|
_spriteBatch.Draw(texture2, sliderRect, Color.Gray);
|
||||||
else if(sliderState == SliderState.HoveringOverSliderButton)
|
else if(sliderState == SliderState.HoveringOverSliderButton)
|
||||||
_spriteBatch.Draw(texture2, sliderRect, new Color(200,0 ,0));
|
_spriteBatch.Draw(texture2, sliderRect, Color.DarkGray);
|
||||||
else
|
else
|
||||||
_spriteBatch.Draw(texture2, sliderRect, Color.Red);
|
_spriteBatch.Draw(texture2, sliderRect, Color.White);
|
||||||
DrawText(_spriteBatch);
|
DrawText(_spriteBatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
ZoFo.sln
|
@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZoFo", "ZoFo\ZoFo.csproj",
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonogameLibrary", "MonogameLibrary\MonogameLibrary.csproj", "{40880E68-4B3A-417B-A39B-95DE46AA2E7E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonogameLibrary", "MonogameLibrary\MonogameLibrary.csproj", "{40880E68-4B3A-417B-A39B-95DE46AA2E7E}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationsFileCreator", "AnimationsFileCreator\AnimationsFileCreator.csproj", "{7B143D5C-5198-4ADE-9291-ECC924B78633}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -21,6 +23,10 @@ Global
|
||||||
{40880E68-4B3A-417B-A39B-95DE46AA2E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{40880E68-4B3A-417B-A39B-95DE46AA2E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{40880E68-4B3A-417B-A39B-95DE46AA2E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{40880E68-4B3A-417B-A39B-95DE46AA2E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{40880E68-4B3A-417B-A39B-95DE46AA2E7E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{40880E68-4B3A-417B-A39B-95DE46AA2E7E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7B143D5C-5198-4ADE-9291-ECC924B78633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7B143D5C-5198-4ADE-9291-ECC924B78633}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7B143D5C-5198-4ADE-9291-ECC924B78633}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7B143D5C-5198-4ADE-9291-ECC924B78633}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -27,6 +27,13 @@
|
||||||
/processorParam:TextureFormat=Compressed
|
/processorParam:TextureFormat=Compressed
|
||||||
/build:Fonts/Font2.spritefont
|
/build:Fonts/Font2.spritefont
|
||||||
|
|
||||||
|
#begin Fonts/Font3.spritefont
|
||||||
|
/importer:FontDescriptionImporter
|
||||||
|
/processor:FontDescriptionProcessor
|
||||||
|
/processorParam:PremultiplyAlpha=True
|
||||||
|
/processorParam:TextureFormat=Compressed
|
||||||
|
/build:Fonts/Font3.spritefont
|
||||||
|
|
||||||
#begin Textures/GUI/checkboxs_off-on.png
|
#begin Textures/GUI/checkboxs_off-on.png
|
||||||
/importer:TextureImporter
|
/importer:TextureImporter
|
||||||
/processor:TextureProcessor
|
/processor:TextureProcessor
|
||||||
|
@ -75,3 +82,39 @@
|
||||||
/processorParam:TextureFormat=Color
|
/processorParam:TextureFormat=Color
|
||||||
/build:Textures/GUI/MenuBackground.jpg
|
/build:Textures/GUI/MenuBackground.jpg
|
||||||
|
|
||||||
|
#begin Textures/GUI/mouse.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/mouse.png
|
||||||
|
|
||||||
|
#begin Textures/GUI/Switch_backgrownd.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/Switch_backgrownd.png
|
||||||
|
|
||||||
|
#begin Textures/GUI/switch.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/switch.png
|
||||||
|
|
||||||
|
|
60
ZoFo/Content/Fonts/Font3.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>MouldyCheeseRegular-WyMWG.ttf</FontName>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Size is a float value, measured in points. Modify this value to change
|
||||||
|
the size of the font.
|
||||||
|
-->
|
||||||
|
<Size>50</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/Fonts/MouldyCheeseRegular-WyMWG.ttf
Normal file
BIN
ZoFo/Content/Textures/GUI/Switch_backgrownd.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.9 KiB |
BIN
ZoFo/Content/Textures/GUI/mouse.png
Normal file
After Width: | Height: | Size: 234 KiB |
BIN
ZoFo/Content/Textures/GUI/switch.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
|
@ -27,12 +27,14 @@ namespace ZoFo.GameCore
|
||||||
|
|
||||||
public void GameEndedUnexpectedly(){ }
|
public void GameEndedUnexpectedly(){ }
|
||||||
|
|
||||||
public void JoinRoom(){ }
|
public void JoinRoom(string ip)
|
||||||
|
{
|
||||||
public void JoinYourself(){ }
|
networkManager.JoinRoom(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void JoinYourself(){ networkManager.JoinYourself(); }
|
||||||
internal void Update(GameTime gameTime)
|
internal void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Draw(SpriteBatch spriteBatch)
|
internal void Draw(SpriteBatch spriteBatch)
|
||||||
|
|
|
@ -21,6 +21,8 @@ public abstract class AbstractGUI
|
||||||
protected DrawableUIElement SelectedElement;
|
protected DrawableUIElement SelectedElement;
|
||||||
private bool isStartedPrint = false;
|
private bool isStartedPrint = false;
|
||||||
private bool isPressed = false;
|
private bool isPressed = false;
|
||||||
|
private Texture2D mouse;
|
||||||
|
private MouseState mouseState;
|
||||||
|
|
||||||
public AbstractGUI()
|
public AbstractGUI()
|
||||||
{
|
{
|
||||||
|
@ -37,20 +39,20 @@ public abstract class AbstractGUI
|
||||||
public virtual void LoadContent()
|
public virtual void LoadContent()
|
||||||
{
|
{
|
||||||
Manager.LoadContent(AppManager.Instance.Content, "Font");
|
Manager.LoadContent(AppManager.Instance.Content, "Font");
|
||||||
|
mouse = AppManager.Instance.Content.Load<Texture2D>("Textures\\GUI\\mouse");
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Update(GameTime gameTime)
|
public virtual void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
Manager.Update(gameTime);
|
Manager.Update(gameTime);
|
||||||
|
mouseState = Mouse.GetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Draw(SpriteBatch spriteBatch)
|
public virtual void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
Manager.Draw(spriteBatch);
|
Manager.Draw(spriteBatch);
|
||||||
}
|
spriteBatch.Begin();
|
||||||
|
spriteBatch.Draw(mouse, new Rectangle(mouseState.Position.X, mouseState.Position.Y, 20, 40), Color.Red);
|
||||||
public virtual void ResolutioChenges()
|
spriteBatch.End();
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
@ -20,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\\MenuBackground" };
|
||||||
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.White, 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",
|
||||||
|
@ -37,12 +38,12 @@ public class MainMenuGUI : AbstractGUI
|
||||||
mainColor = Color.Gray,
|
mainColor = Color.Gray,
|
||||||
fontName = "Fonts\\Font"
|
fontName = "Fonts\\Font"
|
||||||
};
|
};
|
||||||
playButton.LeftButtonPressed += () =>
|
playButton.LeftButtonPressed += () =>
|
||||||
{
|
{
|
||||||
|
AppManager.Instance.SetGUI(new SelectModeMenu());
|
||||||
};
|
};
|
||||||
Elements.Add(playButton);
|
Elements.Add(playButton);
|
||||||
Button optionButton = new Button(Manager)
|
Button optionButton = new Button(Manager)
|
||||||
{
|
{
|
||||||
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 2, (int)(width / 5), (int)(height / 20)),
|
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 2, (int)(width / 5), (int)(height / 20)),
|
||||||
text = "Options",
|
text = "Options",
|
||||||
|
@ -51,12 +52,12 @@ public class MainMenuGUI : AbstractGUI
|
||||||
mainColor = Color.Gray,
|
mainColor = Color.Gray,
|
||||||
fontName = "Fonts\\Font"
|
fontName = "Fonts\\Font"
|
||||||
};
|
};
|
||||||
optionButton.LeftButtonPressed += () =>
|
optionButton.LeftButtonPressed += () =>
|
||||||
{
|
{
|
||||||
AppManager.Instance.SetGUI(new OptionsGUI());
|
AppManager.Instance.SetGUI(new OptionsGUI());
|
||||||
};
|
};
|
||||||
Elements.Add(optionButton);
|
Elements.Add(optionButton);
|
||||||
Button exitButton = new Button(Manager)
|
Button exitButton = new Button(Manager)
|
||||||
{
|
{
|
||||||
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 3, (int)(width / 5), (int)(height / 20)),
|
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 3, (int)(width / 5), (int)(height / 20)),
|
||||||
text = "Exit",
|
text = "Exit",
|
||||||
|
@ -65,15 +66,14 @@ public class MainMenuGUI : AbstractGUI
|
||||||
mainColor = Color.Gray,
|
mainColor = Color.Gray,
|
||||||
fontName = "Fonts\\Font"
|
fontName = "Fonts\\Font"
|
||||||
};
|
};
|
||||||
exitButton.LeftButtonPressed += () =>
|
exitButton.LeftButtonPressed += () =>
|
||||||
{
|
{
|
||||||
AppManager.Instance.Exit();
|
AppManager.Instance.Exit();
|
||||||
};
|
};
|
||||||
Elements.Add(exitButton);
|
Elements.Add(exitButton);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
|
|
|
@ -30,11 +30,11 @@ public class OptionsGUI : AbstractGUI
|
||||||
|
|
||||||
|
|
||||||
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, 50, 50), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
{ 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 };
|
||||||
Elements.Add(label_OverallVolume);
|
Elements.Add(label_OverallVolume);
|
||||||
|
|
||||||
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\\checkbox_on", MinValue = 0, MaxValue = 1 };
|
{ rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
|
||||||
slider_OverallVolume.SliderChanged += (newVal) =>
|
slider_OverallVolume.SliderChanged += (newVal) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -42,11 +42,11 @@ public class OptionsGUI : AbstractGUI
|
||||||
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, 50, 50), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
{ 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 };
|
||||||
Elements.Add(label_MusicVolume);
|
Elements.Add(label_MusicVolume);
|
||||||
|
|
||||||
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\\checkboxs_on", MinValue = 0, MaxValue = 1 };
|
{ 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 };
|
||||||
slider_MusicVolume.SliderChanged += (newVal) =>
|
slider_MusicVolume.SliderChanged += (newVal) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -55,11 +55,11 @@ public class OptionsGUI : AbstractGUI
|
||||||
|
|
||||||
|
|
||||||
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, 50, 50), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
{ 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 };
|
||||||
Elements.Add(label_EffectsVolume);
|
Elements.Add(label_EffectsVolume);
|
||||||
|
|
||||||
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\\checkboxs_on", MinValue = 0, MaxValue = 1 };
|
{ 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 };
|
||||||
slider_EffectsVolume.SliderChanged += (newVal) =>
|
slider_EffectsVolume.SliderChanged += (newVal) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class OptionsGUI : AbstractGUI
|
||||||
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 = "Left/Right Mode", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, 50, 50), mainColor = Color.Transparent};
|
{ 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 };
|
||||||
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) };
|
||||||
|
@ -76,10 +76,10 @@ 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, 50, 50), mainColor = Color.Transparent};
|
{ 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 };
|
||||||
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 / 30, width / 30) };
|
var button_FullScreen = new CheckBox(Manager) { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40) };
|
||||||
button_FullScreen.Checked += (newCheckState) =>
|
button_FullScreen.Checked += (newCheckState) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -88,11 +88,11 @@ public class OptionsGUI : AbstractGUI
|
||||||
|
|
||||||
|
|
||||||
Button bTExit = new Button(Manager)
|
Button bTExit = new Button(Manager)
|
||||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "<-", rectangle = new Rectangle(width / 30, height / 30, 40, 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);
|
||||||
bTExit.LeftButtonPressed += () =>
|
bTExit.LeftButtonPressed += () =>
|
||||||
{
|
{
|
||||||
|
AppManager.Instance.SetGUI(new MainMenuGUI());
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,60 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MonogameLibrary.UI.Base;
|
using MonogameLibrary.UI.Base;
|
||||||
using MonogameLibrary.UI.Elements;
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using ZoFo.GameCore.GameManagers;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GUI;
|
namespace ZoFo.GameCore.GUI;
|
||||||
|
|
||||||
public class SelectModeMenu : AbstractGUI
|
public class SelectModeMenu : AbstractGUI
|
||||||
{
|
{
|
||||||
|
private DrawableUIElement menuBackground;
|
||||||
protected override void CreateUI()
|
protected override void CreateUI()
|
||||||
{
|
{
|
||||||
// int width = AppManager.Instance.inGameHUDHelperResolution.X;
|
int width = AppManager.Instance.CurentScreenResolution.X;
|
||||||
// int height = AppManager.Instance.inGameHUDHelperResolution.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" };
|
||||||
|
Elements.Add(menuBackground);
|
||||||
|
menuBackground.LoadTexture(AppManager.Instance.Content);
|
||||||
|
|
||||||
|
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 6, (int)(width / 4), (int)(height / 20)), text = "Select mode", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"});
|
||||||
|
|
||||||
|
Button playButton = new Button(Manager)
|
||||||
|
{
|
||||||
|
rectangle = new Rectangle(width / 4 - (width / 7) / 2, height / 2, (int)(width / 7), (int)(height / 20)),
|
||||||
|
text = "singleplayer",
|
||||||
|
scale = 0.3f,
|
||||||
|
fontColor = Color.White,
|
||||||
|
mainColor = Color.Gray,
|
||||||
|
fontName = "Fonts\\Font"
|
||||||
|
};
|
||||||
|
playButton.LeftButtonPressed += () =>
|
||||||
|
{
|
||||||
|
// single
|
||||||
|
|
||||||
|
// ваш код здесь
|
||||||
|
};
|
||||||
|
Elements.Add(playButton);
|
||||||
|
Button optionButton = new Button(Manager)
|
||||||
|
{
|
||||||
|
rectangle = new Rectangle(width / 2 + width / 4 - (width / 7) / 2, height / 2, (int)(width / 7), (int)(height / 20)),
|
||||||
|
text = "multiplayer",
|
||||||
|
scale = 0.3f,
|
||||||
|
fontColor = Color.White,
|
||||||
|
mainColor = Color.Gray,
|
||||||
|
fontName = "Fonts\\Font"
|
||||||
|
};
|
||||||
|
optionButton.LeftButtonPressed += () =>
|
||||||
|
{
|
||||||
|
// multi
|
||||||
|
|
||||||
|
// ваш код здесь
|
||||||
|
};
|
||||||
|
Elements.Add(optionButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,9 +20,9 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
{
|
{
|
||||||
private GraphicsDeviceManager _graphics;
|
private GraphicsDeviceManager _graphics;
|
||||||
private SpriteBatch _spriteBatch;
|
private SpriteBatch _spriteBatch;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static AppManager Instance { get; private set; }
|
public static AppManager Instance { get; private set; }
|
||||||
public GameState gamestate;
|
public GameState gamestate;
|
||||||
public AbstractGUI currentGUI;
|
public AbstractGUI currentGUI;
|
||||||
|
@ -31,13 +31,13 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
public Client client;
|
public Client client;
|
||||||
public Server server;
|
public Server server;
|
||||||
|
|
||||||
|
|
||||||
#region Managers
|
#region Managers
|
||||||
|
|
||||||
public InputManager InputManager;
|
public InputManager InputManager;
|
||||||
public ItemManager.ItemManager ItemManager;
|
public ItemManager.ItemManager ItemManager;
|
||||||
|
|
||||||
public AnimationBuilder animationBuilder{get;set; }
|
public AnimationBuilder animationBuilder { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -45,27 +45,27 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
{
|
{
|
||||||
_graphics = new GraphicsDeviceManager(this);
|
_graphics = new GraphicsDeviceManager(this);
|
||||||
SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y);
|
SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y);
|
||||||
FulscrreenSwitch();
|
// FulscrreenSwitch();
|
||||||
|
|
||||||
|
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
IsMouseVisible = true;
|
IsMouseVisible = true;
|
||||||
|
|
||||||
Instance = this;
|
Instance = this;
|
||||||
InputManager = new InputManager();
|
InputManager = new InputManager();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
currentGUI = new MainMenuGUI();
|
currentGUI = new MainMenuGUI();
|
||||||
debugHud = new DebugHUD();
|
debugHud = new DebugHUD();
|
||||||
|
IsMouseVisible = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
currentGUI.Initialize();
|
currentGUI.Initialize();
|
||||||
debugHud.Initialize();
|
debugHud.Initialize();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
@ -86,9 +86,9 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
|
||||||
Keyboard.GetState().IsKeyDown(Keys.Escape))
|
Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||||
Exit();
|
Exit();
|
||||||
|
|
||||||
debugHud.Set("key", "value");
|
debugHud.Set("key", "value");
|
||||||
|
|
||||||
InputManager.Update();
|
InputManager.Update();
|
||||||
currentGUI.Update(gameTime);
|
currentGUI.Update(gameTime);
|
||||||
switch (gamestate)
|
switch (gamestate)
|
||||||
|
@ -113,14 +113,13 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
{
|
{
|
||||||
GraphicsDevice.Clear(Color.CornflowerBlue);
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
|
||||||
|
|
||||||
currentGUI.Draw(_spriteBatch);
|
currentGUI.Draw(_spriteBatch);
|
||||||
debugHud.Draw(_spriteBatch);
|
debugHud.Draw(_spriteBatch);
|
||||||
switch (gamestate)
|
switch (gamestate)
|
||||||
{
|
{
|
||||||
case GameState.ClientPlaying:
|
case GameState.ClientPlaying:
|
||||||
case GameState.HostPlaying:
|
case GameState.HostPlaying:
|
||||||
client.Draw(_spriteBatch);
|
client.Draw(_spriteBatch);
|
||||||
break;
|
break;
|
||||||
case GameState.NotPlaying:
|
case GameState.NotPlaying:
|
||||||
default:
|
default:
|
||||||
|
@ -135,7 +134,7 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
}
|
}
|
||||||
public void SetGUI(AbstractGUI gui)
|
public void SetGUI(AbstractGUI gui)
|
||||||
{
|
{
|
||||||
currentGUI = gui;
|
currentGUI = gui;
|
||||||
currentGUI.Initialize();
|
currentGUI.Initialize();
|
||||||
currentGUI.LoadContent();
|
currentGUI.LoadContent();
|
||||||
|
|
||||||
|
@ -157,5 +156,8 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
{
|
{
|
||||||
_graphics.IsFullScreen = !_graphics.IsFullScreen;
|
_graphics.IsFullScreen = !_graphics.IsFullScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetServer(Server server) { this.server = server; }
|
||||||
|
public void SetClient(Client client) { this.client = client; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||||
|
@ -20,6 +21,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
List<IUpdateData> updates = new List<IUpdateData>();
|
List<IUpdateData> updates = new List<IUpdateData>();
|
||||||
public delegate void OnDataSent(string Data);
|
public delegate void OnDataSent(string Data);
|
||||||
public event OnDataSent GetDataSent; // event
|
public event OnDataSent GetDataSent; // event
|
||||||
|
|
||||||
|
public ClientNetworkManager()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -27,11 +34,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
|
|
||||||
public void SendData()
|
public void SendData()
|
||||||
{
|
{
|
||||||
while(socket.Connected)
|
byte[] bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(updates)); //нужно сериализовать
|
||||||
{
|
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(updates.ToString());
|
|
||||||
socket.Send(bytes);
|
socket.Send(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddData(IUpdateData UpdateData)
|
||||||
|
{
|
||||||
|
updates.Add(UpdateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopConnection()
|
public void StopConnection()
|
||||||
|
@ -47,24 +56,21 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
/// <param name="port"></param>
|
/// <param name="port"></param>
|
||||||
public void JoinRoom(string ip) // multyplayer
|
public void JoinRoom(string ip) // multyplayer
|
||||||
{
|
{
|
||||||
|
|
||||||
endPoint = new IPEndPoint(IPAddress.Parse(ip), port);
|
endPoint = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||||
|
|
||||||
socket.Connect(endPoint);
|
socket.Connect(endPoint);
|
||||||
|
|
||||||
SendData();
|
SendData();
|
||||||
Thread listen = new Thread(StartListening);
|
Thread listen = new Thread(StartListening);
|
||||||
listen.Start();
|
listen.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// создается
|
/// создается одиночная комната к которой ты подключаешься
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void JoinYourself() // single player
|
public void JoinYourself() // single player
|
||||||
{
|
{
|
||||||
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
|
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
|
||||||
|
|
||||||
socket.Connect(endPoint);
|
socket.Connect(endPoint);
|
||||||
|
|
||||||
SendData();
|
SendData();
|
||||||
Thread listen = new Thread(StartListening);
|
Thread listen = new Thread(StartListening);
|
||||||
listen.Start();
|
listen.Start();
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
{
|
{
|
||||||
public class ServerNetworkManager
|
public class ServerNetworkManager
|
||||||
{
|
{
|
||||||
private IPAddress ip = IPAddress.Any;
|
private IPAddress ip =IPAddress.Parse("127.0.0.1"); //IPAddress.Any
|
||||||
private int port = 7632;
|
private int port = 7632;
|
||||||
private IPEndPoint endPoint;
|
private IPEndPoint endPoint;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
|
@ -25,14 +25,23 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
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;
|
||||||
|
Thread serverTheread;
|
||||||
|
|
||||||
|
public ServerNetworkManager() { Init(); }
|
||||||
|
|
||||||
public void Init() //create Socket
|
public void Init() //create Socket
|
||||||
{
|
{
|
||||||
endPoint = new IPEndPoint(ip, port);
|
endPoint = new IPEndPoint(ip, port);
|
||||||
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>();
|
||||||
|
updates = new List<IUpdateData>();
|
||||||
|
managerThread = new Dictionary<Socket, Thread>();
|
||||||
}
|
}
|
||||||
public void SendData() //отправляет клиенту Data
|
/// <summary>
|
||||||
|
/// отправляет клиенту Data
|
||||||
|
/// </summary>
|
||||||
|
public void SendData()
|
||||||
{
|
{
|
||||||
string data = JsonSerializer.Serialize(updates);
|
string data = JsonSerializer.Serialize(updates);
|
||||||
var databytes = Encoding.UTF8.GetBytes(data);
|
var databytes = Encoding.UTF8.GetBytes(data);
|
||||||
|
@ -41,10 +50,14 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
item.SendAsync(databytes);
|
item.SendAsync(databytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void AddData(IUpdateData data)//добавляет в лист updates новую data
|
/// <summary>
|
||||||
|
/// добавляет в лист updates новую data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
public void AddData(IUpdateData data)
|
||||||
{
|
{
|
||||||
updates.Add(data);
|
updates.Add(data);
|
||||||
}
|
}
|
||||||
public void CloseConnection() //По сути коне игры и отключение игроков
|
public void CloseConnection() //По сути коне игры и отключение игроков
|
||||||
{
|
{
|
||||||
foreach (var item in clients)
|
foreach (var item in clients)
|
||||||
|
@ -66,6 +79,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
||||||
clients.Clear();
|
clients.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Start(object players)
|
||||||
|
{
|
||||||
|
serverTheread = new Thread(StartWaitingForPlayers);
|
||||||
|
serverTheread.Start(players);
|
||||||
|
}
|
||||||
|
|
||||||
//Потоки Клиентов
|
//Потоки Клиентов
|
||||||
public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться
|
public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться
|
||||||
{
|
{
|
||||||
|
|
93
ZoFo/GameCore/GameManagers/SettingsManager.cs
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers
|
||||||
|
{
|
||||||
|
public class SettingsManager //нужно что-то менять с разрешением
|
||||||
|
{
|
||||||
|
private SettingsContainer settingsContainer = new SettingsContainer();
|
||||||
|
public bool IsFullScreen { get => settingsContainer.IsFullScreen; }
|
||||||
|
public float MainVolume { get => settingsContainer.MainVolume; }
|
||||||
|
public float MusicVolume { get => settingsContainer.MusicVolume; }
|
||||||
|
public float SoundEffectsVolume { get => settingsContainer.SoundEffectsVolume; }
|
||||||
|
public Point Resolution { get => settingsContainer.Resolution; }
|
||||||
|
public void SetResolution(Point resolution)
|
||||||
|
{
|
||||||
|
settingsContainer.Resolution = resolution;
|
||||||
|
//AppManager.Instance.resolution = resolution;
|
||||||
|
}
|
||||||
|
public void SetMainVolume(float volume)
|
||||||
|
{
|
||||||
|
settingsContainer.MainVolume = volume;
|
||||||
|
//AppManager.Instance.SoundManager.Update();
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
public void SetMusicVolume(float volume)
|
||||||
|
{
|
||||||
|
settingsContainer.MusicVolume = volume;
|
||||||
|
SaveSettings();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void SetSoundEffectsVolume(float volume)
|
||||||
|
{
|
||||||
|
settingsContainer.SoundEffectsVolume = volume;
|
||||||
|
SaveSettings();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void SetIsFullScreen(bool isFullScreen)
|
||||||
|
{
|
||||||
|
settingsContainer.IsFullScreen = isFullScreen;
|
||||||
|
//AppManager.Instance.SetIsFullScreen(isFullScreen);
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
public void LoadSettings()
|
||||||
|
{
|
||||||
|
if (!File.Exists("GameSettings.txt"))
|
||||||
|
{
|
||||||
|
SaveSettings();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsContainer = JsonConvert.DeserializeObject<SettingsContainer>(File.ReadAllText("GameSettings.txt"));
|
||||||
|
SetIsFullScreen(settingsContainer.IsFullScreen);
|
||||||
|
SetMainVolume(settingsContainer.MainVolume);
|
||||||
|
SetMusicVolume(settingsContainer.MusicVolume);
|
||||||
|
SetResolution(settingsContainer.Resolution);
|
||||||
|
SetSoundEffectsVolume(settingsContainer.SoundEffectsVolume);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public void SaveSettings()
|
||||||
|
{
|
||||||
|
using (StreamWriter streamWriter = new StreamWriter("GameSettings.txt"))
|
||||||
|
{
|
||||||
|
string _str = JsonConvert.SerializeObject(settingsContainer);
|
||||||
|
streamWriter.Write(_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
[Serializable]
|
||||||
|
public class SettingsContainer
|
||||||
|
{
|
||||||
|
[JsonProperty("IsFullScreen")]
|
||||||
|
public bool IsFullScreen { get; set; } = false;
|
||||||
|
[JsonProperty("MainVolume")]
|
||||||
|
public float MainVolume { get; set; } = 1;
|
||||||
|
[JsonProperty("MusicVolume")]
|
||||||
|
public float MusicVolume { get; set; } = 1;
|
||||||
|
[JsonProperty("SoundEffectsVolume")]
|
||||||
|
public float SoundEffectsVolume { get; set; } = 1;
|
||||||
|
[JsonProperty("Resolution")]
|
||||||
|
public Point Resolution { get; set; } = new Point(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
|
||||||
|
}
|
||||||
|
}
|
|
@ -114,7 +114,7 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
SoundEffect = soundEffect;
|
SoundEffect = soundEffect;
|
||||||
Position = position;
|
Position = position;
|
||||||
}
|
}
|
||||||
/*/ public void UpdateVolume(Vector2 playerPos)
|
/*/public void UpdateVolume(Vector2 playerPos)
|
||||||
{
|
{
|
||||||
if (isAmbient)
|
if (isAmbient)
|
||||||
SoundEffect.Volume = baseVolume * AppManager.Instance.SettingsManager.MusicVolume * AppManager.Instance.SettingsManager.MainVolume;
|
SoundEffect.Volume = baseVolume * AppManager.Instance.SettingsManager.MusicVolume * AppManager.Instance.SettingsManager.MainVolume;
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
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
|
||||||
{
|
{
|
||||||
|
private int health;
|
||||||
|
Server server = new Server();
|
||||||
|
|
||||||
|
public void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
// server.AddData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TextureLoad(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using ZoFo.GameCore.GameManagers;
|
||||||
using ZoFo.GameCore.ZoFo_graphics;
|
using ZoFo.GameCore.ZoFo_graphics;
|
||||||
|
|
||||||
namespace ZoFo.GameCore.GameObjects;
|
namespace ZoFo.GameCore.GameObjects;
|
||||||
|
@ -7,9 +10,65 @@ namespace ZoFo.GameCore.GameObjects;
|
||||||
public abstract class GameObject
|
public abstract class GameObject
|
||||||
{
|
{
|
||||||
public Vector2 position;
|
public Vector2 position;
|
||||||
public Vector2 rotation;
|
public Vector2 rotation; //вектор направления объекта
|
||||||
|
|
||||||
protected abstract GraphicsComponent graphicsComponent { get; }
|
protected abstract GraphicsComponent graphicsComponent { get; }
|
||||||
public void Draw() { }
|
|
||||||
|
|
||||||
|
#region ServerSide
|
||||||
|
public GameObject(Vector2 position)
|
||||||
|
{
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Это вызывается в логике игры, которая на сервере, здесь будет вызываться уведомление об анимации
|
||||||
|
/// </summary>
|
||||||
|
public void PlayAnimation_OnServer()
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Client Side
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Это вызывается в клиентской части игры
|
||||||
|
/// </summary>
|
||||||
|
public void PlayAnimation_OnClient()
|
||||||
|
{
|
||||||
|
graphicsComponent.Update();
|
||||||
|
}
|
||||||
|
public void LoadContent()
|
||||||
|
{
|
||||||
|
graphicsComponent.LoadContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
//PlayAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
graphicsComponent.DrawAnimation(graphicsComponent.ObjectDrawRectangle, spriteBatch);
|
||||||
|
//debug
|
||||||
|
if (AppManager.Instance.InputManager.CollisionsCheat)
|
||||||
|
DrawDebugRectangle(spriteBatch, graphicsComponent.ObjectDrawRectangle);
|
||||||
|
|
||||||
|
}
|
||||||
|
public void DrawDebugRectangle(SpriteBatch spriteBatch, Rectangle _rectangle, Nullable<Color> color = null)
|
||||||
|
{
|
||||||
|
if (color is null) color = new Color(1, 0, 0, 0.25f);
|
||||||
|
if (color.Value.A == 255) color = new Color(color.Value, 0.25f);
|
||||||
|
//spriteBatch.Draw(debugTexture,
|
||||||
|
// new Rectangle((_rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling,
|
||||||
|
// (_rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling,
|
||||||
|
// _rectangle.Width * GraphicsComponent.scaling,
|
||||||
|
// _rectangle.Height * GraphicsComponent.scaling), color.Value);
|
||||||
|
|
||||||
|
//TODO: debugTexture
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
26
ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ZoFo.GameCore.GameManagers;
|
||||||
|
using ZoFo.GameCore.ZoFo_graphics;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects.MapObjects
|
||||||
|
{
|
||||||
|
internal class MapObject : GameObject
|
||||||
|
{
|
||||||
|
public virtual bool IsColliderOn { get; protected set; } = true;
|
||||||
|
private Rectangle _sourceRectangle;
|
||||||
|
protected override GraphicsComponent graphicsComponent => new("tiles");
|
||||||
|
|
||||||
|
public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle) : base(position)
|
||||||
|
{
|
||||||
|
_sourceRectangle = sourceRectangle;
|
||||||
|
graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0, (int)size.X, (int)size.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
|
using ZoFo.GameCore.ZoFo_graphics;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
|
||||||
|
|
||||||
|
public abstract class StopObject : GameObject
|
||||||
|
{
|
||||||
|
protected StopObject(Vector2 position) : base(position)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
8
ZoFo/GameCore/GameObjects/MapObjects/Tiles/Tile.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameObjects.MapObjects.Tiles;
|
||||||
|
|
||||||
|
public class Tile
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -37,19 +37,27 @@ namespace ZoFo.GameCore
|
||||||
{
|
{
|
||||||
networkManager.AddData(data);
|
networkManager.AddData(data);
|
||||||
}
|
}
|
||||||
public void CreateRoom(int players) //Создает комнату и запускает ожидание подключений
|
/// <summary>
|
||||||
|
/// Создает комнату и запускает ожидание подключений
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="players"></param>
|
||||||
|
public void CreateRoom(int players)
|
||||||
{
|
{
|
||||||
networkManager.StartWaitingForPlayers(players);
|
networkManager.Start(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void StartGame() { } принудительный запуск
|
// public void StartGame() { } принудительный запуск
|
||||||
public void EndGame() //Добавляет UpdateGameEnded и отключает игроков
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавляет UpdateGameEnded и отключает игроков
|
||||||
|
/// </summary>
|
||||||
|
public void EndGame()
|
||||||
{
|
{
|
||||||
UpdateGameEnded gameEnded = new UpdateGameEnded();
|
UpdateGameEnded gameEnded = new UpdateGameEnded();
|
||||||
networkManager.AddData(gameEnded);
|
networkManager.AddData(gameEnded);
|
||||||
networkManager.CloseConnection();
|
networkManager.CloseConnection();
|
||||||
}
|
}
|
||||||
internal void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,10 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
|
|
||||||
public class GraphicsComponent
|
public class GraphicsComponent
|
||||||
{
|
{
|
||||||
|
public Rectangle ObjectDrawRectangle { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public event Action<string> actionOfAnimationEnd;
|
public event Action<string> actionOfAnimationEnd;
|
||||||
private List<AnimationContainer> animations;
|
private List<AnimationContainer> animations;
|
||||||
private List<Texture2D> textures;
|
private List<Texture2D> textures;
|
||||||
|
|