diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index 68768cf..45c6a06 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -22,7 +22,8 @@ namespace AnimationsFileCreator { DialogResult result = Dialog.FileOpen(); - textureName = result.Path.Split('\\').Last(); + var temp = result.Path.Split('\\'); + textureName = temp[temp.Length-2] + "/"+temp[temp.Length - 1]; textureName = textureName.Split('.')[0]; } Console.WriteLine("Введите количество кадров анимации: "); @@ -60,11 +61,11 @@ namespace AnimationsFileCreator container.FrameTime = new System.Collections.Generic.List>(); container.FrameTime.Add(new Tuple(0, interval)); container.StartSpriteRectangle = rectangle; - container.TextureName = textureName; - container.TextureFrameInterval = 1; + container.TextureName = "Textures/AnimationTextures/"+textureName; + container.TextureFrameInterval = 0; container.Id = id; string json = JsonConvert.SerializeObject(container); - StreamWriter writer = new StreamWriter("../../../../ZoFo/Content/animations/"+id); + StreamWriter writer = new StreamWriter("../../../../ZoFo/Content/Textures/Animations/"+id+ ".animation"); writer.WriteLine(json); writer.Close(); } diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb index fd91add..15735cf 100644 --- a/ZoFo/Content/Content.mgcb +++ b/ZoFo/Content/Content.mgcb @@ -91,6 +91,90 @@ /processorParam:Quality=Best /build:sounds/Zombi stoit.wav +#begin Textures/AnimationTextures/Character/hr-level1_idle_gun.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/AnimationTextures/Character/hr-level1_idle_gun.png + +#begin Textures/AnimationTextures/Character/hr-level1_idle.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/AnimationTextures/Character/hr-level1_idle.png + +#begin Textures/AnimationTextures/Character/hr-level1_mining_tool-1.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/AnimationTextures/Character/hr-level1_mining_tool-1.png + +#begin Textures/AnimationTextures/Character/hr-level1_mining_tool-2.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/AnimationTextures/Character/hr-level1_mining_tool-2.png + +#begin Textures/AnimationTextures/Character/hr-level1_running_gun.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/AnimationTextures/Character/hr-level1_running_gun.png + +#begin Textures/AnimationTextures/Character/hr-level1_running.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/AnimationTextures/Character/hr-level1_running.png + +#begin Textures/AnimationTextures/unicorn.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/AnimationTextures/unicorn.png + #begin Textures/GUI/background/base.png /importer:TextureImporter /processor:TextureProcessor diff --git a/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_idle.png b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_idle.png new file mode 100644 index 0000000..85413ee Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_idle.png differ diff --git a/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_idle_gun.png b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_idle_gun.png new file mode 100644 index 0000000..4cb9b20 Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_idle_gun.png differ diff --git a/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_mining_tool-1.png b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_mining_tool-1.png new file mode 100644 index 0000000..8d194a4 Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_mining_tool-1.png differ diff --git a/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_mining_tool-2.png b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_mining_tool-2.png new file mode 100644 index 0000000..c3e4071 Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_mining_tool-2.png differ diff --git a/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_running.png b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_running.png new file mode 100644 index 0000000..5ceabee Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_running.png differ diff --git a/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_running_gun.png b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_running_gun.png new file mode 100644 index 0000000..488b866 Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/Character/hr-level1_running_gun.png differ diff --git a/ZoFo/Content/Textures/AnimationTextures/unicorn.png b/ZoFo/Content/Textures/AnimationTextures/unicorn.png new file mode 100644 index 0000000..3306190 Binary files /dev/null and b/ZoFo/Content/Textures/AnimationTextures/unicorn.png differ diff --git a/ZoFo/Content/Textures/Animations/player_idle_top-right_noweapon.animation b/ZoFo/Content/Textures/Animations/player_idle_top-right_noweapon.animation new file mode 100644 index 0000000..e97cfa8 --- /dev/null +++ b/ZoFo/Content/Textures/Animations/player_idle_top-right_noweapon.animation @@ -0,0 +1,20 @@ +{ + "id": "player_idle_top-right_noweapon", + "textureName": "Textures/AnimationTextures/Character/hr-level1_idle", + "startSpriteRectangle": { + "X": 0, + "Y": 116, + "Width": 92, + "Height": 116 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 5 + } + ], + "textureFrameInterval": 0, + "framesCount": 22, + "isCycle": true, + "offset": "0, 0" +} diff --git a/ZoFo/Content/Textures/Animations/player_idle_top_noweapon.animation b/ZoFo/Content/Textures/Animations/player_idle_top_noweapon.animation new file mode 100644 index 0000000..4e72f22 --- /dev/null +++ b/ZoFo/Content/Textures/Animations/player_idle_top_noweapon.animation @@ -0,0 +1,20 @@ +{ + "id": "player_idle_top_noweapon", + "textureName": "Textures/AnimationTextures/Character/hr-level1_idle", + "startSpriteRectangle": { + "X": 0, + "Y": 0, + "Width": 92, + "Height": 116 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 5 + } + ], + "textureFrameInterval": 0, + "framesCount": 22, + "isCycle": true, + "offset": "0, 0" +} diff --git a/ZoFo/Content/Textures/Animations/running_top.animation b/ZoFo/Content/Textures/Animations/running_top.animation new file mode 100644 index 0000000..5f2991c --- /dev/null +++ b/ZoFo/Content/Textures/Animations/running_top.animation @@ -0,0 +1,20 @@ +{ + "id": "running_top", + "textureName": "unicorn", + "startSpriteRectangle": { + "X": 0, + "Y": 30, + "Width": 30, + "Height": 60 + }, + "frameSecond": [ + { + "Item1": 0, + "Item2": 2 + } + ], + "textureFrameInterval": 1, + "framesCount": 22, + "isCycle": true, + "offset": "0, 0" +} diff --git a/ZoFo/Content/Textures/Animations/testAnimationExample.animation b/ZoFo/Content/Textures/Animations/testAnimationExample.animation new file mode 100644 index 0000000..de970c1 --- /dev/null +++ b/ZoFo/Content/Textures/Animations/testAnimationExample.animation @@ -0,0 +1 @@ +{"id":"testAnimationExample","textureName":"Textures/AnimationTextures/unicorn","startSpriteRectangle":{"X":0,"Y":0,"Width":400,"Height":400},"frameSecond":[{"Item1":0,"Item2":1}],"textureFrameInterval":1,"framesCount":1,"isCycle":true,"offset":"0, 0"} diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 81b4166..4bc324e 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -12,6 +12,8 @@ using ZoFo.GameCore.GameObjects.MapObjects; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects.MapObjects.Tiles; using System.Drawing; +using System.Reflection; +using ZoFo.GameCore.GameObjects.Entities; namespace ZoFo.GameCore { @@ -45,12 +47,17 @@ namespace ZoFo.GameCore List mapObjects = new List(); + List gameObjects = new List(); /// /// Клиент должен обнговлять игру анимаций /// /// internal void Update(GameTime gameTime) { + for (int i = 0; i < gameObjects.Count; i++) + { + gameObjects[i].UpdateAnimations(); + } } internal void Draw(SpriteBatch spriteBatch) { @@ -58,6 +65,10 @@ namespace ZoFo.GameCore { mapObjects[i].Draw(spriteBatch); } + for (int i = 0; i < gameObjects.Count; i++) + { + gameObjects[i].Draw(spriteBatch); + } } internal void GotData(UpdateData update) @@ -72,6 +83,22 @@ namespace ZoFo.GameCore (update as UpdateTileCreated).tileSetName )); } + else if (update is UpdateGameObjectCreated) + { + var a = Assembly.GetAssembly(typeof(GameObject)); + if ((update as UpdateGameObjectCreated).GameObjectType == "EntittyForAnimationTests") + { + + gameObjects.Add( + new EntittyForAnimationTests(new Vector2(100,100)) + ); + } + //gameObjects.Add( TODO reflection + //Activator.CreateInstance(Type.GetType("ZoFo.GameCore.GameObjects.Entities.EntittyForAnimationTests") + ///*(update as UpdateGameObjectCreated).GameObjectType*/, new []{ new Vector2(100, 100) }) + //as GameObject + //); + } } } } \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index 83f0382..afff18d 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -81,8 +81,9 @@ namespace ZoFo.GameCore.GameManagers _spriteBatch = new SpriteBatch(GraphicsDevice); debugHud.LoadContent(); currentGUI.LoadContent(); - - + animationBuilder = new AnimationBuilder(); + animationBuilder.LoadAnimations(); + } diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs index 32052a0..0ca86a4 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateGameObjectCreated.cs @@ -12,5 +12,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient public class UpdateGameObjectCreated : UpdateData { public UpdateGameObjectCreated() { UpdateType = "UpdateGameObjectCreated"; } + public string GameObjectType; + public string GameObjectId; } } diff --git a/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs b/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs new file mode 100644 index 0000000..fb545a1 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs @@ -0,0 +1,24 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZoFo.GameCore.ZoFo_graphics; + +namespace ZoFo.GameCore.GameObjects.Entities +{ + internal class EntittyForAnimationTests : Entity + { + + //public override GraphicsComponent graphicsComponent { get; } = new GraphicsComponent(new List { "тут пишите название анимации" }, "сдублируйте " + + public override GraphicsComponent graphicsComponent { get; } = new GraphicsComponent(new List { "player_idle_top-right_noweapon" }, "player_idle_top-right_noweapon"); + public EntittyForAnimationTests(Vector2 position) : base(position) + { + graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,50,50); + position = new Vector2(10, 10); + + } + + } +} diff --git a/ZoFo/GameCore/GameObjects/Entities/Entity.cs b/ZoFo/GameCore/GameObjects/Entities/Entity.cs index a9e8670..0c7d453 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Entity.cs @@ -10,7 +10,7 @@ namespace ZoFo.GameCore.GameObjects.Entities { public abstract class Entity : GameObject { - public override GraphicsComponent graphicsComponent => null; + //public override GraphicsComponent graphicsComponent => null; public CollisionComponent collisionComponent { get; protected set; } public int Id { get; set; } protected Entity(Vector2 position) : base(position) diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs index 6299155..f28d364 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs @@ -3,11 +3,14 @@ using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.CollisionManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; +using ZoFo.GameCore.ZoFo_graphics; namespace ZoFo.GameCore.GameObjects.Entities.Interactables; public class Interactable : Entity { + public override GraphicsComponent graphicsComponent => throw new System.NotImplementedException(); + public Interactable(Vector2 position) : base(position) { collisionComponent.OnTriggerEnter += (sender, e) => ChangeInteraction(sender, e, true); diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs index 1d73ead..6842723 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/LivingEntity.cs @@ -17,6 +17,8 @@ public class LivingEntity : Entity inputManager = new InputManager(); } + public override GraphicsComponent graphicsComponent { get; } = null; + #region Server side /*public override void Update() { diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/GameObject.cs index 14c306f..98ccc72 100644 --- a/ZoFo/GameCore/GameObjects/GameObject.cs +++ b/ZoFo/GameCore/GameObjects/GameObject.cs @@ -63,8 +63,10 @@ public abstract class GameObject /// Для клиента /// Обновление, которое вызывается у клиента, для просмотра анимаций /// - public virtual void UpdateAnimations(GameTime gameTime) + public virtual void UpdateAnimations() { + graphicsComponent.ObjectDrawRectangle.X = (int)position.X; //Move To place where Updates Sets your position + graphicsComponent.ObjectDrawRectangle.Y = (int)position.Y; PlayAnimation_OnClient(); } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index f844da2..f374401 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.MapManager; using ZoFo.GameCore.GameManagers.NetworkManager; using ZoFo.GameCore.GameManagers.NetworkManager.Updates; @@ -76,6 +77,8 @@ namespace ZoFo.GameCore gameObjects = new List(); entities = new List(); new MapManager().LoadMap(); + + AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(40, 40))); } /// @@ -121,7 +124,13 @@ namespace ZoFo.GameCore Size = (gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size, tileSetName = (gameObject as MapObject).graphicsComponent.mainTextureName });//TODO + return; } + + AddData(new UpdateGameObjectCreated() + { GameObjectType = gameObject.GetType().Name } + ); + } } #endregion diff --git a/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs b/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs index d18303c..04b2cbf 100644 --- a/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs +++ b/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs @@ -13,11 +13,12 @@ namespace DangerousD.GameCore.Graphics public void LoadAnimations() { Animations = new List(); - string[] animationFilesNames = Directory.GetFiles("../../../Content/animations"); + string[] animationFilesNames = Directory.GetFiles("../../../Content/Textures/Animations"); StreamReader reader; foreach (var fileName in animationFilesNames) { + if (!fileName.EndsWith(".animation")) continue; reader = new StreamReader(fileName); string json = reader.ReadToEnd(); AnimationContainer animation = JsonConvert.DeserializeObject(json); diff --git a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs index c945b77..0bb3769 100644 --- a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs +++ b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs @@ -15,7 +15,7 @@ namespace ZoFo.GameCore.ZoFo_graphics public class GraphicsComponent { - public Rectangle ObjectDrawRectangle { get; set; } + public Rectangle ObjectDrawRectangle;