Merge pull request #83 from progtime-net/DevelopmentX

Development x
This commit is contained in:
SergoDobro 2024-08-20 00:36:49 +03:00 committed by GitHub
commit 3f3c9227d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 593 additions and 167 deletions

View file

@ -0,0 +1,91 @@
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Base;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Enums;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework.Content;
namespace MonogameLibrary.UI.Elements;
public class HoverWindow : DrawableUIElement
{
public string tagItem;
public string discriptions;
public Dictionary<string, int> resourcesNeededToCraft;
private List<Label> Labels = new List<Label>();
public float scale2;
public string fontName2;
public Color fontColor2;
public string itemTextureName1;
private DrawableUIElement icon;
private Label itemName;
private Label discription;
private int labelIndex = 0;
public HoverWindow(UIManager manager, int layerIndex = 0, string textureName = "") : base(manager, layerIndex, textureName)
{
}
public void Initialize(ContentManager content)
{
icon = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Width / 20, rectangle.Y + rectangle.Width / 20, rectangle.Width / 5, rectangle.Width / 5),
mainColor = Color.White, textureName = itemTextureName1
};
icon.LoadTexture(content);
itemName = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Width / 20 + rectangle.Width / 5 + rectangle.Width / 20, rectangle.Y + rectangle.Width / 10, rectangle.Width / 3 * 2, rectangle.Width / 5 ),
fontColor = fontColor2, text = tagItem, scale = scale2, fontName = fontName2, mainColor = Color.Transparent, textAligment = TextAligment.Left
};
itemName.LoadTexture(content);
discription = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Width / 20, rectangle.Y + rectangle.Width / 20 + rectangle.Width / 5 + rectangle.Width / 20, rectangle.Width / 5, rectangle.Width / 5),
fontColor = fontColor2, text = discriptions, scale = scale2 / 1.5f, fontName = fontName2, mainColor = Color.Transparent, textAligment = TextAligment.Left
};
discription.LoadTexture(content);
foreach (var resource in resourcesNeededToCraft)
{
Label res = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Width / 2 - rectangle.Width / 3 / 2, rectangle.Y + rectangle.Width / 20 + rectangle.Width / 5 + rectangle.Width / 5 + rectangle.Width / 20 + (rectangle.Width / 10 + rectangle.Width / 40) * labelIndex, rectangle.Width / 3, rectangle.Width / 10),
fontColor = fontColor2, text = resource.Key + " " + resource.Value, scale = scale2, fontName = fontName2, mainColor = Color.Transparent
};
res.LoadTexture(content);
Labels.Add(res);
labelIndex++;
}
}
public override void LoadTexture(ContentManager content)
{
base.LoadTexture(content);
}
public void Update(GameTime gameTime)
{
labelIndex = 0;
icon.rectangle = new Rectangle(rectangle.X + rectangle.Width / 20, rectangle.Y + rectangle.Width / 20, rectangle.Width / 5, rectangle.Width / 5);
itemName.rectangle = new Rectangle(rectangle.X + rectangle.Width / 20 + rectangle.Width / 5 + rectangle.Width / 20,
rectangle.Y + rectangle.Width / 10, rectangle.Width / 3 * 2, rectangle.Width / 5);
discription.rectangle = new Rectangle(rectangle.X + rectangle.Width / 20,
rectangle.Y + rectangle.Width / 20 + rectangle.Width / 5 + rectangle.Width / 20, rectangle.Width / 5,
rectangle.Width / 5);
foreach (var label in Labels)
{
label.rectangle = new Rectangle(rectangle.X + rectangle.Width / 2 - rectangle.Width / 3 / 2,
rectangle.Y + rectangle.Width / 20 + rectangle.Width / 5 + rectangle.Width / 5 + rectangle.Width / 20 +
(rectangle.Width / 10 + rectangle.Width / 40) * labelIndex, rectangle.Width / 3, rectangle.Width / 10);
labelIndex++;
}
}
}

View file

@ -9,10 +9,11 @@ using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
namespace MonogameLibrary.UI.Elements; namespace MonogameLibrary.UI.Elements;
public class ItemDisplayButton : DrawableUIElement public class ItemDisplayButton : Button
{ {
public int count; public int count;
public string itemTextureName; public string itemTextureName;
@ -23,6 +24,11 @@ public class ItemDisplayButton : DrawableUIElement
public string text1; public string text1;
public float scale1; public float scale1;
private DrawableUIElement icon; private DrawableUIElement icon;
private HoverState presentState = HoverState.None;
private HoverWindow hoverWindow = null;
private ContentManager content;
public string discriptions1;
public Dictionary<string, int> resourcesNeededToCraft1;
public ItemDisplayButton(UIManager manager) : base(manager) public ItemDisplayButton(UIManager manager) : base(manager)
@ -51,6 +57,7 @@ public class ItemDisplayButton : DrawableUIElement
public override void LoadTexture(ContentManager content) public override void LoadTexture(ContentManager content)
{ {
this.content = content;
icon.LoadTexture(content); icon.LoadTexture(content);
base.LoadTexture(content); base.LoadTexture(content);
if (itemTextureName == "") if (itemTextureName == "")
@ -72,6 +79,47 @@ public class ItemDisplayButton : DrawableUIElement
} }
} }
public bool Update(GameTime gameTime)
{
if (hoverState == HoverState.Hovering)
{
if (presentState != hoverState)
{
hoverWindow = new HoverWindow(Manager)
{
rectangle = new Rectangle(Mouse.GetState().Position.X, Mouse.GetState().Position.Y, rectangle.Width, rectangle.Height * 10),
mainColor = Color.Gray,
tagItem = text1,
discriptions = discriptions1,
resourcesNeededToCraft = resourcesNeededToCraft1,
fontColor2 = fontColor1,
fontName2 = fontName1,
scale2 = scale1,
itemTextureName1 = itemTextureName
};
hoverWindow.Initialize(content);
hoverWindow.LoadTexture(content);
}
hoverWindow.rectangle.X = Mouse.GetState().Position.X;
hoverWindow.rectangle.Y = Mouse.GetState().Position.Y;
hoverWindow.Update(gameTime);
}
else if (hoverState == HoverState.None)
{
if (presentState != hoverState)
{
return true;
}
}
presentState = hoverState;
return false;
}
public override void Draw(SpriteBatch _spriteBatch) public override void Draw(SpriteBatch _spriteBatch)
{ {
base.Draw(_spriteBatch); base.Draw(_spriteBatch);

View file

@ -9,6 +9,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
namespace MonogameLibrary.UI.Elements; namespace MonogameLibrary.UI.Elements;
@ -23,6 +24,12 @@ public class ItemDisplayLabel : DrawableUIElement
public string text1; public string text1;
public float scale1; public float scale1;
private DrawableUIElement icon; private DrawableUIElement icon;
private HoverState presentState = HoverState.None;
private HoverWindow hoverWindow = null;
public string discriptions1;
public Dictionary<string, int> resourcesNeededToCraft1;
public HoverState hoverState = HoverState.None;
private ContentManager content;
public ItemDisplayLabel(UIManager manager) : base(manager) public ItemDisplayLabel(UIManager manager) : base(manager)
@ -51,6 +58,7 @@ public class ItemDisplayLabel : DrawableUIElement
public override void LoadTexture(ContentManager content) public override void LoadTexture(ContentManager content)
{ {
this.content = content;
icon.LoadTexture(content); icon.LoadTexture(content);
base.LoadTexture(content); base.LoadTexture(content);
if (itemTextureName == "") if (itemTextureName == "")
@ -71,9 +79,72 @@ public class ItemDisplayLabel : DrawableUIElement
} }
} }
} }
public bool Update(GameTime gameTime)
{
if (rectangle.Intersects(new Rectangle(Mouse.GetState().Position, Point.Zero)))
{
hoverState = HoverState.Hovering;
}
else
{
hoverState = HoverState.None;
}
if (hoverState == HoverState.Hovering)
{
if (presentState != hoverState)
{
if (resourcesNeededToCraft1 == null)
{
resourcesNeededToCraft1 = new Dictionary<string, int>();
}
hoverWindow = new HoverWindow(Manager)
{
rectangle = new Rectangle(Mouse.GetState().Position.X, Mouse.GetState().Position.Y, rectangle.Width, rectangle.Height * 10),
mainColor = Color.Gray,
tagItem = text1,
discriptions = discriptions1,
resourcesNeededToCraft = resourcesNeededToCraft1,
fontColor2 = fontColor1,
fontName2 = fontName1,
scale2 = scale1,
itemTextureName1 = itemTextureName
};
hoverWindow.Initialize(content);
hoverWindow.LoadTexture(content);
}
hoverWindow.rectangle.X = Mouse.GetState().Position.X;
hoverWindow.rectangle.Y = Mouse.GetState().Position.Y;
hoverWindow.Update(gameTime);
}
else if (hoverState == HoverState.None)
{
if (presentState != hoverState)
{
return true;
}
}
presentState = hoverState;
return false;
}
public override void Draw(SpriteBatch _spriteBatch) public override void Draw(SpriteBatch _spriteBatch)
{ {
if (hoverState == HoverState.None)
{
_spriteBatch.Draw(texture, rectangle, Color.White);
}
else if (hoverState == HoverState.Hovering)
{
_spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211));
}
base.Draw(_spriteBatch); base.Draw(_spriteBatch);
_spriteBatch.Draw(texture, rectangle, Color.White);
} }
} }

View file

@ -34,6 +34,13 @@
/processorParam:TextureFormat=Compressed /processorParam:TextureFormat=Compressed
/build:Fonts/Font3.spritefont /build:Fonts/Font3.spritefont
#begin Fonts/Font4.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Compressed
/build:Fonts/Font4.spritefont
#begin MapData/TileMaps/main.tmj #begin MapData/TileMaps/main.tmj
/copy:MapData/TileMaps/main.tmj /copy:MapData/TileMaps/main.tmj

View file

@ -0,0 +1,64 @@
<?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>Troubleside-lgjxX.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>32</Start>
<End>127</End>
</CharacterRegion>
<CharacterRegion>
<Start>&#1040;</Start>
<End>&#1112;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>

Binary file not shown.

View file

@ -1,78 +1,49 @@
{ {
"Map/SizeTest": {
"height": 4300,
"width": 2
},
"activeFile": "TileMaps/main.tmj", "activeFile": "TileMaps/main.tmj",
"expandedProjectPaths": [ "expandedProjectPaths": [
"TileMaps",
"Templates",
".", ".",
"TileSets", "TileSets"
"TileMaps"
], ],
"fileStates": { "fileStates": {
"": {
"scaleInDock": 1
},
"TileMaps/TileSets/TileSet 1.tsj": {
"scaleInDock": 1
},
"TileMaps/main.tmj": { "TileMaps/main.tmj": {
"scale": 0.33, "scale": 0.75,
"selectedLayer": 1, "selectedLayer": 1,
"viewCenter": { "viewCenter": {
"x": 1010.6060606060606, "x": 1860.6666666666665,
"y": 553.0303030303031 "y": 871.3333333333333
} }
}, },
"TileMaps/main.tmj#IconSet": {
"dynamicWrapping": true,
"scaleInEditor": 1
},
"TileSets/CollisionTileSet.tsj": {
"scaleInDock": 0.75,
"scaleInEditor": 1
},
"TileSets/IconSet.tsj": { "TileSets/IconSet.tsj": {
"dynamicWrapping": true "dynamicWrapping": true,
"scaleInDock": 1,
"scaleInEditor": 1
}, },
"TileSets/TileSet 1.tsj": { "TileSets/TileSet 1.tsj": {
"dynamicWrapping": false, "dynamicWrapping": false,
"scaleInDock": 1, "scaleInDock": 1.5,
"scaleInEditor": 1.5 "scaleInEditor": 3
}, },
"TileSets/TilesetNature.tsj": { "TileSets/TilesetNature.tsj": {
"dynamicWrapping": false "scaleInDock": 1.5,
"scaleInDock": 1
},
"TileSets/WallSet.tsj": {
"scaleInDock": 1,
"scaleInEditor": 1 "scaleInEditor": 1
}, },
"TileSets/tileset 1 collision.tsj": { "TileSets/tileset 1 collision.tsj": {
"scaleInDock": 1 "scaleInDock": 1
} }
}, },
"last.imagePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/Textures/icons",
"last.objectTemplatePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/MapData/Templates",
"openFiles": [ "openFiles": [
"TileMaps/main.tmj",
"TileSets/IconSet.tsj",
"TileSets/TileSet 1.tsj", "TileSets/TileSet 1.tsj",
"TileMaps/main.tmj" "TileSets/TilesetNature.tsj"
], ],
"project": "MapSession.tiled-project", "project": "MapSession.tiled-project",
"recentFiles": [ "recentFiles": [
"TileSets/TilesetNature.tsj",
"TileSets/TileSet 1.tsj", "TileSets/TileSet 1.tsj",
"TileMaps/main.tmj", "TileSets/IconSet.tsj",
"TileSets/CollisionTileSet.tsj", "TileMaps/main.tmj"
"TileSets/WallSet.tsj" ]
],
"stampsFolder": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/MapData/TileStamps",
"tileset.embedInMap": false,
"tileset.lastUsedFormat": "json",
"tileset.margin": 0,
"tileset.spacing": 0,
"tileset.tileSize": {
"height": 16,
"width": 16
},
"tileset.type": 1
} }

View file

@ -1 +1 @@
{"id":"zombie_attack","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":64,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":3,"isCycle":true,"offset":"0, 0"} {"id":"zombie_attack","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":64,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":3,"isCycle":false,"offset":"0, 0"}

View file

@ -1 +1 @@
{"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"} {"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"}

View file

@ -23,7 +23,6 @@ using System.Web;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -50,17 +49,17 @@ namespace ZoFo.GameCore
networkManager.AddData(new UpdateInput() networkManager.AddData(new UpdateInput()
{ {
InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection, InputMovementDirection = AppManager.Instance.InputManager.InputMovementDirection,
InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection InputAttackDirection = AppManager.Instance.InputManager.InputAttackDirection
}); });
}; };
AppManager.Instance.InputManager.OnInteract += () => AppManager.Instance.InputManager.OnInteract += () =>
{ {
networkManager.AddData(new UpdateInputInteraction() { }); networkManager.AddData(new UpdateInputInteraction() { });
}; };
AppManager.Instance.InputManager.ShootEvent += () => AppManager.Instance.InputManager.ShootEvent += () =>
{ {
networkManager.AddData(new UpdateInputShoot() { }); networkManager.AddData(new UpdateInputShoot() { });
}; };
} }
@ -95,7 +94,7 @@ namespace ZoFo.GameCore
Player myPlayer; Player myPlayer;
List<MapObject> mapObjects = new List<MapObject>(); List<MapObject> mapObjects = new List<MapObject>();
List<GameObject> gameObjects = new List<GameObject>(); List<GameObject> gameObjects = new List<GameObject>();
List<Player> players = new List<Player>(); List<Player> players = new List<Player>();
List<StopObject> stopObjects = new List<StopObject>(); List<StopObject> stopObjects = new List<StopObject>();
@ -112,8 +111,13 @@ namespace ZoFo.GameCore
} }
networkManager.SendData();//set to ticks networkManager.SendData();//set to ticks
if (myPlayer!=null) if (myPlayer != null)
GraphicsComponent.CameraPosition = (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2()/2 - AppManager.Instance.CurentScreenResolution.ToVector2()/(2*GraphicsComponent.scaling)).ToPoint(); GraphicsComponent.CameraPosition =
((GraphicsComponent.CameraPosition.ToVector2() *0.9f +
(myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2() / 2 - AppManager.Instance.CurentScreenResolution.ToVector2() / (2 * GraphicsComponent.scaling)
) * 0.1f
) )
.ToPoint();
} }
internal void Draw(SpriteBatch spriteBatch) internal void Draw(SpriteBatch spriteBatch)
{ {
@ -151,47 +155,47 @@ namespace ZoFo.GameCore
(update as UpdateStopObjectCreated).Size.GetPoint().ToVector2(), (update as UpdateStopObjectCreated).Size.GetPoint().ToVector2(),
(update as UpdateStopObjectCreated).sourceRectangle.GetRectangle(), (update as UpdateStopObjectCreated).sourceRectangle.GetRectangle(),
(update as UpdateStopObjectCreated).tileSetName, (update as UpdateStopObjectCreated).tileSetName,
(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)
{ {
GameObject created_gameObject; GameObject created_gameObject;
if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests") if((update as UpdateGameObjectCreated).GameObjectType == "Player")
gameObjects.Add(new EntittyForAnimationTests((update as UpdateGameObjectCreated).position));
if ((update as UpdateGameObjectCreated).GameObjectType == "Player")
{ {
created_gameObject = new Player((update as UpdateGameObjectCreated).position); created_gameObject = new Player((update as UpdateGameObjectCreated).position);
players.Add(created_gameObject as Player); players.Add(created_gameObject as Player);
myPlayer = players[0]; myPlayer = players[0];
gameObjects.Add(created_gameObject); gameObjects.Add(created_gameObject);
} }
if ((update as UpdateGameObjectCreated).GameObjectType == "Ammo") else if((update as UpdateGameObjectCreated).GameObjectType == "Ammo")
gameObjects.Add(new Ammo((update as UpdateGameObjectCreated).position)); gameObjects.Add(new Ammo((update as UpdateGameObjectCreated).position));
if ((update as UpdateGameObjectCreated).GameObjectType == "Zombie") else if((update as UpdateGameObjectCreated).GameObjectType == "Zombie")
gameObjects.Add(new Zombie((update as UpdateGameObjectCreated).position)); gameObjects.Add(new Zombie((update as UpdateGameObjectCreated).position));
else
{
Type t = Type.GetType("ZoFo.GameCore.GameObjects." + (update as UpdateGameObjectCreated).GameObjectType);
GameObject gameObject = Activator.CreateInstance(t, (update as UpdateGameObjectCreated).position) as GameObject;
if (gameObject is Entity)
(gameObject as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity);
gameObjects.Add(gameObject);
}
(gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity);
(gameObjects.Last() as Entity).SetIdByClient((update as UpdateGameObjectCreated).IdEntity);
//var a = Assembly.GetAssembly(typeof(GameObject));
//gameObjects.Add( TODO reflection
//Activator.CreateInstance(Type.GetType("ZoFo.GameCore.GameObjects.Entities.EntittyForAnimationTests")
///*(update as UpdateGameObjectCreated).GameObjectType*/, new []{ new Vector2(100, 100) })
//as GameObject
//);
} }
else if (update is UpdatePosition) else if (update is UpdatePosition)
{ {
var ent = FindEntityById(update.IdEntity); var ent = FindEntityById(update.IdEntity);
ent.position = (update as UpdatePosition).NewPosition; if (ent != null)
ent.position = (update as UpdatePosition).NewPosition;
} }
else if (update is UpdateAnimation) else if (update is UpdateAnimation)
{ {
var ent = FindEntityById(update.IdEntity); var ent = FindEntityById(update.IdEntity);
if (ent != null) if (ent != null)
((ent as Entity).graphicsComponent as AnimatedGraphicsComponent).StartAnimation((update as UpdateAnimation).animationId); ((ent as Entity).graphicsComponent as AnimatedGraphicsComponent).StartAnimation((update as UpdateAnimation).animationId);
//DebugHUD.Instance.Log("new Animation " + ent.position); //DebugHUD.Instance.Log("new Animation " + ent.position);
} }
else if (update is UpdateGameObjectDeleted) else if (update is UpdateGameObjectDeleted)
{ {

View file

@ -19,17 +19,20 @@ namespace ZoFo.GameCore.GUI;
public class BaseGUI : AbstractGUI public class BaseGUI : AbstractGUI
{ {
private DrawableUIElement menuBackground; private DrawableUIElement menuBackground;
private List<ItemDisplayLabel> ItemDisplayButtonsList; private List<ItemDisplayLabel> ItemDisplayLabelsList;
private List<ItemDisplayButton> ItemDisplayButtonsList;
private int buttonIndex = 0; private int buttonIndex = 0;
private string textureName; private string textureName;
protected override void CreateUI() protected override void CreateUI()
{ {
ItemDisplayButtonsList = new List<ItemDisplayLabel>(); ItemDisplayLabelsList = new List<ItemDisplayLabel>();
ItemDisplayButtonsList = new List<ItemDisplayButton>();
int width = AppManager.Instance.CurentScreenResolution.X; int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y; int height = AppManager.Instance.CurentScreenResolution.Y;
Dictionary<string, int> playerItems = AppManager.Instance.playerData.items; Dictionary<string, int> playerItems = AppManager.Instance.playerData.items;
Dictionary<string, ItemInfo> items = AppManager.Instance.ItemManager.tagItemPairs; Dictionary<string, ItemInfo> items = AppManager.Instance.ItemManager.tagItemPairs;
int numberCraftItem = 0;
menuBackground = new DrawableUIElement(Manager) menuBackground = new DrawableUIElement(Manager)
{ {
@ -46,67 +49,110 @@ public class BaseGUI : AbstractGUI
fontName = "Fonts\\Font" fontName = "Fonts\\Font"
}); });
DrawableUIElement baseHudBack = new DrawableUIElement(Manager) DrawableUIElement baseItemBack = new DrawableUIElement(Manager)
{ {
rectangle = new Rectangle(width / 2 - (int)(width / 1.5) / 2, height / 2 - (int)(height / 1.5) / 2, rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2,
(int)(width / 1.5), (int)(height / 1.5)), height / 2 - (int)(height / 1.5) / 2,
height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray mainColor = Color.LightGray
}; };
Elements.Add(baseHudBack); Elements.Add(baseItemBack);
DrawableUIElement baseCraftBack = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(width / 2 + height / 160, height / 2 - (int)(height / 1.5) / 2,
height / 40 + width / 5, (int)(height / 1.5)),
mainColor = Color.LightGray
};
Elements.Add(baseCraftBack);
//player itams //player itams
foreach (var item in playerItems) foreach (var item in playerItems)
{ {
textureName = AppManager.Instance.ItemManager.GetItemInfo(item.Key).textureName; if (item.Value > 0)
var temp = new ItemDisplayLabel(Manager)
{ {
rectangle = new Rectangle(width / 2 - (int)(width / 1.5) / 2 + height / 80, ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
height / 2 - (int)(height / 1.5) / 2 + height / 80 + (height / 20 + height / 80) * (buttonIndex), var temp = new ItemDisplayLabel(Manager)
(int)(width / 5), (int)(height / 20)), {
text1 = item.Key, rectangle = new Rectangle(width / 2 - (height / 16 + (int)(width / 2.5)) / 2 + height / 80,
scale1 = 0.4f, height / 2 - (int)(height / 1.5) / 2 + height / 80 +
count = item.Value, (height / 20 + height / 80) * (buttonIndex),
itemTextureName = textureName, (int)(width / 5), (int)(height / 20)),
fontColor1 = Color.White, text1 = item.Key,
mainColor = Color.Gray, scale1 = 0.4f,
fontName1 = "Fonts\\Font3" count = item.Value,
}; itemTextureName = itemInfo.textureName,
Elements.Add(temp); fontColor1 = Color.White,
temp.Initialize(); mainColor = Color.Gray,
temp.LoadTexture(AppManager.Instance.Content); fontName1 = "Fonts\\Font4",
ItemDisplayButtonsList.Add(temp); discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayLabelsList.Add(temp);
buttonIndex++; buttonIndex++;
}
} }
// craftable items // craftable items
buttonIndex = 0; buttonIndex = 0;
foreach (var item in items) foreach (var item in items)
{ {
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key); try
if (itemInfo.isCraftable)
{ {
var temp = new ItemDisplayLabel(Manager) ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
if (itemInfo.isCraftable)
{ {
rectangle = new Rectangle(width / 2 - (int)(width / 1.5) / 2 + height / 40 + width / 5, Dictionary<string, int> needToCraft =
height / 2 - (int)(height / 1.5) / 2 + height / 80 + AppManager.Instance.ItemManager.GetItemInfo(item.Key).resourcesNeededToCraft;
(height / 20 + height / 80) * (buttonIndex), numberCraftItem = playerItems[needToCraft.Keys.First()] / needToCraft.Values.First();
(int)(width / 5), (int)(height / 20)), foreach (var itemNeedToCraft in needToCraft)
text1 = item.Key, {
scale1 = 0.4f, int xValue = playerItems[itemNeedToCraft.Key] / itemNeedToCraft.Value;
count = 0, if (numberCraftItem > xValue)
itemTextureName = itemInfo.textureName, {
fontColor1 = Color.White, numberCraftItem = xValue;
mainColor = Color.Gray, }
fontName1 = "Fonts\\Font3" }
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayButtonsList.Add(temp);
buttonIndex++; if (numberCraftItem > 0)
{
var temp = new ItemDisplayButton(Manager)
{
rectangle = new Rectangle(
width / 2 - (height / 16 + (int)(width / 2.5)) / 2 + height / 20 + width / 5,
height / 2 - (int)(height / 1.5) / 2 + height / 80 +
(height / 20 + height / 80) * (buttonIndex),
(int)(width / 5), (int)(height / 20)),
text1 = item.Key,
scale1 = 0.4f,
count = numberCraftItem,
itemTextureName = itemInfo.textureName,
fontColor1 = Color.White,
mainColor = Color.Gray,
fontName1 = "Fonts\\Font4",
discriptions1 = itemInfo.description,
resourcesNeededToCraft1 = itemInfo.resourcesNeededToCraft
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayButtonsList.Add(temp);
temp.LeftButtonPressed += () =>
{
AppManager.Instance.playerData.CraftItem(item.Key);
AppManager.Instance.SetGUI(new BaseGUI());
};
buttonIndex++;
}
}
}
catch
{
} }
} }
@ -123,5 +169,19 @@ public class BaseGUI : AbstractGUI
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
base.Update(gameTime); base.Update(gameTime);
foreach (var item in ItemDisplayButtonsList)
{
if (item.Update(gameTime))
{
AppManager.Instance.SetGUI(new BaseGUI());
}
}
foreach (var item in ItemDisplayLabelsList)
{
if (item.Update(gameTime))
{
AppManager.Instance.SetGUI(new BaseGUI());
}
}
} }
} }

View file

@ -12,6 +12,7 @@ using ZoFo.GameCore.GameManagers.ItemManager;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
using static System.Collections.Specialized.BitVector32; using static System.Collections.Specialized.BitVector32;
using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Base;
using ZoFo.GameCore.GameManagers.AssetsManager;
using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameObjects;
namespace ZoFo.GameCore.GameManagers namespace ZoFo.GameCore.GameManagers
@ -40,6 +41,7 @@ namespace ZoFo.GameCore.GameManagers
public ItemManager.ItemManager ItemManager; public ItemManager.ItemManager ItemManager;
public SettingsManager SettingsManager; public SettingsManager SettingsManager;
public SoundManager SoundManager; public SoundManager SoundManager;
public AssetManager AssetManager;
public AnimationBuilder animationBuilder { get; set; } public AnimationBuilder animationBuilder { get; set; }
@ -56,6 +58,7 @@ namespace ZoFo.GameCore.GameManagers
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
server = new Server();
playerData = new PlayerData(); playerData = new PlayerData();
ItemManager = new ItemManager.ItemManager(); ItemManager = new ItemManager.ItemManager();
Instance = this; Instance = this;
@ -63,6 +66,7 @@ namespace ZoFo.GameCore.GameManagers
SettingsManager = new SettingsManager(); SettingsManager = new SettingsManager();
SettingsManager.LoadSettings(); SettingsManager.LoadSettings();
SoundManager = new SoundManager(); SoundManager = new SoundManager();
AssetManager = new AssetManager();
SoundManager.LoadSounds(); SoundManager.LoadSounds();
@ -101,7 +105,7 @@ namespace ZoFo.GameCore.GameManagers
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
{ {
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape)) { server.CloseConnection(); Exit(); } Keyboard.GetState().IsKeyDown(Keys.Escape)) { server?.CloseConnection(); Exit(); }
// debugHud.Set("key", "value"); // debugHud.Set("key", "value");

View file

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace ZoFo.GameCore.GameManagers.AssetsManager;
public class AssetContainer
{
public List<string> Animations;
public string IdleAnimation;
}

View file

@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace ZoFo.GameCore.GameManagers.AssetsManager;
public class AssetManager
{
public AssetContainer Zombie = new()
{
Animations = ["zombie_damaged", "zombie_walk", "zombie_idle", "zombie_attack", "zombie_death"],
IdleAnimation = "zombie_walk"
};
public AssetContainer Player = new()
{
Animations = [ "player_look_down" ],
IdleAnimation = "player_look_down"
};
}

View file

@ -30,9 +30,10 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
/// <summary> /// <summary>
/// минимальный накоп изменения перед перевдижением /// минимальный накоп изменения перед перевдижением
/// </summary> /// </summary>
const float minimalValueToChange = 4; const float minimalValueToChange = 0;
public void CheckComponentCollision(CollisionComponent componentOfEntity) public void CheckComponentCollision(CollisionComponent componentOfEntity)
{ {
//ADD CHECKSPEED TODO
var entity = componentOfEntity.gameObject as LivingEntity; var entity = componentOfEntity.gameObject as LivingEntity;
//for (int i = 0; i < ObjectsWithCollisions.Count; i++) //for (int i = 0; i < ObjectsWithCollisions.Count; i++)
//{ //{
@ -74,7 +75,8 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
} }
else else
{ {
entity.position.X += entity.velocity.X; //update player position entity.position.X += (int)entity.velocity.X; //update player position
//entity.position.X = (float)Math.Round(entity.position.X, 2);
newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК newRect.X = tryingRectX.X;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
} }
@ -112,7 +114,8 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
} }
else else
{ {
entity.position.Y += entity.velocity.Y; entity.position.Y += (int)entity.velocity.Y;
//entity.position.Y = (float)Math.Round(entity.position.Y, 2);
newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК newRect.Y = tryingRectY.Y;//значение по X для нового РЕК приравниваем к значению испытуемого РЕК
} }
entity.velocity.Y = 0; entity.velocity.Y = 0;

View file

@ -14,16 +14,18 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
public string textureName; public string textureName;
Texture2D itemTexture; Texture2D itemTexture;
public bool isCraftable; public bool isCraftable;
public string description;
public Dictionary<string, int> resourcesNeededToCraft; public Dictionary<string, int> resourcesNeededToCraft;
public ItemInfo (string tag) public ItemInfo (string tag)
{ {
this.tag = tag; this.tag = tag;
} }
public ItemInfo(string tag,string textureName,bool isCraftable, Dictionary<string, int> resourcesNeededToCraft) public ItemInfo(string tag, string description, string textureName, bool isCraftable, Dictionary<string, int> resourcesNeededToCraft)
{ {
this.tag = tag; this.tag = tag;
this.textureName = textureName; this.textureName = textureName;
this.description = description;
this.isCraftable = isCraftable; this.isCraftable = isCraftable;
this.resourcesNeededToCraft = resourcesNeededToCraft; this.resourcesNeededToCraft = resourcesNeededToCraft;
} }

View file

@ -25,13 +25,13 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
public void Initialize() public void Initialize()
{ {
tagItemPairs = new Dictionary<string, ItemInfo>(); tagItemPairs = new Dictionary<string, ItemInfo>();
tagItemPairs.Add("wood", new ItemInfo("wood","Textures\\Test\\wood",false,null)); tagItemPairs.Add("wood", new ItemInfo("wood", "бревна кусок", "Textures\\Test\\wood",false,null));
tagItemPairs.Add("rock", new ItemInfo("rock", "Textures\\Test\\rock", false, null)); tagItemPairs.Add("rock", new ItemInfo("rock", "пять галек", "Textures\\Test\\rock", false, null));
tagItemPairs.Add("steel", new ItemInfo("steel", "Textures\\Test\\steel", false, null)); tagItemPairs.Add("steel", new ItemInfo("steel", "метал, метал, \nжелезо, метал", "Textures\\Test\\steel", false, null));
tagItemPairs.Add("pickaxe", new ItemInfo("steel", "Textures\\Test\\pickaxe", true, new Dictionary<string, int>() tagItemPairs.Add("pickaxe", new ItemInfo("steel", "прямой путь к \nстановлению каменьщиком", "Textures\\Test\\pickaxe", true, new Dictionary<string, int>()
{ {
{"wood", 2}, {"wood", 2},
{"Steel", 3} {"steel", 3}
})); }));
} }

View file

@ -35,14 +35,24 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
{ {
items[item.Key] -= item.Value; items[item.Key] -= item.Value;
} }
if (items.Keys.Contains(itemTag))
{
items[itemTag] += 1;
}
else
{
items.Add(itemTag, 1);
}
return true; return true;
} }
public void LoadPlayerData() public void LoadPlayerData()
{ {
//TODO //TODO
items = new Dictionary<string, int>(); items = new Dictionary<string, int>();
items.Add("wood", 2); items.Add("wood", 5);
items.Add("steel", 110); items.Add("steel", 110);
items.Add("rock", 6); items.Add("rock", 6);
} }

View file

@ -85,7 +85,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
var databytes = Encoding.UTF8.GetBytes(data); var databytes = Encoding.UTF8.GetBytes(data);
foreach (Socket socket in clients) foreach (Socket socket in clients)
{ {
clients[0].SendAsync(databytes, SocketFlags.Partial); clients[0].SendAsync(databytes);
} }
for (int i = 0; i < 200 && i< datasToSend.Count; i++) for (int i = 0; i < 200 && i< datasToSend.Count; i++)
updates.RemoveAt(0); updates.RemoveAt(0);

View file

@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects.Entities namespace ZoFo.GameCore.GameObjects
{ {
internal class EntittyForAnimationTests : Entity internal class EntittyForAnimationTests : Entity
{ {

View file

@ -6,14 +6,14 @@ using Microsoft.Xna.Framework.Graphics;
using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.CollisionManager;
namespace ZoFo.GameCore.GameObjects.Entities namespace ZoFo.GameCore.GameObjects
{ {
public abstract class Entity : GameObject public abstract class Entity : GameObject
{ {
//public override GraphicsComponent graphicsComponent => null; //public override GraphicsComponent graphicsComponent => null;
public CollisionComponent collisionComponent { get; protected set; } public CollisionComponent collisionComponent { get; protected set; }
public int Id { get; set; } public int Id { get; set; }
static int totalEntitiesCreated = 0; static int totalEntitiesCreated = 1;
protected Entity(Vector2 position) : base(position) protected Entity(Vector2 position) : base(position)
{ {
Id = totalEntitiesCreated; Id = totalEntitiesCreated;

View file

@ -11,7 +11,7 @@ using ZoFo.GameCore.Graphics;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables namespace ZoFo.GameCore.GameObjects
{ {
class Ammo:Collectable class Ammo:Collectable
{ {

View file

@ -4,7 +4,7 @@ using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; namespace ZoFo.GameCore.GameObjects;
public class Collectable : Interactable public class Collectable : Interactable
{ {
protected static readonly string _path = "Textures/icons/Collectables/"; protected static readonly string _path = "Textures/icons/Collectables/";

View file

@ -5,7 +5,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects.Entities.Interactables; namespace ZoFo.GameCore.GameObjects;
public class Interactable : Entity public class Interactable : Entity
{ {

View file

@ -5,7 +5,7 @@ using System.Reflection;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies; namespace ZoFo.GameCore.GameObjects;
public class Enemy : LivingEntity public class Enemy : LivingEntity
{ {
protected float speed; protected float speed;

View file

@ -1,24 +1,37 @@
using Microsoft.Xna.Framework; using Microsoft.VisualBasic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.GameManagers.AssetsManager;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies namespace ZoFo.GameCore.GameObjects
{ {
class Zombie : Enemy class Zombie : Enemy
{ {
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "zombie_damaged", "zombie_walk", "zombie_idle", "zombie_attack", "zombie_death" }, "zombie_walk"); public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "zombie_damaged", "zombie_walk", "zombie_idle", "zombie_attack", "zombie_death" }, "zombie_walk");
public bool isAttacking;
public Zombie(Vector2 position) : base(position) public Zombie(Vector2 position) : base(position)
{ {
health = 5; health = 5;
speed = 2; speed = 0.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;
StartAnimation("zombie_walk"); StartAnimation("zombie_walk");
collisionComponent.isTrigger = true;
collisionComponent.hasCollision = true;
(graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += EndAttack;
collisionComponent.OnTriggerZone += OnPlayerClose;
collisionComponent.triggerRectangle = new Rectangle(-5, -5, 40, 40);
} }
public override void Update() public override void Update()
@ -26,18 +39,39 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies
Vector2 duration = Vector2.Normalize( Vector2 duration = Vector2.Normalize(
AppManager.Instance.server.players[0].position - position AppManager.Instance.server.players[0].position - position
); );
velocity += new Vector2(duration.X * speed, duration.Y * speed);
if (Random.Shared.NextDouble() > 0.9)
if (!isAttacking) { velocity += new Vector2(duration.X * speed, duration.Y * speed); }
}
public void OnPlayerClose(GameObject sender)
{
if(!isAttacking)
{ {
StartAnimation("zombie_attack");
StartAnimation("zombie_walk"); isAttacking = true;
} }
if (Random.Shared.NextDouble() > 0.9)
{
//StartAnimation("zombie_idle");
}
public void EndAttack(string a)
{
var damagedPlayers=AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position));
//TODO ДАМАЖИТЬ ИГРОКОВ В ЗОНЕ
if (damagedPlayers.Length>0) { DebugHUD.DebugLog("End of" + a);
AppManager.Instance.server.DeleteObject(this);
} }
isAttacking = false;
}
public override void Draw(SpriteBatch spriteBatch)
{
DrawDebugRectangle(spriteBatch, collisionComponent.triggerRectangle.SetOrigin(position), Color.Blue);
base.Draw(spriteBatch);
} }
} }
} }

View file

@ -6,7 +6,7 @@ using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities; namespace ZoFo.GameCore.GameObjects;
public class LivingEntity : Entity public class LivingEntity : Entity
{ {
/// <summary> /// <summary>

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player namespace ZoFo.GameCore.GameObjects
{ {
class LootData class LootData
{ {

View file

@ -4,12 +4,13 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.AssetsManager;
using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.CollisionManager;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; namespace ZoFo.GameCore.GameObjects;
public class Player : LivingEntity public class Player : LivingEntity
{ {
@ -21,14 +22,14 @@ public class Player : LivingEntity
//public bool IsTryingToShoot { get; set; } //public bool IsTryingToShoot { get; set; }
private float speed; private float speed;
private int health; private int health;
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "player_look_down" }, "player_look_down"); public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(AppManager.Instance.AssetManager.Player);
private LootData lootData; private LootData lootData;
//public bool isTryingToInteract { get; set; } //public bool isTryingToInteract { get; set; }
public Player(Vector2 position) : base(position) public Player(Vector2 position) : base(position)
{ {
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10); collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10);
speed = 10; speed = 5;
//isTryingToInteract = false; //isTryingToInteract = false;
//IsTryingToShoot = false; //IsTryingToShoot = false;
@ -43,7 +44,7 @@ public class Player : LivingEntity
} }
public void MovementLogic() public void MovementLogic()
{ {
velocity = InputPlayerRotation * speed; velocity += InputPlayerRotation * speed;
} }
public void HandleNewInput(UpdateInput updateInput) public void HandleNewInput(UpdateInput updateInput)
{ {

View file

@ -10,7 +10,7 @@ using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.Graphics; using ZoFo.GameCore.Graphics;
namespace ZoFo.GameCore.GameObjects.MapObjects namespace ZoFo.GameCore.GameObjects
{ {
public class MapObject : GameObject public class MapObject : GameObject
{ {
@ -34,6 +34,25 @@ namespace ZoFo.GameCore.GameObjects.MapObjects
(graphicsComponent as StaticGraphicsComponent).LoadContent(); (graphicsComponent as StaticGraphicsComponent).LoadContent();
this.sourceRectangle = sourceRectangle; this.sourceRectangle = sourceRectangle;
}
/// <summary>
/// Конструктор для объектов с карты с анимациями, REDO
/// </summary>
/// <param name="position"></param>
/// <param name="size"></param>
/// <param name="sourceRectangle"></param>
/// <param name="textureName"></param>
/// <param name="sourceRectangles"></param>
/// <param name="frameSize"></param>
public MapObject(Vector2 position, Vector2 size, Rectangle sourceRectangle, string textureName, Rectangle sourceRectangles, int frameSize) : base(position)
{
//graphicsComponent for source
(graphicsComponent as StaticGraphicsComponent)._textureName = textureName;
(graphicsComponent as StaticGraphicsComponent).BuildComponent(textureName);
(graphicsComponent as StaticGraphicsComponent).ObjectDrawRectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
(graphicsComponent as StaticGraphicsComponent).LoadContent();
this.sourceRectangle = sourceRectangle;
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {

View file

@ -4,6 +4,7 @@ using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.AssetsManager;
using ZoFo.GameCore.GUI; using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.Graphics namespace ZoFo.GameCore.Graphics
@ -60,7 +61,17 @@ namespace ZoFo.GameCore.Graphics
private int interval; private int interval;
private int lastInterval; private int lastInterval;
private Rectangle sourceRectangle; private Rectangle sourceRectangle;
public AnimatedGraphicsComponent(AssetContainer asset)
{
Build(asset.Animations, asset.IdleAnimation);
}
public AnimatedGraphicsComponent(List<string> animationsId, string neitralAnimationId) public AnimatedGraphicsComponent(List<string> animationsId, string neitralAnimationId)
{
Build(animationsId, neitralAnimationId);
}
private void Build(List<string> animationsId, string neitralAnimationId)
{ {
//this._spriteBatch = _spriteBatch; //this._spriteBatch = _spriteBatch;
currentFrame = 0; currentFrame = 0;

View file

@ -16,8 +16,7 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer;
using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameObjects;
using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.GameObjects.Entities;
using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; using ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
using ZoFo.GameCore.GameObjects.MapObjects; using ZoFo.GameCore.GameObjects.MapObjects;
using ZoFo.GameCore.GameObjects.MapObjects.StopObjects; using ZoFo.GameCore.GameObjects.MapObjects.StopObjects;
@ -162,9 +161,9 @@ namespace ZoFo.GameCore
{ {
if (ticks == 3) //ОБРАБАТЫВАЕТСЯ 20 РАЗ В СЕКУНДУ if (ticks == 3) //ОБРАБАТЫВАЕТСЯ 20 РАЗ В СЕКУНДУ
{ {
foreach (var go in gameObjects) for (int i = 0; i < gameObjects.Count; i++)
{ {
go.UpdateLogic(); gameObjects[i].UpdateLogic();
} }
collisionManager.ResolvePhysics(); collisionManager.ResolvePhysics();
ticks = 0; ticks = 0;