Merge pull request #105 from progtime-net/DevelopmentX

Development x
This commit is contained in:
AnloGames 2024-08-23 22:58:18 +03:00 committed by GitHub
commit aa3cf04cc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 3516 additions and 591 deletions

View file

@ -18,6 +18,7 @@ namespace MonogameLibrary.UI.Base
public string textureName = ""; public string textureName = "";
public Rectangle rectangle = new Rectangle(0, 0, 10, 10); public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
public Color mainColor = Color.White; public Color mainColor = Color.White;
public bool sus = true;
public DrawableUIElement(UIManager manager, int layerIndex = 0, string textureName = "") public DrawableUIElement(UIManager manager, int layerIndex = 0, string textureName = "")
{ {
@ -29,6 +30,7 @@ namespace MonogameLibrary.UI.Base
{ {
if (textureName == "") if (textureName == "")
{ {
sus = false;
texture = new Texture2D(Manager.GraphicsDevice, 1, 1); texture = new Texture2D(Manager.GraphicsDevice, 1, 1);
texture.SetData<Color>(new Color[] { mainColor }); texture.SetData<Color>(new Color[] { mainColor });
} }

View file

@ -18,7 +18,7 @@ public class Bar : DrawableUIElement
public float percent = 0.5f; public float percent = 0.5f;
private DrawableUIElement barInside; private DrawableUIElement barInside;
public Color inColor; public Color inColor;
public string inTextureName; public string inTextureName = "";
public Bar(UIManager manager, int layerIndex = 0, string textureName = "") : base(manager, layerIndex, textureName) public Bar(UIManager manager, int layerIndex = 0, string textureName = "") : base(manager, layerIndex, textureName)
{ {
@ -30,8 +30,7 @@ public class Bar : DrawableUIElement
{ {
rectangle = new Rectangle(rectangle.X + rectangle.Height / 8, rectangle.Y + rectangle.Height / 8, rectangle = new Rectangle(rectangle.X + rectangle.Height / 8, rectangle.Y + rectangle.Height / 8,
(int)((rectangle.Width - rectangle.Height / 4) * percent), rectangle.Height / 8 * 7), (int)((rectangle.Width - rectangle.Height / 4) * percent), rectangle.Height / 8 * 7),
mainColor = inColor, mainColor = inColor
textureName = inTextureName
}; };
} }

View file

@ -102,7 +102,8 @@ public class ItemDisplayButton : Button
fontColor2 = fontColor1, fontColor2 = fontColor1,
fontName2 = fontName1, fontName2 = fontName1,
scale2 = scale1, scale2 = scale1,
itemTextureName1 = itemTextureName itemTextureName1 = itemTextureName,
textureName = "Textures/GUI/Back"
}; };
hoverWindow.Initialize(content); hoverWindow.Initialize(content);
hoverWindow.LoadTexture(content); hoverWindow.LoadTexture(content);

View file

@ -111,7 +111,8 @@ public class ItemDisplayLabel : DrawableUIElement
fontColor2 = fontColor1, fontColor2 = fontColor1,
fontName2 = fontName1, fontName2 = fontName1,
scale2 = scale1, scale2 = scale1,
itemTextureName1 = itemTextureName itemTextureName1 = itemTextureName,
textureName = "Textures/GUI/Back"
}; };
hoverWindow.Initialize(content); hoverWindow.Initialize(content);
hoverWindow.LoadTexture(content); hoverWindow.LoadTexture(content);

View file

@ -44,6 +44,9 @@
#begin MapData/TileMaps/main.tmj #begin MapData/TileMaps/main.tmj
/copy:MapData/TileMaps/main.tmj /copy:MapData/TileMaps/main.tmj
#begin MapData/TileSets/bonfire.tsj
/copy:MapData/TileSets/bonfire.tsj
#begin MapData/TileSets/IconSet.tsj #begin MapData/TileSets/IconSet.tsj
/copy:MapData/TileSets/IconSet.tsj /copy:MapData/TileSets/IconSet.tsj
@ -56,6 +59,36 @@
#begin MapData/TileSets/TilesetNature.tsj #begin MapData/TileSets/TilesetNature.tsj
/copy:MapData/TileSets/TilesetNature.tsj /copy:MapData/TileSets/TilesetNature.tsj
#begin sounds/Background menu music.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Background menu music.wav
#begin sounds/Background music.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Background music.wav
#begin sounds/Button click.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Button click.wav
#begin sounds/Craft sound.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/Craft sound.wav
#begin sounds/gun-gunshot-01.wav
/importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/gun-gunshot-01.wav
#begin sounds/Loot.wav #begin sounds/Loot.wav
/importer:WavImporter /importer:WavImporter
/processor:SoundEffectProcessor /processor:SoundEffectProcessor
@ -98,14 +131,20 @@
/processorParam:Quality=Best /processorParam:Quality=Best
/build:sounds/Zombi stoit.wav /build:sounds/Zombi stoit.wav
#begin Textures/Animations/player_down_idle.animation #begin sounds/zombie sound 2.wav
/copy:Textures/Animations/player_down_idle.animation /importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/zombie sound 2.wav
#begin Textures/Animations/player_down-left_idle.animation #begin sounds/zombie sound.wav
/copy:Textures/Animations/player_down-left_idle.animation /importer:WavImporter
/processor:SoundEffectProcessor
/processorParam:Quality=Best
/build:sounds/zombie sound.wav
#begin Textures/Animations/player_down-right_idle.animation #begin Textures/Animations/explosion_1.animation
/copy:Textures/Animations/player_down-right_idle.animation /copy:Textures/Animations/explosion_1.animation
#begin Textures/Animations/player_idle_down_mining.animation #begin Textures/Animations/player_idle_down_mining.animation
/copy:Textures/Animations/player_idle_down_mining.animation /copy:Textures/Animations/player_idle_down_mining.animation
@ -131,9 +170,6 @@
#begin Textures/Animations/player_idle_top-rights_mining.animation #begin Textures/Animations/player_idle_top-rights_mining.animation
/copy:Textures/Animations/player_idle_top-rights_mining.animation /copy:Textures/Animations/player_idle_top-rights_mining.animation
#begin Textures/Animations/player_left_idle.animation
/copy:Textures/Animations/player_left_idle.animation
#begin Textures/Animations/player_look_down_weapon.animation #begin Textures/Animations/player_look_down_weapon.animation
/copy:Textures/Animations/player_look_down_weapon.animation /copy:Textures/Animations/player_look_down_weapon.animation
@ -182,9 +218,6 @@
#begin Textures/Animations/player_look_up.animation #begin Textures/Animations/player_look_up.animation
/copy:Textures/Animations/player_look_up.animation /copy:Textures/Animations/player_look_up.animation
#begin Textures/Animations/player_right_idle.animation
/copy:Textures/Animations/player_right_idle.animation
#begin Textures/Animations/player_run_down.animation #begin Textures/Animations/player_run_down.animation
/copy:Textures/Animations/player_run_down.animation /copy:Textures/Animations/player_run_down.animation
@ -218,15 +251,30 @@
#begin Textures/Animations/player_top_mining.animation #begin Textures/Animations/player_top_mining.animation
/copy:Textures/Animations/player_top_mining.animation /copy:Textures/Animations/player_top_mining.animation
#begin Textures/Animations/player_top-left_idle.animation
/copy:Textures/Animations/player_top-left_idle.animation
#begin Textures/Animations/player_top-right_idle.animation
/copy:Textures/Animations/player_top-right_idle.animation
#begin Textures/Animations/running_top.animation #begin Textures/Animations/running_top.animation
/copy:Textures/Animations/running_top.animation /copy:Textures/Animations/running_top.animation
#begin Textures/Animations/Simple Idles/player_down_idle.animation
/copy:Textures/Animations/Simple Idles/player_down_idle.animation
#begin Textures/Animations/Simple Idles/player_down-left_idle.animation
/copy:Textures/Animations/Simple Idles/player_down-left_idle.animation
#begin Textures/Animations/Simple Idles/player_down-right_idle.animation
/copy:Textures/Animations/Simple Idles/player_down-right_idle.animation
#begin Textures/Animations/Simple Idles/player_left_idle.animation
/copy:Textures/Animations/Simple Idles/player_left_idle.animation
#begin Textures/Animations/Simple Idles/player_right_idle.animation
/copy:Textures/Animations/Simple Idles/player_right_idle.animation
#begin Textures/Animations/Simple Idles/player_top-left_idle.animation
/copy:Textures/Animations/Simple Idles/player_top-left_idle.animation
#begin Textures/Animations/Simple Idles/player_top-right_idle.animation
/copy:Textures/Animations/Simple Idles/player_top-right_idle.animation
#begin Textures/Animations/testAnimation.animation #begin Textures/Animations/testAnimation.animation
/copy:Textures/Animations/testAnimation.animation /copy:Textures/Animations/testAnimation.animation
@ -368,6 +416,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/Effects/explosion.png /build:Textures/Effects/explosion.png
#begin Textures/GUI/back.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/back.png
#begin Textures/GUI/background/base.png #begin Textures/GUI/background/base.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -452,6 +512,42 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/background/waiting.png /build:Textures/GUI/background/waiting.png
#begin Textures/GUI/Button.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/Button.png
#begin Textures/GUI/Button2.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/Button2.png
#begin Textures/GUI/ButtonI.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/ButtonI.png
#begin Textures/GUI/checkboxs_off-on.png #begin Textures/GUI/checkboxs_off-on.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
@ -680,7 +776,7 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/Collectables/BottleOfWater.png /build:Textures/icons/Collectables/BottleOfWater.png
#begin Textures/icons/Collectables/Peeble.png #begin Textures/icons/Collectables/Pebble.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255
@ -690,7 +786,7 @@
/processorParam:ResizeToPowerOfTwo=False /processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False /processorParam:MakeSquare=False
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/Collectables/Peeble.png /build:Textures/icons/Collectables/Pebble.png
#begin Textures/icons/Collectables/PureBottleOfWater.png #begin Textures/icons/Collectables/PureBottleOfWater.png
/importer:TextureImporter /importer:TextureImporter
@ -740,6 +836,18 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/Collectables/Wood.png /build:Textures/icons/Collectables/Wood.png
#begin Textures/icons/ExitZone.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/icons/ExitZone.png
#begin Textures/icons/Material/Fabric.png #begin Textures/icons/Material/Fabric.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor

View file

@ -1,15 +1,24 @@
{ {
"activeFile": "TileMaps/main.tmj",
"expandedProjectPaths": [
"Templates",
"Templates/Zones",
"TileMaps",
".",
"Templates/Enemies"
],
"fileStates": { "fileStates": {
"TileMaps/main.tmj": { "TileMaps/main.tmj": {
"scale": 0.33, "scale": 2,
"selectedLayer": 0, "selectedLayer": 1,
"viewCenter": { "viewCenter": {
"x": -463.63636363636374, "x": -682.5,
"y": 300 "y": 1140.25
} }
}, },
"TileSets/IconSet.tsj": { "TileSets/IconSet.tsj": {
"dynamicWrapping": true "dynamicWrapping": true,
"scaleInDock": 1
}, },
"TileSets/TileSet 1.tsj": { "TileSets/TileSet 1.tsj": {
"dynamicWrapping": false, "dynamicWrapping": false,
@ -18,9 +27,21 @@
"TileSets/TilesetNature.tsj": { "TileSets/TilesetNature.tsj": {
"scaleInDock": 1.5 "scaleInDock": 1.5
}, },
"TileSets/bonfire.tsj": {
"dynamicWrapping": false,
"scaleInDock": 1
},
"TileSets/tileset 1 collision.tsj": { "TileSets/tileset 1 collision.tsj": {
"dynamicWrapping": false, "dynamicWrapping": false,
"scaleInDock": 1 "scaleInDock": 1
} }
} },
"last.objectTemplatePath": "C:/Users/artem/source/repos/ZoFo/ZoFo/Content/MapData/Templates/Zones",
"openFiles": [
"TileMaps/main.tmj"
],
"project": "MapSession.tiled-project",
"recentFiles": [
"TileMaps/main.tmj"
]
} }

View file

@ -0,0 +1,12 @@
{ "object":
{
"height":124,
"id":218,
"name":"Exit",
"rotation":0,
"type":"",
"visible":true,
"width":74
},
"type":"template"
}

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -46,21 +46,31 @@ namespace ZoFo.GameCore
// Подписка на действия инпутменеджера. // Подписка на действия инпутменеджера.
// Отправляются данные апдейтса с обновлением инпута // Отправляются данные апдейтса с обновлением инпута
AppManager.Instance.InputManager.ActionEvent += () => AppManager.Instance.InputManager.ActionEvent += () =>
{
if (AppManager.Instance.client.networkManager.PlayerId > 0)
{ {
networkManager.AddData(new UpdateInput() networkManager.AddData(new UpdateInput()
{ {
InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection.Serialize(), InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection.Serialize(),
InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection.Serialize() InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection.Serialize(),
PlayerId = AppManager.Instance.client.networkManager.PlayerId
}); });
}
}; };
AppManager.Instance.InputManager.OnInteract += () => AppManager.Instance.InputManager.OnInteract += () =>
{ {
networkManager.AddData(new UpdateInputInteraction() { }); if (AppManager.Instance.client.networkManager.PlayerId > 0)
{
networkManager.AddData(new UpdateInputInteraction() { PlayerId = AppManager.Instance.client.networkManager.PlayerId });
}
}; };
AppManager.Instance.InputManager.ShootEvent += () => AppManager.Instance.InputManager.ShootEvent += () =>
{ {
networkManager.AddData(new UpdateInputShoot() { }); if (AppManager.Instance.client.networkManager.PlayerId > 0)
{
networkManager.AddData(new UpdateInputShoot() { PlayerId = AppManager.Instance.client.networkManager.PlayerId });
}
}; };
} }
@ -103,7 +113,7 @@ namespace ZoFo.GameCore
float shakeEffect = 0; float shakeEffect = 0;
public void AddShaking(float power) public void AddShaking(float power)
{ {
shakeEffect += power; shakeEffect += power*3;
} }
public void UpdateShaking() public void UpdateShaking()
{ {
@ -133,10 +143,10 @@ namespace ZoFo.GameCore
networkManager.SendData();//set to ticks networkManager.SendData();//set to ticks
if (myPlayer != null) if (myPlayer != null)
GraphicsComponent.CameraPosition = GraphicsComponent.CameraPosition =
((GraphicsComponent.CameraPosition.ToVector2() *0.9f + ((GraphicsComponent.CameraPosition.ToVector2() * 0.9f +
(myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2 - AppManager.Instance.CurentScreenResolution.ToVector2() / (2 * GraphicsComponent.scaling) (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2 - AppManager.Instance.CurentScreenResolution.ToVector2() / (2 * GraphicsComponent.scaling)
) * 0.1f ) * 0.1f
) ) ))
.ToPoint(); .ToPoint();
} }
public void SendData() public void SendData()
@ -195,14 +205,14 @@ namespace ZoFo.GameCore
(update as UpdateStopObjectCreated).collisions.Select(x => x.GetRectangle()).ToArray() (update as UpdateStopObjectCreated).collisions.Select(x => x.GetRectangle()).ToArray()
)); ));
} }
else if (update is UpdateGameObjectCreated) else if (update is UpdateGameObjectCreated)
{ {
//TODO
Entity created_gameObject; Entity created_gameObject;
if ((update as UpdateGameObjectCreated).GameObjectType == "Player") if ((update as UpdateGameObjectCreated).GameObjectType == "Player")
{ {
created_gameObject = new Player((update as UpdateGameObjectCreated).position.GetVector2()); created_gameObject = new Player((update as UpdateGameObjectCreated).position.GetVector2());
players.Add(created_gameObject as Player);
myPlayer = players[0];
gameObjects.Add(created_gameObject); gameObjects.Add(created_gameObject);
} }
else else
@ -245,11 +255,15 @@ namespace ZoFo.GameCore
DeleteObject(ent); DeleteObject(ent);
} }
else if (update is UpdatePlayerParametrs) else if (update is UpdateGameEnded)
{
GameEnd();
}
else if (update is UpdatePlayerParametrs && myPlayer !=null && update.IdEntity == myPlayer.Id) //aaa
{ {
UpdatePlayerHealth(update as UpdatePlayerParametrs); UpdatePlayerHealth(update as UpdatePlayerParametrs);
} }
else if (update is UpdateLoot) else if (update is UpdateLoot && myPlayer != null && update.IdEntity == myPlayer.Id)//aaa
{ {
if ((update as UpdateLoot).quantity == 0) if ((update as UpdateLoot).quantity == 0)
{ {
@ -259,6 +273,15 @@ namespace ZoFo.GameCore
if (ent != null) if (ent != null)
(ent as Player).lootData.AddLoot_Client((update as UpdateLoot).lootName, (update as UpdateLoot).quantity); (ent as Player).lootData.AddLoot_Client((update as UpdateLoot).lootName, (update as UpdateLoot).quantity);
} }
else if (update is UpdateCreatePlayer)
{
UpdateCreatePlayer ucp = (UpdateCreatePlayer)update;
if (networkManager.PlayerId == ucp.PlayerId)
{
myPlayer = (Player)FindEntityById(ucp.IdEntity);
players.Add(myPlayer);
}
}
} }
public void UpdatePlayerHealth(UpdatePlayerParametrs update) public void UpdatePlayerHealth(UpdatePlayerParametrs update)
@ -298,9 +321,13 @@ namespace ZoFo.GameCore
(ent as Player).health = (update as UpdatePlayerParametrs).health; (ent as Player).health = (update as UpdatePlayerParametrs).health;
(ent as Player).rad = (update as UpdatePlayerParametrs).radiatoin; (ent as Player).rad = (update as UpdatePlayerParametrs).radiatoin;
} }
} }
public bool changeGUI = false;
public void GameEnd()
{
changeGUI = true;
}
public Entity FindEntityById(int id) public Entity FindEntityById(int id)
{ {

View file

@ -54,14 +54,14 @@ public class BaseGUI : AbstractGUI
rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2, rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2,
height / 2 - (int)(height / 1.5) / 2, height / 2 - (int)(height / 1.5) / 2,
height / 40 + width / 5, (int)(height / 1.5)), height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray textureName = "Textures/GUI/Back"
}; };
Elements.Add(baseItemBack); Elements.Add(baseItemBack);
DrawableUIElement baseCraftBack = new DrawableUIElement(Manager) DrawableUIElement baseCraftBack = new DrawableUIElement(Manager)
{ {
rectangle = new Rectangle(width / 2 + height / 160, height / 2 - (int)(height / 1.5) / 2, rectangle = new Rectangle(width / 2 + height / 160, height / 2 - (int)(height / 1.5) / 2,
height / 40 + width / 5, (int)(height / 1.5)), height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray textureName = "Textures/GUI/Back"
}; };
Elements.Add(baseCraftBack); Elements.Add(baseCraftBack);
@ -85,7 +85,8 @@ public class BaseGUI : AbstractGUI
mainColor = Color.Gray, mainColor = Color.Gray,
fontName1 = "Fonts\\Font4", fontName1 = "Fonts\\Font4",
discriptions1 = itemInfo.description, discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft,
textureName = "Textures/GUI/Button"
}; };
Elements.Add(temp); Elements.Add(temp);
temp.Initialize(); temp.Initialize();
@ -134,7 +135,8 @@ public class BaseGUI : AbstractGUI
mainColor = Color.Gray, mainColor = Color.Gray,
fontName1 = "Fonts\\Font4", fontName1 = "Fonts\\Font4",
discriptions1 = itemInfo.description, discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft,
textureName = "Textures/GUI/Button"
}; };
Elements.Add(temp); Elements.Add(temp);
temp.Initialize(); temp.Initialize();
@ -142,6 +144,7 @@ public class BaseGUI : AbstractGUI
ItemDisplayButtonsList.Add(temp); ItemDisplayButtonsList.Add(temp);
temp.LeftButtonPressed += () => temp.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Craft sound");
AppManager.Instance.playerData.CraftItem(item.Key); AppManager.Instance.playerData.CraftItem(item.Key);
AppManager.Instance.SetGUI(new BaseGUI()); AppManager.Instance.SetGUI(new BaseGUI());
}; };
@ -160,10 +163,12 @@ public class BaseGUI : AbstractGUI
{ {
fontName = "Fonts\\Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, fontName = "Fonts\\Font3", scale = 0.4f, text = "<-", fontColor = Color.Black,
mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40),
textureName = "Textures\\GUI\\checkboxs_off" textureName = "Textures/GUI/Button2"
}; };
Elements.Add(bTExit); Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new MainMenuGUI()); }; bTExit.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new MainMenuGUI());
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
};
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)

View file

@ -31,6 +31,7 @@ public class DebugHUD
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
//return;//TODO delete
var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()); var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
spriteBatch.Begin(); spriteBatch.Begin();
spriteBatch.DrawString( spriteBatch.DrawString(

View file

@ -36,7 +36,8 @@ public class ExitGameGUI : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
endButton.LeftButtonPressed += () => endButton.LeftButtonPressed += () =>
{ {

View file

@ -38,7 +38,8 @@ public class FinishingGUI : AbstractGUI
rectangle = new Rectangle(width / 2 - height / 80 - width / 5 / 2, rectangle = new Rectangle(width / 2 - height / 80 - width / 5 / 2,
height / 2 - (int)(height / 1.5) / 2, height / 2 - (int)(height / 1.5) / 2,
height / 40 + width / 5, (int)(height / 1.5)), height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray mainColor = Color.LightGray,
textureName = "Textures/GUI/Back"
}; };
Elements.Add(inventoryBack); Elements.Add(inventoryBack);
@ -50,9 +51,20 @@ public class FinishingGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts\\Font" fontName = "Fonts\\Font",
textureName = "Textures/GUI/Button"
};
ExitButton.LeftButtonPressed += () => {
foreach (var item in AppManager.Instance.client.myPlayer.lootData.loots)
{
AppManager.Instance.playerData.AddLoot(item.Key, item.Value);
}
AppManager.Instance.SetGUI(new MainMenuGUI());
}; };
ExitButton.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new MainMenuGUI()); };
Elements.Add(ExitButton); Elements.Add(ExitButton);
//player itams //player itams

View file

@ -36,7 +36,8 @@ public class GameEndedGUI : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
endButton.LeftButtonPressed += () => endButton.LeftButtonPressed += () =>
{ {

View file

@ -24,17 +24,27 @@ public class HUD : AbstractGUI
int height = AppManager.Instance.CurentScreenResolution.Y; int height = AppManager.Instance.CurentScreenResolution.Y;
Button pauseButton = new Button(Manager) Button pauseButton = new Button(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"}; {
fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black,
mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 30, width / 40, width / 40),
textureName = "Textures/GUI/Button2"
};
Elements.Add(pauseButton); Elements.Add(pauseButton);
pauseButton.LeftButtonPressed += () => pauseButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new PauseGUI());
//AppManager.Instance.SetGUI(new FinishingGUI()); //AppManager.Instance.SetGUI(new FinishingGUI());
overlayGUI = new PauseGUI(); overlayGUI = new PauseGUI();
overlayGUI.Initialize(); overlayGUI.Initialize();
overlayGUI.LoadContent(); overlayGUI.LoadContent();
}; };
Button invButton = new Button(Manager) Button invButton = new Button(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "inv", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 15 + width / 40, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"}; {
fontName = "Fonts\\Font3", scale = 0.4f, fontColor = Color.Black,
mainColor = Color.Transparent, rectangle = new Rectangle(width - width / 30 - width / 40, height / 15 + width / 40, width / 40, width / 40),
textureName = "Textures/GUI/ButtonI"
};
Elements.Add(invButton); Elements.Add(invButton);
invButton.LeftButtonPressed += () => invButton.LeftButtonPressed += () =>
{ {

View file

@ -31,7 +31,8 @@ public class InventoryGUI : AbstractGUI
rectangle = new Rectangle(width / 2 - height / 80 - width / 5 / 2, rectangle = new Rectangle(width / 2 - height / 80 - width / 5 / 2,
height / 2 - (int)(height / 1.5) / 2 - height / 10, height / 2 - (int)(height / 1.5) / 2 - height / 10,
height / 40 + width / 5, (int)(height / 1.5)), height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray mainColor = Color.LightGray,
textureName = "Textures/GUI/Back"
}; };
Elements.Add(inventoryBack); Elements.Add(inventoryBack);
@ -43,7 +44,8 @@ public class InventoryGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts\\Font" fontName = "Fonts\\Font",
textureName = "Textures/GUI/Button"
}; };
continueButton.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new HUD()); }; continueButton.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new HUD()); };
Elements.Add(continueButton); Elements.Add(continueButton);
@ -69,7 +71,8 @@ public class InventoryGUI : AbstractGUI
mainColor = Color.Gray, mainColor = Color.Gray,
fontName1 = "Fonts\\Font4", fontName1 = "Fonts\\Font4",
discriptions1 = itemInfo.description, discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft,
textureName = "Texturs/GUI/Button"
}; };
Elements.Add(temp); Elements.Add(temp);
temp.Initialize(); temp.Initialize();

View file

@ -36,11 +36,12 @@ public class MainMenuGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
playButton.LeftButtonPressed += () => playButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Loot"); AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new SelectModeMenu()); AppManager.Instance.SetGUI(new SelectModeMenu());
}; };
Elements.Add(playButton); Elements.Add(playButton);
@ -51,10 +52,12 @@ public class MainMenuGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts\\Font" fontName = "Fonts\\Font",
textureName = "Textures/GUI/Button"
}; };
baseButton.LeftButtonPressed += () => baseButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new BaseGUI()); AppManager.Instance.SetGUI(new BaseGUI());
}; };
Elements.Add(baseButton); Elements.Add(baseButton);
@ -65,11 +68,12 @@ public class MainMenuGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
optionButton.LeftButtonPressed += () => optionButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Loot"); AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new OptionsGUI()); AppManager.Instance.SetGUI(new OptionsGUI());
}; };
Elements.Add(optionButton); Elements.Add(optionButton);
@ -80,7 +84,8 @@ public class MainMenuGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
exitButton.LeftButtonPressed += () => exitButton.LeftButtonPressed += () =>
{ {

View file

@ -43,6 +43,7 @@ public class OptionsGUI : AbstractGUI
label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%"; label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%";
slider_OverallVolume.SliderChanged += (newVal) => slider_OverallVolume.SliderChanged += (newVal) =>
{ {
label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%"; label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%";
AppManager.Instance.SettingsManager.SetMainVolume(newVal); AppManager.Instance.SettingsManager.SetMainVolume(newVal);
}; };
@ -64,6 +65,7 @@ public class OptionsGUI : AbstractGUI
label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%"; label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%";
slider_MusicVolume.SliderChanged += (newVal) => slider_MusicVolume.SliderChanged += (newVal) =>
{ {
label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%"; label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%";
AppManager.Instance.SettingsManager.SetMusicVolume(newVal); AppManager.Instance.SettingsManager.SetMusicVolume(newVal);
}; };
@ -85,6 +87,7 @@ public class OptionsGUI : AbstractGUI
label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%"; label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%";
slider_EffectsVolume.SliderChanged += (newVal) => slider_EffectsVolume.SliderChanged += (newVal) =>
{ {
label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%"; label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%";
AppManager.Instance.SettingsManager.SetSoundEffectsVolume(newVal); AppManager.Instance.SettingsManager.SetSoundEffectsVolume(newVal);
}; };
@ -109,6 +112,7 @@ public class OptionsGUI : AbstractGUI
button_FullScreen.SetIsChecked(AppManager.Instance.SettingsManager.IsFullScreen); button_FullScreen.SetIsChecked(AppManager.Instance.SettingsManager.IsFullScreen);
button_FullScreen.Checked += (newCheckState) => button_FullScreen.Checked += (newCheckState) =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SettingsManager.SetIsFullScreen(newCheckState); AppManager.Instance.SettingsManager.SetIsFullScreen(newCheckState);
}; };
Elements.Add(button_FullScreen); Elements.Add(button_FullScreen);
@ -116,10 +120,15 @@ public class OptionsGUI : AbstractGUI
//-------------------------------------- //--------------------------------------
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"}; {
fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent,
rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40),
textureName = "Textures/GUI/Button2"
};
Elements.Add(bTExit); Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => bTExit.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new MainMenuGUI()); AppManager.Instance.SetGUI(new MainMenuGUI());
}; };

View file

@ -27,10 +27,12 @@ public class PauseGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts\\Font" fontName = "Fonts\\Font",
textureName = "Textures/GUI/Button"
}; };
continueButton.LeftButtonPressed += () => continueButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new HUD()); AppManager.Instance.SetGUI(new HUD());
}; };
Elements.Add(continueButton); Elements.Add(continueButton);
@ -41,10 +43,14 @@ public class PauseGUI : AbstractGUI
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts\\Font" fontName = "Fonts\\Font",
textureName = "Textures/GUI/Button"
}; };
exitButton.LeftButtonPressed += () => exitButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StopAllSounds();
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SoundManager.StartAmbientSound("Background menu music");
AppManager.Instance.SetGUI(new MainMenuGUI()); AppManager.Instance.SetGUI(new MainMenuGUI());
}; };
Elements.Add(exitButton); Elements.Add(exitButton);

View file

@ -34,10 +34,14 @@ public class SelectModeMenu : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
singleButton.LeftButtonPressed += () => singleButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StopAllSounds();
AppManager.Instance.SoundManager.StartAmbientSound("Background music");
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
// single // single
Server server = new Server(); Server server = new Server();
Client client = new Client(); Client client = new Client();
@ -64,10 +68,12 @@ public class SelectModeMenu : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
optionButton.LeftButtonPressed += () => optionButton.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new SelectingServerGUI()); AppManager.Instance.SetGUI(new SelectingServerGUI());
// multi // multi
@ -76,10 +82,17 @@ public class SelectModeMenu : AbstractGUI
Elements.Add(optionButton); Elements.Add(optionButton);
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"}; {
fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent,
rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40),
textureName = "Textures/GUI/Button2"
};
Elements.Add(bTExit); Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => bTExit.LeftButtonPressed += () =>
{ {
AppManager.Instance.SoundManager.StartAmbientSound("Button click");
AppManager.Instance.SetGUI(new MainMenuGUI()); AppManager.Instance.SetGUI(new MainMenuGUI());
}; };
} }

View file

@ -36,7 +36,8 @@ public class SelectingServerGUI : AbstractGUI
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
textAligment = MonogameLibrary.UI.Enums.TextAligment.Left, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left,
fontName = "Fonts/Font3" fontName = "Fonts/Font3",
textureName = "Textures/GUI/Button"
}; };
ipBox.TextChanged += input => ipBox.TextChanged += input =>
{ {
@ -61,7 +62,8 @@ public class SelectingServerGUI : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
joinButton.LeftButtonPressed += () => joinButton.LeftButtonPressed += () =>
{ {
@ -80,11 +82,7 @@ public class SelectingServerGUI : AbstractGUI
AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false));
} }
} }
catch (Exception) catch (Exception) { }
{
// throw;
}
// ваш код здесь // ваш код здесь
}; };
@ -96,7 +94,8 @@ public class SelectingServerGUI : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
hostButton.LeftButtonPressed += () => hostButton.LeftButtonPressed += () =>
{ {
@ -116,7 +115,11 @@ public class SelectingServerGUI : AbstractGUI
Elements.Add(hostButton); Elements.Add(hostButton);
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off" }; {
fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent,
rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40),
textureName = "Textures/GUI/Button2"
};
Elements.Add(bTExit); Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => bTExit.LeftButtonPressed += () =>
{ {

View file

@ -28,7 +28,7 @@ public class WaitingForPlayersGUI : 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/background/Waiting" }; menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures/GUI/background/waiting" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
// string pcIp = // string pcIp =
@ -47,7 +47,8 @@ public class WaitingForPlayersGUI : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
startButton.LeftButtonPressed += () => startButton.LeftButtonPressed += () =>
{ {
@ -67,18 +68,24 @@ public class WaitingForPlayersGUI : AbstractGUI
scale = 0.3f, scale = 0.3f,
fontColor = Color.White, fontColor = Color.White,
mainColor = Color.Gray, mainColor = Color.Gray,
fontName = "Fonts/Font" fontName = "Fonts/Font",
textureName = "Textures/GUI/Button"
}; };
waitButton.LeftButtonPressed += () => waitButton.LeftButtonPressed += () =>
{ {
// start // start
AppManager.Instance.SetGUI(new HUD());
// ваш код здесь // ваш код здесь
}; };
Elements.Add(waitButton); Elements.Add(waitButton);
} }
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"}; {
fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent,
rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40),
textureName = "Textures/GUI/Button2"
};
Elements.Add(bTExit); Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => bTExit.LeftButtonPressed += () =>
{ {

View file

@ -62,12 +62,14 @@ namespace ZoFo.GameCore.GameManagers
ItemManager = new ItemManager.ItemManager(); ItemManager = new ItemManager.ItemManager();
Instance = this; Instance = this;
InputManager = new InputManager(); InputManager = new InputManager();
SoundManager = new SoundManager();
SoundManager.LoadSounds();
SettingsManager = new SettingsManager(); SettingsManager = new SettingsManager();
SettingsManager.LoadSettings(); SettingsManager.LoadSettings();
SoundManager = new SoundManager();
AssetManager = new AssetManager();
SoundManager.LoadSounds();
AssetManager = new AssetManager();
SoundManager.StartAmbientSound("Background menu music");
currentGUI = new MainMenuGUI(); currentGUI = new MainMenuGUI();
debugHud = new DebugHUD(); debugHud = new DebugHUD();
@ -125,13 +127,20 @@ namespace ZoFo.GameCore.GameManagers
default: default:
break; break;
} }
if (client != null)
{
if (client.changeGUI)
{
SetGUI(new FinishingGUI());
client.changeGUI = false;
}
}
base.Update(gameTime); base.Update(gameTime);
} }
protected override void Draw(GameTime gameTime) protected override void Draw(GameTime gameTime)
{ {
GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.Black);
// Pointwrap // Pointwrap
@ -139,6 +148,8 @@ namespace ZoFo.GameCore.GameManagers
switch (gamestate) switch (gamestate)
{ {
case GameState.ClientPlaying: case GameState.ClientPlaying:
client.Draw(_spriteBatch);
break;
case GameState.HostPlaying: case GameState.HostPlaying:
client.Draw(_spriteBatch); client.Draw(_spriteBatch);
break; break;

View file

@ -168,7 +168,7 @@ namespace ZoFo.GameCore.GameManagers
#endregion #endregion
#region Обработка взаимодействия с collectable(например лутом). Вызывает событие OnInteract #region Обработка взаимодействия с collectable(например лутом). Вызывает событие OnInteract
if (keyBoardState.IsKeyDown(Keys.E) && !isInteract) if ((keyBoardState.IsKeyDown(Keys.E) || mouseState.LeftButton == ButtonState.Pressed) && !isInteract)
{ {
OnInteract?.Invoke(); OnInteract?.Invoke();
Debug.WriteLine("взаимодействие с Collectable"); Debug.WriteLine("взаимодействие с Collectable");
@ -256,6 +256,34 @@ namespace ZoFo.GameCore.GameManagers
DebugHUD.DebugSet("x", vector.X.ToString()); DebugHUD.DebugSet("x", vector.X.ToString());
} }
return currentScopeState; return currentScopeState;
}
public static Vector2 ConvertStateToVector2(ScopeState scopeState)
{
switch (scopeState)
{
case ScopeState.Idle:
return new Vector2(0, 0);
case ScopeState.Left:
return new Vector2(-1, 0);
case ScopeState.Right:
return new Vector2(1, 0);
case ScopeState.Top:
return new Vector2(0, -1);
case ScopeState.Down:
return new Vector2(0, 1);
case ScopeState.TopLeft:
return new Vector2(-1, -1);
case ScopeState.TopRight:
return new Vector2(-1, 1);
case ScopeState.DownLeft:
return new Vector2(1, -1);
case ScopeState.DownRight:
return new Vector2(1, 1);
default:
return new Vector2(0, 0);
}
} }
#endregion #endregion
public bool ButtonClicked(Keys key) => keyBoardState.IsKeyUp(key) && keyBoardState.IsKeyDown(key); public bool ButtonClicked(Keys key) => keyBoardState.IsKeyUp(key) && keyBoardState.IsKeyDown(key);

View file

@ -13,6 +13,8 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
//методы //методы
public ItemInfo GetItemInfo(string tag) public ItemInfo GetItemInfo(string tag)
{ {
if (tag == "peeble")
return tagItemPairs["pebble"];
return tagItemPairs[tag]; return tagItemPairs[tag];
} }
public void LoadItemTextures() public void LoadItemTextures()
@ -25,19 +27,47 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
public void Initialize() public void Initialize()
{ {
tagItemPairs = new Dictionary<string, ItemInfo>(); tagItemPairs = new Dictionary<string, ItemInfo>();
tagItemPairs.Add("rottenflesh", new ItemInfo("rottenflesh", "БУХАТЬ", "Textures/icons/Collectables/RottenFlesh",false,null)); tagItemPairs.Add("rottenflesh", new ItemInfo("rottenflesh", "гниль", "Textures/icons/Collectables/RottenFlesh",false,null));
tagItemPairs.Add("purebottleofwater", new ItemInfo("purebottleofwater", "БУХАТЬ 2", "Textures/icons/Collectables/PureBottleOfWater",false,null)); tagItemPairs.Add("bottleofwater", new ItemInfo("bottleofwater", "грязная водка", "Textures/icons/Collectables/BottleOfWater",false,null));
tagItemPairs.Add("bottleofwater", new ItemInfo("bottleofwater", "БУХАТЬ", "Textures/icons/Collectables/BottleOfWater",false,null));
//tagItemPairs.Add("antiradin", new ItemInfo("antiradin", "радиацию опускает", "Textures/icons/Collectables/Ammo",false,null)); //tagItemPairs.Add("antiradin", new ItemInfo("antiradin", "радиацию опускает", "Textures/icons/Collectables/Ammo",false,null));
tagItemPairs.Add("ammo", new ItemInfo("ammo", "деньги в метро", "Textures/icons/Collectables/Ammo",false,null)); tagItemPairs.Add("ammo", new ItemInfo("ammo", "деньги в метро", "Textures/icons/Collectables/Ammo",false,null));
tagItemPairs.Add("wood", new ItemInfo("wood", "бревна кусок", "Textures/icons/Collectables/Wood",false,null)); tagItemPairs.Add("wood", new ItemInfo("wood", "бревна кусок", "Textures/icons/Collectables/Wood",false,null));
tagItemPairs.Add("peeble", new ItemInfo("peeble", "пять галек", "Textures/icons/Collectables/Peeble", false, null)); tagItemPairs.Add("fabric", new ItemInfo("fabric", "смотя какой fabric", "Textures/icons/Material/Fabric",false,null));
tagItemPairs.Add("paper", new ItemInfo("paper", "бумага", "Textures/icons/Material/Paper",false,null));
tagItemPairs.Add("pebble", new ItemInfo("pebble", "пять галек", "Textures/icons/Collectables/Pebble", false, null));
tagItemPairs.Add("steel", new ItemInfo("steel", "метал, метал, \nжелезо, метал", "Textures/icons/Collectables/Steel", false, null)); tagItemPairs.Add("steel", new ItemInfo("steel", "метал, метал, \nжелезо, метал", "Textures/icons/Collectables/Steel", false, null));
tagItemPairs.Add("pickaxe", new ItemInfo("pickaxe", "прямой путь к \nстановлению каменьщиком", "Textures/Test/pickaxe", true, new Dictionary<string, int>() tagItemPairs.Add("pickaxe", new ItemInfo("pickaxe", "прямой путь к \nстановлению каменьщиком", "Textures/Test/pickaxe", true, new Dictionary<string, int>()
{ {
{"wood", 2}, {"wood", 2},
{"steel", 3} {"steel", 3}
})); }));
tagItemPairs.Add("plank", new ItemInfo("plank", "проосто доска", "Textures/icons/Material/Wooden Plank", true, new Dictionary<string, int>()
{
{"wood", 1}
}));
tagItemPairs.Add("gear", new ItemInfo("gear", "настройки", "Textures/icons/Misc/Gear", true, new Dictionary<string, int>()
{
{"steel", 3}
}));
tagItemPairs.Add("purebottleofwater", new ItemInfo("purebottleofwater", "чистая водка", "Textures/icons/Collectables/PureBottleOfWater", true, new Dictionary<string, int>()
{
{"bottleofwater", 1},
{"wood", 2}
}));
tagItemPairs.Add("leather", new ItemInfo("leather", "кожа", "Textures/icons/Material/Leather", true, new Dictionary<string, int>()
{
{"rottenflash", 1},
{"wood", 2}
}));
tagItemPairs.Add("crate", new ItemInfo("crate", "коробка", "Textures/icons/Misc/Crate", true, new Dictionary<string, int>()
{
{"plank", 5}
}));
tagItemPairs.Add("book", new ItemInfo("book", "книга", "Textures/icons/Misc/Book", true, new Dictionary<string, int>()
{
{"leather", 2},
{"paper", 5}
}));
} }
} }

View file

@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.ItemManager namespace ZoFo.GameCore.GameManagers.ItemManager
@ -15,7 +17,16 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
{ {
LoadPlayerData(); LoadPlayerData();
} }
public Dictionary<string, int> items; public Dictionary<string, int> items = new Dictionary<string, int>();
public void AddLoot(string loot, int quantity)
{
if (items.ContainsKey(loot))
items[loot] += quantity;
else
items.Add(loot, quantity);
AppManager.Instance.playerData.SavePlayerData();
}
/// <summary> /// <summary>
/// Принимает тэг и крафтит этот объект /// Принимает тэг и крафтит этот объект
/// </summary> /// </summary>
@ -50,11 +61,52 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
public void LoadPlayerData() public void LoadPlayerData()
{ {
//TODO /*items.Add("wood", 100);
items = new Dictionary<string, int>(); items.Add("steel", 100);
items.Add("wood", 5); items.Add("bottleofwater", 100);
items.Add("steel", 110); items.Add("rottenflesh", 100);
items.Add("peeble", 6); items.Add("pebble", 100);
items.Add("ammo", 100);
items.Add("fabric", 100);
items.Add("paper", 100);*/
if (File.Exists("Items.txt"))
{
string data;
using (StreamReader reader = new StreamReader("Items.txt"))
{
data = reader.ReadToEnd();
} }
List<PlayerItemsData> itemsDatas = JsonSerializer.Deserialize<List<PlayerItemsData>>(data);
foreach (var item in itemsDatas)
{
items.Add(item.Name, item.Count);
}
}
}
public void SavePlayerData()
{
var options = new JsonSerializerOptions { WriteIndented = true };
List<PlayerItemsData> playerItemsDatas = new List<PlayerItemsData>();
foreach (var item in items)
{
playerItemsDatas.Add(new PlayerItemsData { Name = item.Key, Count = item.Value });
}
string data = JsonSerializer.Serialize<List<PlayerItemsData>>(playerItemsDatas);
using (StreamWriter outputFile = new StreamWriter("Items.txt", new FileStreamOptions() { Mode = FileMode.Create, Access = FileAccess.Write } ))
{
outputFile.WriteLine(data);
}
}
}
class PlayerItemsData
{
public string Name { get; set; }
public int Count { get; set; }
} }
} }

View file

@ -21,7 +21,8 @@ namespace ZoFo.GameCore.GameManagers.MapManager
private static readonly JsonSerializerOptions _options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; // Задача настроек для JsonSerialize private static readonly JsonSerializerOptions _options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; // Задача настроек для JsonSerialize
private static readonly Dictionary<string, string> _classPath = new Dictionary<string, string>() { private static readonly Dictionary<string, string> _classPath = new Dictionary<string, string>() {
{ "Collectables", "ZoFo.GameCore.GameObjects." }, { "Collectables", "ZoFo.GameCore.GameObjects." },
{ "Enemies", "ZoFo.GameCore.GameObjects." } { "Enemies", "ZoFo.GameCore.GameObjects." },
{ "Zones", "ZoFo.GameCore.GameObjects." }
}; };
//private static readonly float _scale = 1.0f; //private static readonly float _scale = 1.0f;

View file

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Data.SqlTypes; using System.Data.SqlTypes;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
@ -20,7 +21,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
{ {
public class ClientNetworkManager public class ClientNetworkManager
{ {
private int PlayerId; public int PlayerId = 0;
private IPEndPoint endPoint; private IPEndPoint endPoint;
private IPEndPoint sendingEP; private IPEndPoint sendingEP;
private Socket socket; private Socket socket;
@ -83,7 +84,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
if (AppManager.Instance.gamestate != GameState.HostPlaying) if (AppManager.Instance.gamestate != GameState.HostPlaying)
{ {
AppManager.Instance.ChangeState(GameState.ClientPlaying); AppManager.Instance.ChangeState(GameState.ClientPlaying);
AppManager.Instance.SetGUI(new HUD());
} }
SendAcknowledgement(Dgramm.DatagrammId); SendAcknowledgement(Dgramm.DatagrammId);
} }
@ -139,6 +139,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
update = token.ToObject<UpdateGameObjectCreated>(); update = token.ToObject<UpdateGameObjectCreated>();
data.Add(update); data.Add(update);
break; break;
case "UpdateGameObjectWithoutIdCreated":
update = token.ToObject<UpdateGameObjectWithoutIdCreated>();
data.Add(update);
break;
case "UpdateGameObjectDeleted": case "UpdateGameObjectDeleted":
update = token.ToObject<UpdateGameObjectDeleted>(); update = token.ToObject<UpdateGameObjectDeleted>();
data.Add(update); data.Add(update);
@ -171,6 +175,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
update = token.ToObject<UpdateTileCreated>(); update = token.ToObject<UpdateTileCreated>();
data.Add(update); data.Add(update);
break; break;
case "UpdateCreatePlayer":
update = token.ToObject<UpdateCreatePlayer>();
data.Add(update);
break;
} }
} }
@ -215,7 +223,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
public void JoinRoom(string ip, int port) // multyplayer public void JoinRoom(string ip, int port) // multyplayer
{ {
sendingEP = new IPEndPoint(IPAddress.Parse(ip), port); sendingEP = new IPEndPoint(IPAddress.Parse(ip), port);
AppManager.Instance.ChangeState(GameState.ClientPlaying);
SendData(); SendData();
Thread listen = new Thread(StartListening); Thread listen = new Thread(StartListening);
listen.IsBackground = true; listen.IsBackground = true;
@ -236,19 +243,18 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
#endregion #endregion
public static IPAddress GetIp() public static IPAddress GetIp()
{ {
string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ips = NetworkInterface.GetAllNetworkInterfaces()
var ipList = Dns.GetHostEntry(hostName).AddressList; .Where(x => x.OperationalStatus == OperationalStatus.Up)
var ipV4List = new List<IPAddress>(); .Where(x => x.NetworkInterfaceType is NetworkInterfaceType.Wireless80211
foreach (var ip in ipList) or NetworkInterfaceType.Ethernet)
.SelectMany(x => x.GetIPProperties().UnicastAddresses)
.Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(x => x.Address)
.ToList();
if (ips.Count > 0)
{ {
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) return ips[^1];
{
ipV4List.Add(ip);
}
}
if (ipV4List.Count>0)
{
return ipV4List[ipV4List.Count - 1];
} }
return IPAddress.Loopback; return IPAddress.Loopback;
} }

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -28,7 +29,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
private IPAddress ip; private IPAddress ip;
private bool isMultiplayer; private bool isMultiplayer;
//Player Id to Player endPoint //Player Id to Player endPoint
private List<IPEndPoint> clientsEP; public List<IPEndPoint> clientsEP;
public IPEndPoint endPoint; public IPEndPoint endPoint;
private List<UpdateData> commonUpdates; private List<UpdateData> commonUpdates;
private List<UpdateData> importantUpdates; private List<UpdateData> importantUpdates;
@ -66,20 +67,18 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
/// <returns></returns> /// <returns></returns>
public static IPAddress GetIp() public static IPAddress GetIp()
{ {
string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ips = NetworkInterface.GetAllNetworkInterfaces()
var ipList = Dns.GetHostEntry(hostName).AddressList; .Where(x => x.OperationalStatus == OperationalStatus.Up)
.Where(x => x.NetworkInterfaceType is NetworkInterfaceType.Wireless80211
or NetworkInterfaceType.Ethernet)
.SelectMany(x => x.GetIPProperties().UnicastAddresses)
.Where(x => x.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(x => x.Address)
.ToList();
var ipV4List = new List<IPAddress>(); if (ips.Count > 0)
foreach (var ip in ipList)
{ {
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) return ips[^1];
{
ipV4List.Add(ip);
}
}
if (ipV4List.Count > 0)
{
return ipV4List[ipV4List.Count - 1];
} }
return IPAddress.Loopback; return IPAddress.Loopback;
} }
@ -116,28 +115,26 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
} }
List<UpdateData> dataToSend; List<UpdateData> dataToSend;
if (importantUpdates.Count > 0) if (importantUpdates.Count > 0)
{
for (int i = 0; i < clientsEP.Count; i++)
{ {
dataToSend = new List<UpdateData>(); dataToSend = new List<UpdateData>();
for (int j = 0; j < datapackSize && j < importantUpdates.Count; j++) for (int j = 0; j < datapackSize && j < importantUpdates.Count; j++)
dataToSend.Add(importantUpdates[j]); dataToSend.Add(importantUpdates[j]);
for (int i = 0; i < clientsEP.Count; i++)
{
Datagramm impDgramm = new Datagramm(); Datagramm impDgramm = new Datagramm();
impDgramm.DatagrammId = currentDatagrammId; impDgramm.DatagrammId = currentDatagrammId;
impDgramm.updateDatas = dataToSend; impDgramm.updateDatas = dataToSend;
impDgramm.isImportant = true; impDgramm.isImportant = true;
impDgramm.PlayerId = i + 1; impDgramm.PlayerId = i + 1;
sendedData.Add(impDgramm); sendedData.Add(impDgramm);
}
for (int j = 0; j < datapackSize && j < dataToSend.Count; j++) for (int j = 0; j < datapackSize && j < dataToSend.Count; j++)
importantUpdates.RemoveAt(0); importantUpdates.RemoveAt(0);
}
currentDatagrammId++; currentDatagrammId++;
} }
if (sendedData.Count != 0) if (sendedData.Count != 0)
{ {
for (int i = 0; i < clientsEP.Count; i++) for (int i = 0; i < clientsEP.Count; i++)
{ {
foreach (Datagramm Dgramm in sendedData.Where(x => x.PlayerId == i+1)) foreach (Datagramm Dgramm in sendedData.Where(x => x.PlayerId == i+1))

View file

@ -14,6 +14,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer
// public int IdEntity { get; set; } // public int IdEntity { get; set; }
public SerializableVector2 InputMovementDirection{get;set;} public SerializableVector2 InputMovementDirection{get;set;}
public SerializableVector2 InputAttackDirection {get;set;} public SerializableVector2 InputAttackDirection {get;set;}
public int PlayerId {get;set;}
public UpdateInput() public UpdateInput()
{ {
UpdateType = "UpdateInput"; UpdateType = "UpdateInput";

View file

@ -9,4 +9,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
public class UpdateInputInteraction : UpdateData public class UpdateInputInteraction : UpdateData
{ {
public UpdateInputInteraction() { UpdateType = "UpdateInputInteraction"; } public UpdateInputInteraction() { UpdateType = "UpdateInputInteraction"; }
public int PlayerId { get; set; }
} }

View file

@ -6,4 +6,5 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
public class UpdateInputShoot : UpdateData public class UpdateInputShoot : UpdateData
{ {
public UpdateInputShoot() { UpdateType = "UpdateInputShoot"; } public UpdateInputShoot() { UpdateType = "UpdateInputShoot"; }
public int PlayerId { get; set; }
} }

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
{
public class UpdateCreatePlayer : UpdateData
{
public int PlayerId { get; set; }
public UpdateCreatePlayer()
{
isImportant = true;
UpdateType = "UpdateCreatePlayer";
}
}
}

View file

@ -9,7 +9,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
/// </summary> /// </summary>
public class UpdateGameObjectWithoutIdCreated : UpdateData public class UpdateGameObjectWithoutIdCreated : UpdateData
{ {
public UpdateGameObjectWithoutIdCreated() { UpdateType = "UpdateGameObjectWithoutIdCreated"; } public UpdateGameObjectWithoutIdCreated() { UpdateType = "UpdateGameObjectWithoutIdCreated"; isImportant = true; }
public string GameObjectClassName { get; set; } public string GameObjectClassName { get; set; }
public SerializableVector2 position { get; set; } public SerializableVector2 position { get; set; }
} }

View file

@ -12,6 +12,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
public class UpdateGameObjectDeleted : UpdateData public class UpdateGameObjectDeleted : UpdateData
{ {
public UpdateGameObjectDeleted() { UpdateType = "UpdateGameObjectDeleted"; isImportant = false; } public UpdateGameObjectDeleted() { UpdateType = "UpdateGameObjectDeleted"; isImportant = false; }
public string GameObjectType; public string GameObjectType { get; set; }
} }
} }

View file

@ -11,8 +11,8 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
/// </summary> /// </summary>
public class UpdatePlayerParametrs : UpdateData public class UpdatePlayerParametrs : UpdateData
{ {
public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; } public UpdatePlayerParametrs() { UpdateType = "UpdatePlayerParametrs"; isImportant = true; }
public float radiatoin; public float radiatoin { get; set; }
public float health; public float health { get; set; }
} }
} }

View file

@ -27,6 +27,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates
[JsonDerivedType(typeof(UpdatePlayerExit))] [JsonDerivedType(typeof(UpdatePlayerExit))]
[JsonDerivedType(typeof(UpdateInputInteraction))] [JsonDerivedType(typeof(UpdateInputInteraction))]
[JsonDerivedType(typeof(UpdateInputShoot))] [JsonDerivedType(typeof(UpdateInputShoot))]
[JsonDerivedType(typeof(UpdateCreatePlayer))]
public class UpdateData public class UpdateData
{ {

View file

@ -28,18 +28,21 @@ namespace ZoFo.GameCore.GameManagers
public void SetMainVolume(float volume) public void SetMainVolume(float volume)
{ {
settingsContainer.MainVolume = volume; settingsContainer.MainVolume = volume;
//AppManager.Instance.SoundManager.Update(); // AppManager.Instance.SoundManager.Update();
SaveSettings(); SaveSettings();
} }
public void SetMusicVolume(float volume) public void SetMusicVolume(float volume)
{ {
settingsContainer.MusicVolume = volume; settingsContainer.MusicVolume = volume;
//AppManager.Instance.SoundManager.Update();
SaveSettings(); SaveSettings();
} }
public void SetSoundEffectsVolume(float volume) public void SetSoundEffectsVolume(float volume)
{ {
settingsContainer.SoundEffectsVolume = volume; settingsContainer.SoundEffectsVolume = volume;
// AppManager.Instance.SoundManager.Update();
SaveSettings(); SaveSettings();
} }
@ -68,6 +71,7 @@ namespace ZoFo.GameCore.GameManagers
} }
public void SaveSettings() public void SaveSettings()
{ {
AppManager.Instance.SoundManager.Update();
using (StreamWriter streamWriter = new StreamWriter("GameSettings.txt")) using (StreamWriter streamWriter = new StreamWriter("GameSettings.txt"))
{ {
string _str = JsonConvert.SerializeObject(settingsContainer); string _str = JsonConvert.SerializeObject(settingsContainer);

View file

@ -39,6 +39,8 @@ namespace ZoFo.GameCore.GameObjects
} }
public void StartAnimation(string animationId) public void StartAnimation(string animationId)
{
if (AppManager.Instance.gamestate == GameState.HostPlaying)
{ {
(graphicsComponent as Graphics.AnimatedGraphicsComponent).StartAnimation(animationId); (graphicsComponent as Graphics.AnimatedGraphicsComponent).StartAnimation(animationId);
AppManager.Instance.server.AddData(new GameManagers.NetworkManager.Updates.ServerToClient.UpdateAnimation() AppManager.Instance.server.AddData(new GameManagers.NetworkManager.Updates.ServerToClient.UpdateAnimation()
@ -47,6 +49,7 @@ namespace ZoFo.GameCore.GameObjects
IdEntity = Id IdEntity = Id
}); });
} }
}
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
DrawDebugRectangle(spriteBatch, collisionComponent.stopRectangle.SetOrigin(position), Color.Orange); DrawDebugRectangle(spriteBatch, collisionComponent.stopRectangle.SetOrigin(position), Color.Orange);
@ -55,9 +58,12 @@ namespace ZoFo.GameCore.GameObjects
} }
public virtual void Delete() public virtual void Delete()
{
if (AppManager.Instance.gamestate == GameState.HostPlaying)
{ {
AppManager.Instance.server.DeleteObject(this); AppManager.Instance.server.DeleteObject(this);
} }
} }
}
} }

View file

@ -14,7 +14,7 @@ namespace ZoFo.GameCore.GameObjects
{ {
public class Peeble:Collectable public class Peeble:Collectable
{ {
public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Peeble"); public override StaticGraphicsComponent graphicsComponent { get; } = new(_path + "Pebble");
public Peeble(Vector2 position) : base(position) { } public Peeble(Vector2 position) : base(position) { }
} }

View file

@ -22,7 +22,7 @@ namespace ZoFo.GameCore.GameObjects
public Zombie(Vector2 position) : base(position) public Zombie(Vector2 position) : base(position)
{ {
health = 5; health = 5;
speed = 0.5f; speed = 7.5f;
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(10, 20, 10, 10); collisionComponent.stopRectangle = new Rectangle(10, 20, 10, 10);
isAttacking = false; isAttacking = false;
@ -45,15 +45,36 @@ namespace ZoFo.GameCore.GameObjects
public override void Update() public override void Update()
{ {
if (isDying) return; if (isDying) return;
Vector2 duration = Vector2.Normalize( float m = 10000000;
AppManager.Instance.server.players[0].position - position int j = -1;
for (int i = 0; i < AppManager.Instance.server.players.Count; i++)
{
var player = AppManager.Instance.server.players[i];
if (m > (player.position.X - position.X) * (player.position.X - position.X) + (player.position.Y - position.Y) * (player.position.Y - position.Y))
{
m = (player.position.X - position.X) * (player.position.X - position.X) + (player.position.Y - position.Y) * (player.position.Y - position.Y);
j = i;
}
}
Vector2 duration = Vector2.Zero;
if (m<= 130000)
{
duration = Vector2.Normalize(
AppManager.Instance.server.players[j].position - position
); );
if (Random.Shared.NextDouble() > 0.999)
{
AppManager.Instance.SoundManager.StartSound("zombie sound", position, AppManager.Instance.server.players[0].position, pitch: new Random().Next(-1, 2) * (float)new Random().NextDouble());
}
}
if (!isAttacking) { velocity += new Vector2(duration.X * speed, duration.Y * speed); } if (!isAttacking) { velocity += new Vector2(duration.X * speed, duration.Y * speed); }
} }
public void OnPlayerClose(GameObject sender) public void OnPlayerClose(GameObject sender)
{ {
@ -61,6 +82,8 @@ namespace ZoFo.GameCore.GameObjects
if(!isAttacking) if(!isAttacking)
{ {
AppManager.Instance.SoundManager.StartSound("Zombi napal", position, AppManager.Instance.server.players[0].position,pitch:new Random().Next(-1,2)*(float)new Random().NextDouble());
StartAnimation("zombie_attack"); StartAnimation("zombie_attack");
isAttacking = true; isAttacking = true;
} }
@ -70,13 +93,14 @@ namespace ZoFo.GameCore.GameObjects
} }
public void EndAttack(string a) public void EndAttack(string a)
{ {
if (AppManager.Instance.server is null) return;
var damagedPlayers=AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position)); var damagedPlayers=AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position));
//TODO ДАМАЖИТЬ ИГРОКОВ В ЗОНЕ //TODO ДАМАЖИТЬ ИГРОКОВ В ЗОНЕ
if (damagedPlayers.Length>0) { DebugHUD.DebugLog("End of" + a); if (damagedPlayers.Length>0) { DebugHUD.DebugLog("End of" + a);
foreach (var item in damagedPlayers) foreach (var item in damagedPlayers)
item.TakeDamage(5); item.TakeDamage(20);
} }
isAttacking = false;
} }
public override void Die() public override void Die()
@ -87,9 +111,11 @@ namespace ZoFo.GameCore.GameObjects
public override void DeathEnd() public override void DeathEnd()
{ {
Instantiate(new Particle(collisionComponent.stopRectangle.Location.ToVector2() + position + ExtentionClass.RandomVector() * 20)); Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
Instantiate(new Particle(collisionComponent.stopRectangle.Location.ToVector2() + position + ExtentionClass.RandomVector() * 20)); Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
Instantiate(new Particle(collisionComponent.stopRectangle.Location.ToVector2() + position + ExtentionClass.RandomVector() * 20)); Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
Instantiate(new Particle(position - collisionComponent.stopRectangle.Size.ToVector2() / 2 + ExtentionClass.RandomVector() * 20));
base.DeathEnd(); base.DeathEnd();
} }

View file

@ -38,15 +38,15 @@ public class LivingEntity : Entity
{ {
base.UpdateAnimations(); base.UpdateAnimations();
} }
Vector2 prevPosition_forClient; protected Vector2 prevPosition_forClient;
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
if ((position - prevPosition_forClient).X < 0) if ((positionDraw - prevPosition_forClient).X < 0)
graphicsComponent.Flip = SpriteEffects.FlipHorizontally; graphicsComponent.Flip = SpriteEffects.FlipHorizontally;
else if ((position - prevPosition_forClient).X > 0) else if ((positionDraw - prevPosition_forClient).X > 0)
graphicsComponent.Flip = SpriteEffects.None; graphicsComponent.Flip = SpriteEffects.None;
base.Draw(spriteBatch); base.Draw(spriteBatch);
prevPosition_forClient = position; prevPosition_forClient = positionDraw;
} }
public virtual void Die() public virtual void Die()

View file

@ -12,6 +12,7 @@ using ZoFo.GameCore.Graphics;
using System.Diagnostics; using System.Diagnostics;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Linq;
namespace ZoFo.GameCore.GameObjects; namespace ZoFo.GameCore.GameObjects;
@ -22,7 +23,7 @@ public class Player : LivingEntity
private float speed; private float speed;
public int reloading; public int reloading;
public float health= 100; public float health = 100;
public float MaxHealth = 100; public float MaxHealth = 100;
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player.Animations, AppManager.Instance.AssetManager.Player.IdleAnimation); public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player.Animations, AppManager.Instance.AssetManager.Player.IdleAnimation);
@ -32,7 +33,7 @@ public class Player : LivingEntity
public float rad = 0; public float rad = 0;
public float MaxRad = 100; public float MaxRad = 100;
public LootData lootData; public LootData lootData;
Vector2 prevPosition;
public bool IsTryingToInteract { get; set; } public bool IsTryingToInteract { get; set; }
@ -41,13 +42,15 @@ public class Player : LivingEntity
/// Факт того, что плеер в этом апдейте пытается стрелять /// Факт того, что плеер в этом апдейте пытается стрелять
/// </summary> /// </summary>
public bool IsTryingToShoot { get; set; } public bool IsTryingToShoot { get; set; }
ScopeState prevScopeState;
public Player(Vector2 position) : base(position) public Player(Vector2 position) : base(position)
{ {
lootData = new LootData(); lootData = new LootData();
lootData.loots = new Dictionary<string, int>(); lootData.loots = new Dictionary<string, int>();
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(0, 15, 30, 15); collisionComponent.stopRectangle = new Rectangle(10, 15, 10, 15);
speed = 2.5f; speed = 7;
StartAnimation("player_look_down"); StartAnimation("player_look_down");
} }
@ -61,47 +64,97 @@ public class Player : LivingEntity
#region анимация управления подбора лута #region анимация управления подбора лута
DebugHUD.DebugSet("texture name", idName); DebugHUD.DebugSet("texture name", idName);
if (reloading>0) if (reloading > 0)
{ {
reloading--; reloading--;
} }
switch(AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation)) switch (AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation))
{ {
case ScopeState.Top: case ScopeState.Top:
if (idName!="player_run_up") if (idName != "player_run_up")
StartAnimation("player_run_up"); StartAnimation("player_run_up");
break; break;
case ScopeState.Down: case ScopeState.Down:
if (idName!="player_run_down") if (idName != "player_run_down")
StartAnimation("player_run_down"); StartAnimation("player_run_down");
break; break;
case ScopeState.Right: case ScopeState.Right:
case ScopeState.Left: case ScopeState.Left:
if (idName!="player_run_right") if (idName != "player_run_right")
StartAnimation("player_run_right"); StartAnimation("player_run_right");
break; break;
case ScopeState.TopRight: case ScopeState.TopRight:
case ScopeState.TopLeft: case ScopeState.TopLeft:
if (idName!="player_run_right_up") if (idName != "player_run_right_up")
StartAnimation("player_run_right_up"); StartAnimation("player_run_right_up");
break; break;
case ScopeState.DownRight: case ScopeState.DownRight:
case ScopeState.DownLeft: case ScopeState.DownLeft:
if (idName!="player_run_right_down") if (idName != "player_run_right_down")
StartAnimation("player_run_right_down"); StartAnimation("player_run_right_down");
break; break;
case ScopeState.Idle: case ScopeState.Idle:
if (idName!="player_look_down") if (idName != "player_look_down")
StartAnimation("player_look_down"); StartAnimation("player_look_down");
break; break;
} }
if (AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation) != ScopeState.Idle)
{
prevScopeState = AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation);
}
else if (AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation) == ScopeState.Idle && false)
{
switch (prevScopeState)
{
case ScopeState.Top:
if (idName != "player_look_up_weapon")
StartAnimation("player_look_up_weapon");
break;
case ScopeState.Down:
if (idName != "player_look_down_weapon")
StartAnimation("player_look_down_weapon");
break;
case ScopeState.Right:
case ScopeState.Left:
if (idName != "player_look_right_down_weapon")
StartAnimation("player_look_right_down_weapon");
break;
case ScopeState.TopRight:
case ScopeState.TopLeft:
if (idName != "player_look_right_up_weapon")
StartAnimation("player_look_right_up_weapon");
break;
case ScopeState.DownRight:
case ScopeState.DownLeft:
if (idName != "player_look_right_down_weapon")
StartAnimation("player_look_right_down_weapon");
break;
case ScopeState.Idle:
if (idName != "player_look_down")
StartAnimation("player_look_down");
break;
}
}
#endregion #endregion
#region анимация поворота оружия #region анимация поворота оружия
int currentAttackSection = AppManager.Instance.InputManager.ConvertAttackVector2ToState(InputWeaponRotation); int currentAttackSection = AppManager.Instance.InputManager.ConvertAttackVector2ToState(InputWeaponRotation);
switch(currentAttackSection) switch (currentAttackSection)
{ {
case 0 or 1: case 0 or 1:
//right //right
@ -156,7 +209,8 @@ public class Player : LivingEntity
MovementLogic(); MovementLogic();
} }
public void WeaponAttack(){ public void WeaponAttack()
{
} }
public void MovementLogic() public void MovementLogic()
@ -168,7 +222,12 @@ public class Player : LivingEntity
{ {
InputPlayerRotation = updateInput.InputMovementDirection.GetVector2(); InputPlayerRotation = updateInput.InputMovementDirection.GetVector2();
InputWeaponRotation = updateInput.InputAttackDirection.GetVector2(); InputWeaponRotation = updateInput.InputAttackDirection.GetVector2();
if (InputPlayerRotation.X != 0f || InputPlayerRotation.Y != 0f)
{
InputPlayerRotation /= (InputPlayerRotation.Length());
}
DebugHUD.DebugSet("dir", InputPlayerRotation.ToString());
DebugHUD.DebugSet("dir2", InputWeaponRotation.ToString());
} }
public void HandleInteract(UpdateInputInteraction updateInputInteraction) public void HandleInteract(UpdateInputInteraction updateInputInteraction)
{ {
@ -199,16 +258,24 @@ public class Player : LivingEntity
reloading = 5; reloading = 5;
IsTryingToShoot = true; IsTryingToShoot = true;
var rect = collisionComponent.stopRectangle.SetOrigin(position); List<Entity> entities = AppManager.Instance.server.collisionManager.GetEntities(GetDamageArea(InputWeaponRotation), this).ToList();
rect.Width += 100; entities.AddRange(AppManager.Instance.server.collisionManager.GetEntities(GetDamageArea(InputWeaponRotation, 2), this).ToList());
rect.Height += 100; entities.AddRange(AppManager.Instance.server.collisionManager.GetEntities(GetDamageArea(InputWeaponRotation, 3), this).ToList());
Entity[] entities = AppManager.Instance.server.collisionManager.GetEntities(rect, this);
if (entities != null) if (entities != null)
{ {
foreach (Entity entity in entities) foreach (Entity entity in entities)
{ {
if (entity is Enemy) if (entity is Enemy)
{ {
for (int i = 3; i <= 3; i++)
{
Instantiate(new Particle(
((position - graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2) * (3 - i) / 3f) +
((entity.position - graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2) * i / 3f) + ExtentionClass.RandomVector() * 3
));
}
(entity as Enemy).TakeDamage(1); (entity as Enemy).TakeDamage(1);
} }
} }
@ -216,7 +283,22 @@ public class Player : LivingEntity
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
//DrawDebugRectangle(spriteBatch, collisionComponent.stopRectangle.SetOrigin(position + new Vector2(10,10)), Color.Green);
DrawDebugRectangle(spriteBatch, GetDamageArea(AppManager.Instance.InputManager.InputAttackDirection), Color.Green);
DrawDebugRectangle(spriteBatch, GetDamageArea(AppManager.Instance.InputManager.InputAttackDirection, 2), Color.Green);
DrawDebugRectangle(spriteBatch, GetDamageArea(AppManager.Instance.InputManager.InputAttackDirection, 3), Color.Green);
base.Draw(spriteBatch); base.Draw(spriteBatch);
} }
public Rectangle GetDamageArea(Vector2 direction, float mult = 1)
{
direction.Normalize();
var rect = collisionComponent.stopRectangle.SetOrigin(position);
int size = 10;
rect.X -= size;
rect.Y -= size;
rect.Width += 2 * size;
rect.Height += 2 * size;
rect = rect.SetOrigin(direction * 40 * mult);
return rect;
}
} }

View file

@ -16,11 +16,16 @@ namespace ZoFo.GameCore.GameObjects
public Particle(Vector2 position) : base(position) public Particle(Vector2 position) : base(position)
{ {
graphicsComponent.ObjectDrawRectangle = new Rectangle(-30, -30,60,60).SetOrigin(position); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0,60,60).SetOrigin(position);
AppManager.Instance.SoundManager.StartSound("gun-gunshot-01", Vector2.Zero, Vector2.Zero, 0.5f, (float)(Random.Shared.NextDouble()*2-1));
(graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ => { (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += _ => {
if (AppManager.Instance.client!=null)
{
AppManager.Instance.client.DeleteObject(this); AppManager.Instance.client.DeleteObject(this);
}
}; };
} }
} }

View file

@ -0,0 +1,42 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects
{
public class ExitZone : Entity
{
public override GraphicsComponent graphicsComponent { get; } = new StaticGraphicsComponent("Content/Textures/icons/ExitZone");
public ExitZone(Vector2 position) : base(position)
{
collisionComponent.OnTriggerZone += Exit;
graphicsComponent.ObjectDrawRectangle.Width = 100;
graphicsComponent.ObjectDrawRectangle.Height = 100;
position = new Vector2(500f, 500f);
collisionComponent.isTrigger = true;
collisionComponent.triggerRectangle = new Rectangle(0, 0, 100, 100);
}
public void Exit(GameObject sender)
{
if (sender is Player &&
AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position)).Length == AppManager.Instance.server.players.Count)
{
sender.position = new Vector2(0f, 0f);
AppManager.Instance.server.EndGame();
AppManager.Instance.debugHud.Set("Exit", sender.position.ToString());
}
}
}
}

View file

@ -24,6 +24,7 @@ public abstract class GameObject
graphicsComponent.ObjectDrawRectangle.X = (int)position.X; graphicsComponent.ObjectDrawRectangle.X = (int)position.X;
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y; graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y;
positionDraw = position;
} }
public virtual void UpdateLogic() public virtual void UpdateLogic()
{ {
@ -42,9 +43,12 @@ public abstract class GameObject
} }
public void Instantiate(GameObject gameObject) public void Instantiate(GameObject gameObject)
{
if (AppManager.Instance.gamestate == GameState.HostPlaying)
{ {
AppManager.Instance.server.RegisterGameObject(gameObject); AppManager.Instance.server.RegisterGameObject(gameObject);
} }
}
#endregion #endregion
@ -58,6 +62,7 @@ public abstract class GameObject
public void PlayAnimation_OnClient() public void PlayAnimation_OnClient()
{ {
graphicsComponent.Update(); graphicsComponent.Update();
} }
/// <summary> /// <summary>
@ -69,14 +74,19 @@ public abstract class GameObject
graphicsComponent.LoadContent(); graphicsComponent.LoadContent();
} }
/// <summary>
/// for smooth client draw
/// </summary>
public Vector2 positionDraw;
/// <summary> /// <summary>
/// Для клиента /// Для клиента
/// Обновление, которое вызывается у клиента, для просмотра анимаций /// Обновление, которое вызывается у клиента, для просмотра анимаций
/// </summary> /// </summary>
public virtual void UpdateAnimations() public virtual void UpdateAnimations()
{ {
graphicsComponent.ObjectDrawRectangle.X = (int)position.X; //Move To place where Updates Sets your position positionDraw = (position * 0.15f + positionDraw*0.85f);
graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y; graphicsComponent.ObjectDrawRectangle.X = (int)positionDraw.X; //Move To place where Updates Sets your position
graphicsComponent.ObjectDrawRectangle.Y = (int)positionDraw.Y;
PlayAnimation_OnClient(); PlayAnimation_OnClient();
} }
@ -93,6 +103,7 @@ public abstract class GameObject
} }
public void DrawDebugRectangle(SpriteBatch spriteBatch, Rectangle _rectangle, Nullable<Color> color = null) public void DrawDebugRectangle(SpriteBatch spriteBatch, Rectangle _rectangle, Nullable<Color> color = null)
{ {
return;
if (color is null) color = new Color(1, 0, 0, 0.1f); if (color is null) color = new Color(1, 0, 0, 0.1f);
if (color.Value.A == 255) color = new Color(color.Value, 0.25f); if (color.Value.A == 255) color = new Color(color.Value, 0.25f);
spriteBatch.Draw(debugTexture, spriteBatch.Draw(debugTexture,

View file

@ -35,7 +35,7 @@ namespace ZoFo.GameCore
{ {
networkManager = new ServerNetworkManager(); networkManager = new ServerNetworkManager();
collisionManager = new CollisionManager(); collisionManager = new CollisionManager();
players = new List<Player>();
} }
#region server logic as App #region server logic as App
@ -69,20 +69,35 @@ namespace ZoFo.GameCore
{ {
case "UpdateInput": case "UpdateInput":
if (players.Count > 0) if (players.Count > 0)
players[0].HandleNewInput(updateData as UpdateInput);//TODO id instead of 0 {
UpdateInput data = updateData as UpdateInput;
if (data.PlayerId > 0)
{
players[data.PlayerId - 1].HandleNewInput(data);
}
}
//TODO id instead of 0
else else
DebugHUD.DebugLog("NO PLAYER ON MAP"); DebugHUD.DebugLog("NO PLAYER ON MAP");
break; break;
case "UpdateTileCreated": case "UpdateTileCreated":
break; break;
case "UpdateInputInteraction": case "UpdateInputInteraction":
players[0].HandleInteract(updateData as UpdateInputInteraction); if (players.Count > 0)
{
UpdateInputInteraction data = updateData as UpdateInputInteraction;
players[data.PlayerId - 1].HandleInteract(data);
}
break; break;
case "UpdateInputShoot": case "UpdateInputShoot":
players[0].HandleShoot(updateData as UpdateInputShoot); if (players.Count > 0)
{
UpdateInputShoot data = updateData as UpdateInputShoot;
players[data.PlayerId - 1].HandleShoot(data);
}
break; break;
} }
} }//Поспать
/// <summary> /// <summary>
@ -120,18 +135,20 @@ namespace ZoFo.GameCore
collisionManager = new CollisionManager(); collisionManager = new CollisionManager();
gameObjects = new List<GameObject>(); gameObjects = new List<GameObject>();
entities = new List<Entity>(); entities = new List<Entity>();
players = new List<Player>();
networkManager.StartGame(); networkManager.StartGame();
new MapManager().LoadMap(); new MapManager().LoadMap();
//AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(0, 0))); //AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(0, 0)));
AppManager.Instance.server.RegisterGameObject(new Player(new Vector2(740, 140))); for (int i = 0; i < networkManager.clientsEP.Count; i++)
{
Player player = new Player(new Vector2(-800 - 30 * i, 750));
RegisterGameObject(player);
networkManager.AddData(new UpdateCreatePlayer() { PlayerId = i+1, IdEntity=player.Id});
}
//for (int i = 0; i < 20; i++) //for (int i = 0; i < 20; i++)
// for (int j = 0; j < 20; j++) // for (int j = 0; j < 20; j++)
// AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1300 + i*70, 1000+j*70))); // AppManager.Instance.server.RegisterGameObject(new Zombie(new Vector2(1300 + i*70, 1000+j*70)));
AppManager.Instance.server.RegisterGameObject(new Ammo(new Vector2(140, 440)));
AppManager.Instance.server.RegisterGameObject(new Ammo(new Vector2(240, 440)));
} }
/// <summary> /// <summary>
@ -141,6 +158,7 @@ namespace ZoFo.GameCore
{ {
UpdateGameEnded gameEnded = new UpdateGameEnded(); UpdateGameEnded gameEnded = new UpdateGameEnded();
networkManager.AddData(gameEnded); networkManager.AddData(gameEnded);
// networkManager.CloseConnection();
} }
public List<GameObject> gameObjects = new List<GameObject>(); public List<GameObject> gameObjects = new List<GameObject>();
@ -211,7 +229,6 @@ namespace ZoFo.GameCore
}); });
return; return;
} }
if (gameObject is Entity entity) if (gameObject is Entity entity)
{ {
AddData(new UpdateGameObjectCreated() AddData(new UpdateGameObjectCreated()

View file

@ -29,6 +29,7 @@
<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="MonoGame.Templates.CSharp" Version="3.8.1.1-kniEngine" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>