From bd25894407f92e5768edfd0bd651cd308c6acfc5 Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Sun, 18 Aug 2024 00:26:36 +0300 Subject: [PATCH] Fix --- .../Entities/EntittyForAnimationTests.cs | 2 +- .../Entities/Interactables/Collectables/Wood.cs | 2 +- .../GameObjects/Entities/Interactables/Door.cs | 2 +- .../Entities/Interactables/Interactable.cs | 2 +- .../GameCore/GameObjects/MapObjects/MapObject.cs | 2 +- .../Graphics/AnimatedGraphicsComponent.cs | 6 ++++++ ZoFo/GameCore/Graphics/IGraphicsComponent.cs | 16 ++++++++++++++++ .../GameCore/Graphics/StaticGraphicsComponent.cs | 5 +++++ 8 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 ZoFo/GameCore/Graphics/IGraphicsComponent.cs diff --git a/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs b/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs index 3ee347d..5ff1061 100644 --- a/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs +++ b/ZoFo/GameCore/GameObjects/Entities/EntittyForAnimationTests.cs @@ -12,7 +12,7 @@ namespace ZoFo.GameCore.GameObjects.Entities { //public override GraphicsComponent graphicsComponent { get; } = new GraphicsComponent(new List { "тут пишите название анимации" }, "сдублируйте " + - public override AnimatedGraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "player_running_top_rotate" }, "player_running_top_rotate"); + public override AnimatedGraphicsComponent graphicsComponent { get; } = new(new List { "player_running_top_rotate" }, "player_running_top_rotate"); public EntittyForAnimationTests(Vector2 position) : base(position) { graphicsComponent.ObjectDrawRectangle = new Rectangle(0,0,16*12, 16 * 16); diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs index b5876d4..5686918 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Collectables/Wood.cs @@ -6,7 +6,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables.Collectables; public class Wood : Collectable { - public override StaticGraphicsComponent graphicsComponent { get; } = new("Wood"); + public override AnimatedGraphicsComponent graphicsComponent { get; } = new("Wood"); public Wood(Vector2 position) : base(position) { diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs index 39b52f0..52f1eba 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Door.cs @@ -9,7 +9,7 @@ public class Door : Interactable { public bool isOpened; - public override StaticGraphicsComponent graphicsComponent { get; } = new("DoorClosed"); + public override AnimatedGraphicsComponent graphicsComponent { get; } = new("DoorClosed"); public Door(Vector2 position) : base(position) { diff --git a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs index 270b986..0004328 100644 --- a/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs +++ b/ZoFo/GameCore/GameObjects/Entities/Interactables/Interactable.cs @@ -9,7 +9,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.Interactables; public class Interactable : Entity { - public override StaticGraphicsComponent graphicsComponent => throw new System.NotImplementedException(); + public override AnimatedGraphicsComponent graphicsComponent => throw new System.NotImplementedException(); public Interactable(Vector2 position) : base(position) { diff --git a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs index da53cfa..a1f4fae 100644 --- a/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs +++ b/ZoFo/GameCore/GameObjects/MapObjects/MapObject.cs @@ -16,7 +16,7 @@ namespace ZoFo.GameCore.GameObjects.MapObjects { public virtual bool IsColliderOn { get; protected set; } = true;//Who added that? public Rectangle sourceRectangle; - public override StaticGraphicsComponent graphicsComponent { get; } = new(); + public override AnimatedGraphicsComponent graphicsComponent { get; } = new(); /// /// Создается простой объект на карте - no animations, только где, насколько крупно рисовать, по какой сорс ректанглу рисовать и из какой текстуры diff --git a/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs b/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs index b56e844..cc2f87d 100644 --- a/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs +++ b/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs @@ -4,6 +4,7 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.Graphics { @@ -202,6 +203,7 @@ namespace ZoFo.GameCore.Graphics public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch) { Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; + float scale; if (currentAnimation.Offset.X != 0) { @@ -223,10 +225,14 @@ namespace ZoFo.GameCore.Graphics destinationRectangle = Scaling(destinationRectangle); _spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White); + DebugHUD.Instance.Log(texture.Name); + } public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle) { + Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; + float scale; if (currentAnimation.Offset.X != 0) { diff --git a/ZoFo/GameCore/Graphics/IGraphicsComponent.cs b/ZoFo/GameCore/Graphics/IGraphicsComponent.cs new file mode 100644 index 0000000..50e2424 --- /dev/null +++ b/ZoFo/GameCore/Graphics/IGraphicsComponent.cs @@ -0,0 +1,16 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace ZoFo.GameCore.Graphics; + +public interface IGraphicsComponent +{ + public Rectangle ObjectDrawRectangle { get; set; } + public static int scaling = 1; + public string mainTextureName { get; set; }//TODO костыль - пофиксить + + public abstract void LoadContent(); + public abstract void Update(); + public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch); + public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle); +} \ No newline at end of file diff --git a/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs b/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs index ea28b30..5c36538 100644 --- a/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs +++ b/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs @@ -4,6 +4,7 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.Graphics { @@ -42,6 +43,8 @@ namespace ZoFo.GameCore.Graphics public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch) { + DebugHUD.Instance.Log("draw "); + destinationRectangle.X -= CameraPosition.X; destinationRectangle.Y -= CameraPosition.Y; destinationRectangle = Scaling(destinationRectangle); @@ -50,6 +53,8 @@ namespace ZoFo.GameCore.Graphics public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle) { + DebugHUD.Instance.Log("draw "); + destinationRectangle.X -= CameraPosition.X; destinationRectangle.Y -= CameraPosition.Y;