First animations, prepared for addition of new animations

This commit is contained in:
SergoDobro 2024-08-17 10:07:21 +03:00
parent 23ee2b79a6
commit aed8016bfd
24 changed files with 227 additions and 10 deletions

View file

@ -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<Tuple<int, int>>();
container.FrameTime.Add(new Tuple<int, int>(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();
}

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"}

View file

@ -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<MapObject> mapObjects = new List<MapObject>();
List<GameObject> gameObjects = new List<GameObject>();
/// <summary>
/// Клиент должен обнговлять игру анимаций
/// </summary>
/// <param name="gameTime"></param>
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
//);
}
}
}
}

View file

@ -81,8 +81,9 @@ namespace ZoFo.GameCore.GameManagers
_spriteBatch = new SpriteBatch(GraphicsDevice);
debugHud.LoadContent();
currentGUI.LoadContent();
animationBuilder = new AnimationBuilder();
animationBuilder.LoadAnimations();
}

View file

@ -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;
}
}

View file

@ -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<string> { "тут пишите название анимации" }, "сдублируйте " +
public override GraphicsComponent graphicsComponent { get; } = new GraphicsComponent(new List<string> { "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);
}
}
}

View file

@ -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)

View file

@ -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);

View file

@ -17,6 +17,8 @@ public class LivingEntity : Entity
inputManager = new InputManager();
}
public override GraphicsComponent graphicsComponent { get; } = null;
#region Server side
/*public override void Update()
{

View file

@ -63,8 +63,10 @@ public abstract class GameObject
/// Для клиента
/// Обновление, которое вызывается у клиента, для просмотра анимаций
/// </summary>
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();
}

View file

@ -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<GameObject>();
entities = new List<Entity>();
new MapManager().LoadMap();
AppManager.Instance.server.RegisterGameObject(new EntittyForAnimationTests(new Vector2(40, 40)));
}
/// <summary>
@ -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

View file

@ -13,11 +13,12 @@ namespace DangerousD.GameCore.Graphics
public void LoadAnimations()
{
Animations = new List<AnimationContainer>();
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<AnimationContainer>(json);

View file

@ -15,7 +15,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
public class GraphicsComponent
{
public Rectangle ObjectDrawRectangle { get; set; }
public Rectangle ObjectDrawRectangle;