From 72638e36662240c2804b636508d9d7b9df80a710 Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 15 Aug 2024 00:38:01 +0300 Subject: [PATCH 1/8] Init_gameObj --- ZoFo/Game1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZoFo/Game1.cs b/ZoFo/Game1.cs index 3c35539..28c0ee4 100644 --- a/ZoFo/Game1.cs +++ b/ZoFo/Game1.cs @@ -27,7 +27,7 @@ public class Game1 : Game { _spriteBatch = new SpriteBatch(GraphicsDevice); - // TODO: use this.Content to load your game content here + // TODO: use this.Content to load your game content here } protected override void Update(GameTime gameTime) From 2b52b10a7215059c445795e8548e3db4cbc4fafd Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 15 Aug 2024 00:57:39 +0300 Subject: [PATCH 2/8] AddFiles --- ZoFo/GameCore/GameObjects/Bullet.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Collectable.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Enemy.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Entity.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/LivingEntity.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Player.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Projectile.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Rock.cs | 8 ++++++++ 8 files changed, 64 insertions(+) create mode 100644 ZoFo/GameCore/GameObjects/Bullet.cs create mode 100644 ZoFo/GameCore/GameObjects/Collectable.cs create mode 100644 ZoFo/GameCore/GameObjects/Enemy.cs create mode 100644 ZoFo/GameCore/GameObjects/Entity.cs create mode 100644 ZoFo/GameCore/GameObjects/LivingEntity.cs create mode 100644 ZoFo/GameCore/GameObjects/Player.cs create mode 100644 ZoFo/GameCore/GameObjects/Projectile.cs create mode 100644 ZoFo/GameCore/GameObjects/Rock.cs diff --git a/ZoFo/GameCore/GameObjects/Bullet.cs b/ZoFo/GameCore/GameObjects/Bullet.cs new file mode 100644 index 0000000..46520c4 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Bullet.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Bullet : Projectile +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Collectable.cs b/ZoFo/GameCore/GameObjects/Collectable.cs new file mode 100644 index 0000000..77af5a4 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Collectable.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Collectable : Entity +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Enemy.cs b/ZoFo/GameCore/GameObjects/Enemy.cs new file mode 100644 index 0000000..cfae853 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Enemy.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Enemy : LivingEntity +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Entity.cs b/ZoFo/GameCore/GameObjects/Entity.cs new file mode 100644 index 0000000..03124ac --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Entity.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Entity +{ + +} diff --git a/ZoFo/GameCore/GameObjects/LivingEntity.cs b/ZoFo/GameCore/GameObjects/LivingEntity.cs new file mode 100644 index 0000000..92f1b1c --- /dev/null +++ b/ZoFo/GameCore/GameObjects/LivingEntity.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class LivingEntity : Entity +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Player.cs b/ZoFo/GameCore/GameObjects/Player.cs new file mode 100644 index 0000000..1842b56 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Player.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Player : LivingEntity +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Projectile.cs b/ZoFo/GameCore/GameObjects/Projectile.cs new file mode 100644 index 0000000..4760e92 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Projectile.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Projectile : LivingEntity +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Rock.cs b/ZoFo/GameCore/GameObjects/Rock.cs new file mode 100644 index 0000000..aa60b17 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Rock.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo; + +public class Rock : Projectile +{ + +} From c2d070cd8de769e7ce1e1438d820a6325ee0fab9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Aug 2024 01:07:51 +0300 Subject: [PATCH 3/8] 2element --- ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs | 12 ++++++++++++ ZoFo/GameCore/GameObjects/LootData.cs | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs create mode 100644 ZoFo/GameCore/GameObjects/LootData.cs diff --git a/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs b/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs new file mode 100644 index 0000000..30c945e --- /dev/null +++ b/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameObjects +{ + internal interface IPlayerWeaponAttack + { + } +} diff --git a/ZoFo/GameCore/GameObjects/LootData.cs b/ZoFo/GameCore/GameObjects/LootData.cs new file mode 100644 index 0000000..162c725 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/LootData.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameObjects +{ + internal class LootData + { + public void AddLoot(object lootObject, int quantity) + { + + } + } +} From 4e9c54906b4e94fd04c6408cee1da9e420640456 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Aug 2024 01:27:00 +0300 Subject: [PATCH 4/8] addClassesFromIPlayer --- ZoFo/GameCore/GameObjects/GunAttack.cs | 13 +++++++++++++ ZoFo/GameCore/GameObjects/HandAttack.cs | 13 +++++++++++++ ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs | 1 + ZoFo/GameCore/GameObjects/LootData.cs | 1 + ZoFo/GameCore/GameObjects/SwordAttack.cs | 13 +++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 ZoFo/GameCore/GameObjects/GunAttack.cs create mode 100644 ZoFo/GameCore/GameObjects/HandAttack.cs create mode 100644 ZoFo/GameCore/GameObjects/SwordAttack.cs diff --git a/ZoFo/GameCore/GameObjects/GunAttack.cs b/ZoFo/GameCore/GameObjects/GunAttack.cs new file mode 100644 index 0000000..b3a611e --- /dev/null +++ b/ZoFo/GameCore/GameObjects/GunAttack.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameObjects +{ + internal class GunAttack:IPlayerWeaponAttack + { + + } +} diff --git a/ZoFo/GameCore/GameObjects/HandAttack.cs b/ZoFo/GameCore/GameObjects/HandAttack.cs new file mode 100644 index 0000000..3d73249 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/HandAttack.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameObjects +{ + internal class HandAttack:IPlayerWeaponAttack + { + + } +} diff --git a/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs b/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs index 30c945e..f47220e 100644 --- a/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs +++ b/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs @@ -8,5 +8,6 @@ namespace ZoFo.GameCore.GameObjects { internal interface IPlayerWeaponAttack { + } } diff --git a/ZoFo/GameCore/GameObjects/LootData.cs b/ZoFo/GameCore/GameObjects/LootData.cs index 162c725..93f67f1 100644 --- a/ZoFo/GameCore/GameObjects/LootData.cs +++ b/ZoFo/GameCore/GameObjects/LootData.cs @@ -8,6 +8,7 @@ namespace ZoFo.GameCore.GameObjects { internal class LootData { + public Dictionary loots; public void AddLoot(object lootObject, int quantity) { diff --git a/ZoFo/GameCore/GameObjects/SwordAttack.cs b/ZoFo/GameCore/GameObjects/SwordAttack.cs new file mode 100644 index 0000000..507ae6b --- /dev/null +++ b/ZoFo/GameCore/GameObjects/SwordAttack.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameObjects +{ + internal class SwordAttack:IPlayerWeaponAttack + { + + } +} From 1f54391527394fc4f6282fbc9a990ca717d0597a Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 15 Aug 2024 01:47:12 +0300 Subject: [PATCH 5/8] add abstract logic of entity --- ZoFo/GameCore/GameObjects/Bullet.cs | 3 +-- ZoFo/GameCore/GameObjects/Collectable.cs | 3 +-- ZoFo/GameCore/GameObjects/Enemy.cs | 9 +++++--- ZoFo/GameCore/GameObjects/Entity.cs | 26 ++++++++++++++++++++--- ZoFo/GameCore/GameObjects/LivingEntity.cs | 3 +-- ZoFo/GameCore/GameObjects/Player.cs | 3 +-- ZoFo/GameCore/GameObjects/Projectile.cs | 3 +-- ZoFo/GameCore/GameObjects/Rock.cs | 3 +-- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/ZoFo/GameCore/GameObjects/Bullet.cs b/ZoFo/GameCore/GameObjects/Bullet.cs index 46520c4..4e2197d 100644 --- a/ZoFo/GameCore/GameObjects/Bullet.cs +++ b/ZoFo/GameCore/GameObjects/Bullet.cs @@ -1,7 +1,6 @@ using System; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class Bullet : Projectile { diff --git a/ZoFo/GameCore/GameObjects/Collectable.cs b/ZoFo/GameCore/GameObjects/Collectable.cs index 77af5a4..7a32b43 100644 --- a/ZoFo/GameCore/GameObjects/Collectable.cs +++ b/ZoFo/GameCore/GameObjects/Collectable.cs @@ -1,7 +1,6 @@ using System; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class Collectable : Entity { diff --git a/ZoFo/GameCore/GameObjects/Enemy.cs b/ZoFo/GameCore/GameObjects/Enemy.cs index cfae853..934da77 100644 --- a/ZoFo/GameCore/GameObjects/Enemy.cs +++ b/ZoFo/GameCore/GameObjects/Enemy.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; +using System.Net.Mime; +using System.Reflection; +using Microsoft.Xna.Framework.Content; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class Enemy : LivingEntity { -} +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/Entity.cs b/ZoFo/GameCore/GameObjects/Entity.cs index 03124ac..936b18d 100644 --- a/ZoFo/GameCore/GameObjects/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entity.cs @@ -1,8 +1,28 @@ using System; +using ZoFo.GameCore.GameObjects; -namespace ZoFo; - -public class Entity +namespace ZoFo.GameCore.GameObjects; +public class Entity : GameObject { + public int Id{ get; set; } + //public CollisionComponent collisionComponents{ get; set; } + //public AnimationComponent animationComponent{ get; set; } + // в апдейте может заявляет изменения позиции + public void UpdateLogic() + { + + } + + + + // Методы для клиента + public void UpdateAnimation() + { + + } + public void Draw(ContentManager manager) + { + + } } diff --git a/ZoFo/GameCore/GameObjects/LivingEntity.cs b/ZoFo/GameCore/GameObjects/LivingEntity.cs index 92f1b1c..44270fa 100644 --- a/ZoFo/GameCore/GameObjects/LivingEntity.cs +++ b/ZoFo/GameCore/GameObjects/LivingEntity.cs @@ -1,7 +1,6 @@ using System; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class LivingEntity : Entity { diff --git a/ZoFo/GameCore/GameObjects/Player.cs b/ZoFo/GameCore/GameObjects/Player.cs index 1842b56..5a033e3 100644 --- a/ZoFo/GameCore/GameObjects/Player.cs +++ b/ZoFo/GameCore/GameObjects/Player.cs @@ -1,7 +1,6 @@ using System; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class Player : LivingEntity { diff --git a/ZoFo/GameCore/GameObjects/Projectile.cs b/ZoFo/GameCore/GameObjects/Projectile.cs index 4760e92..80cbf5a 100644 --- a/ZoFo/GameCore/GameObjects/Projectile.cs +++ b/ZoFo/GameCore/GameObjects/Projectile.cs @@ -1,7 +1,6 @@ using System; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class Projectile : LivingEntity { diff --git a/ZoFo/GameCore/GameObjects/Rock.cs b/ZoFo/GameCore/GameObjects/Rock.cs index aa60b17..1ff7a29 100644 --- a/ZoFo/GameCore/GameObjects/Rock.cs +++ b/ZoFo/GameCore/GameObjects/Rock.cs @@ -1,7 +1,6 @@ using System; -namespace ZoFo; - +namespace ZoFo.GameCore.GameObjects; public class Rock : Projectile { From 09dff14367f0c7d81e22d50d3dc28eaefc08a3ab Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 15 Aug 2024 02:05:36 +0300 Subject: [PATCH 6/8] fix bags in entity and add ZoFo_grafics with bag --- ZoFo/GameCore/GameObjects/Entity.cs | 1 + .../GameCore/ZoFo_grafics/AnimationBuilder.cs | 30 ++ .../ZoFo_grafics/AnimationContainer.cs | 33 +++ .../ZoFo_grafics/GraphicsComponent.cs | 277 ++++++++++++++++++ 4 files changed, 341 insertions(+) create mode 100644 ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs create mode 100644 ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs create mode 100644 ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs diff --git a/ZoFo/GameCore/GameObjects/Entity.cs b/ZoFo/GameCore/GameObjects/Entity.cs index 936b18d..0600b1d 100644 --- a/ZoFo/GameCore/GameObjects/Entity.cs +++ b/ZoFo/GameCore/GameObjects/Entity.cs @@ -1,5 +1,6 @@ using System; using ZoFo.GameCore.GameObjects; +using Microsoft.Xna.Framework.Content; namespace ZoFo.GameCore.GameObjects; public class Entity : GameObject diff --git a/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs b/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs new file mode 100644 index 0000000..ec544c7 --- /dev/null +++ b/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs @@ -0,0 +1,30 @@ +/*using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using Newtonsoft.Json; + +namespace DangerousD.GameCore.Graphics +{ + public class AnimationBuilder + { + public List Animations { get; private set; } + public void LoadAnimations() + { + Animations = new List(); + string[] animationFilesNames = Directory.GetFiles("../../../Content/animations"); + + StreamReader reader; + foreach (var fileName in animationFilesNames) + { + reader = new StreamReader(fileName); + string json = reader.ReadToEnd(); + AnimationContainer animation = JsonConvert.DeserializeObject(json); + Animations.Add(animation); + reader.Close(); + } + + } + } +} +*/ \ No newline at end of file diff --git a/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs b/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs new file mode 100644 index 0000000..ee9df51 --- /dev/null +++ b/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs @@ -0,0 +1,33 @@ +/*using Microsoft.Xna.Framework; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace DangerousD.GameCore.Graphics +{ + [Serializable] + public class AnimationContainer + { + [JsonProperty("id")] + public string Id { get; set; } + [JsonProperty("textureName")] + public string TextureName { get; set; } + [JsonProperty("startSpriteRectangle")] + public Rectangle StartSpriteRectangle { get; set; } + [JsonProperty("frameSecond")] + public List> FrameTime { get; set; } + [JsonProperty("textureFrameInterval")] + public int TextureFrameInterval { get; set; } + [JsonProperty("framesCount")] + public int FramesCount { get; set; } + [JsonProperty("isCycle")] + public bool IsCycle { get; set; } + [JsonProperty("offset")] + public Vector2 Offset { get; set; } + + + + } +} +*/ \ No newline at end of file diff --git a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs new file mode 100644 index 0000000..96e50d4 --- /dev/null +++ b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs @@ -0,0 +1,277 @@ +/*using ZoFo.GameCore.GameObjects; +using ZoFo.GameCore.Managers; +using ZoFo.GameCore.Network; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; + +namespace DangerousD.GameCore.Graphics +{ + + public class GraphicsComponent + { + public event Action actionOfAnimationEnd; + private List animations; + private List textures; + private List texturesNames; + private AnimationContainer currentAnimation; + static public int scaling = 4; + public int parentId; + public AnimationContainer CurrentAnimation + { + get + { + return currentAnimation; + } + } + public string LastAnimation { get; set; } + public string GetCurrentAnimation + { + get { return currentAnimation.Id; } + } + + private AnimationContainer neitralAnimation; + //private SpriteBatch _spriteBatch; + + private int currentFrame; + public int CurrentFrame + { + get + { + return currentFrame; + } + } + private int interval; + private int lastInterval; + private Rectangle sourceRectangle; + public GraphicsComponent(List animationsId, string neitralAnimationId) + { + //this._spriteBatch = _spriteBatch; + currentFrame = 0; + lastInterval = 1; + LoadAnimations(animationsId, neitralAnimationId); + currentAnimation = neitralAnimation; + SetInterval(); + buildSourceRectangle(); + } + + public GraphicsComponent(string textureName) + { + animations = new List(); + textures = new List(); + var texture = AppManager.Instance.Content.Load(textureName); + textures.Add(texture); + AnimationContainer animationContainer = new AnimationContainer(); + animationContainer.StartSpriteRectangle = new Rectangle(0, 0, texture.Width, texture.Height); + animationContainer.TextureFrameInterval = 0; + animationContainer.TextureName = texture.Name; + animationContainer.IsCycle = true; + animationContainer.FramesCount = 1; + animationContainer.FrameTime = new List>() { new Tuple(0, 10) }; + animationContainer.Id = texture.Name; + currentAnimation = animationContainer; + neitralAnimation = animationContainer; + animations.Add(animationContainer); + } + + private void LoadAnimations(List animationsId, string neitralAnimationId) + { + animations = new List(); + foreach (var id in animationsId) + { + animations.Add(AppManager.Instance.AnimationBuilder.Animations.Find(x => x.Id == id)); + if (id == neitralAnimationId) + { + neitralAnimation = animations.Last(); + } + } + } + + public void LoadContent() + { + textures = new List(); + texturesNames = new List(); + + foreach (var animation in animations) + { + if (!texturesNames.Contains(animation.TextureName)) + { + texturesNames.Add(animation.TextureName); + textures.Add(AppManager.Instance.Content.Load(animation.TextureName)); + } + } + } + + public void StartAnimation(string startedanimationId) + { + if (AppManager.Instance.multiPlayerStatus != MultiPlayerStatus.SinglePlayer) + { + LivingEntity entity = AppManager.Instance.GameManager.livingEntities.Find(x => x.id == parentId); + if (((entity is Player) || AppManager.Instance.multiPlayerStatus == MultiPlayerStatus.Host) && startedanimationId != GetCurrentAnimation) + { + AppManager.Instance.NetworkTasks.Add(new NetworkTask(parentId, startedanimationId, Vector2.Zero)); + } + } + currentFrame = 0; + currentAnimation = animations.Find(x => x.Id == startedanimationId); + + buildSourceRectangle(); + SetInterval(); + } + + public void StopAnimation() + { + currentFrame = 0; + interval = 0; + currentAnimation = neitralAnimation; + buildSourceRectangle(); + SetInterval(); + } + + public void Update() + { + if (interval == 0) + { + currentFrame++; + if (currentAnimation.FramesCount <= currentFrame) + { + if (!currentAnimation.IsCycle) + { + if (actionOfAnimationEnd != null) + { + actionOfAnimationEnd(currentAnimation.Id); + } + currentAnimation = neitralAnimation; + + } + + currentFrame = 0; + + } + + buildSourceRectangle(); + SetInterval(); + } + + interval--; + } + + public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch) + { + Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; + float scale; + if (currentAnimation.Offset.X != 0) + { + destinationRectangle.X -= (int)currentAnimation.Offset.X; + scale = destinationRectangle.Height / sourceRectangle.Height; + destinationRectangle.Width = (int)(sourceRectangle.Width * scale); + + } + else if (currentAnimation.Offset.Y != 0) + { + destinationRectangle.Y -= (int)currentAnimation.Offset.Y; + scale = destinationRectangle.Width / sourceRectangle.Width; + destinationRectangle.Height = (int)(sourceRectangle.Height * scale); + } + + destinationRectangle.X -= CameraPosition.X; + destinationRectangle.Y -= CameraPosition.Y; + + destinationRectangle = Scaling(destinationRectangle); + _spriteBatch.Draw(texture, + destinationRectangle, sourceRectangle, Color.White); + } + public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle) + { + Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)]; + float scale; + if (currentAnimation.Offset.X != 0) + { + destinationRectangle.X -= (int)currentAnimation.Offset.X; + scale = destinationRectangle.Height / sourceRectangle.Height; + destinationRectangle.Width = (int)(sourceRectangle.Width * scale); + + } + else if (currentAnimation.Offset.Y != 0) + { + destinationRectangle.Y -= (int)currentAnimation.Offset.Y; + scale = destinationRectangle.Width / sourceRectangle.Width; + destinationRectangle.Height = (int)(sourceRectangle.Height * scale); + } + + destinationRectangle.X -= CameraPosition.X; + destinationRectangle.Y -= CameraPosition.Y; + + destinationRectangle = Scaling(destinationRectangle); + _spriteBatch.Draw(texture, + destinationRectangle, sourceRectangle, Color.White); + } + private Rectangle Scaling(Rectangle destinationRectangle) + { + destinationRectangle.X *= scaling; + destinationRectangle.Y *= scaling; + destinationRectangle.Width *= scaling; + destinationRectangle.Height *= scaling; + return destinationRectangle; + } + private void buildSourceRectangle() + { + sourceRectangle = new Rectangle(); + if (currentAnimation == null) + { + currentAnimation = neitralAnimation; + } + sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame * + (currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval); + sourceRectangle.Y = currentAnimation.StartSpriteRectangle.Y; + sourceRectangle.Height = currentAnimation.StartSpriteRectangle.Height; + sourceRectangle.Width = currentAnimation.StartSpriteRectangle.Width; + } + + private void SetInterval() + { + Tuple i = currentAnimation.FrameTime.Find(x => x.Item1 == currentFrame); + if (i != null) + { + interval = i.Item2; + lastInterval = interval; + } + else + { + interval = lastInterval; + } + } + public static void SetCameraPosition(Vector2 playerPosition) + { + CameraPosition = (playerPosition).ToPoint(); + CameraPosition.X -= 200; + CameraPosition.Y -= 120; + + if (CameraPosition.X > AppManager.Instance.GameManager.CameraBorder.Y - 460) + { + CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.Y - 460; + } + + if (CameraPosition.Y < AppManager.Instance.GameManager.CameraBorder.Z) + { + CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.Z; + } + if (CameraPosition.X < AppManager.Instance.GameManager.CameraBorder.X) + { + CameraPosition.X = (int)AppManager.Instance.GameManager.CameraBorder.X; + } + if (CameraPosition.Y > AppManager.Instance.GameManager.CameraBorder.W - 240) + { + CameraPosition.Y = (int)AppManager.Instance.GameManager.CameraBorder.W - 240; + } + AppManager.Instance.DebugHUD.Set("CameraPosition", $"{CameraPosition.X}, {CameraPosition.Y}"); + } + public static Point CameraPosition = new Point(-700, 300); + } +} +*/ \ No newline at end of file From 6593b9c1d6855a25cf5811befe94443add2601f2 Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 15 Aug 2024 10:06:58 +0300 Subject: [PATCH 7/8] add tile and stopTile and partlially done the ZoFo_grafics --- Install-Package | 0 ZoFo/GameCore/GameObjects/StopObject.cs | 8 ++++++++ ZoFo/GameCore/GameObjects/Tile.cs | 8 ++++++++ ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs | 4 ++-- .../GameCore/ZoFo_grafics/AnimationContainer.cs | 5 ++--- ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs | 10 +++++----- ZoFo/ZoFo.csproj | 17 +++++++++-------- 7 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 Install-Package create mode 100644 ZoFo/GameCore/GameObjects/StopObject.cs create mode 100644 ZoFo/GameCore/GameObjects/Tile.cs diff --git a/Install-Package b/Install-Package new file mode 100644 index 0000000..e69de29 diff --git a/ZoFo/GameCore/GameObjects/StopObject.cs b/ZoFo/GameCore/GameObjects/StopObject.cs new file mode 100644 index 0000000..cddb0d5 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/StopObject.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo.GameCore.GameObjects; + +public class StopObject +{ + +} diff --git a/ZoFo/GameCore/GameObjects/Tile.cs b/ZoFo/GameCore/GameObjects/Tile.cs new file mode 100644 index 0000000..16cc1c9 --- /dev/null +++ b/ZoFo/GameCore/GameObjects/Tile.cs @@ -0,0 +1,8 @@ +using System; + +namespace ZoFo.GameCore.GameObjects; + +public class Tile +{ + +} diff --git a/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs b/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs index ec544c7..d18303c 100644 --- a/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs +++ b/ZoFo/GameCore/ZoFo_grafics/AnimationBuilder.cs @@ -1,8 +1,9 @@ -/*using System; +using System; using System.Collections.Generic; using System.Text; using System.IO; using Newtonsoft.Json; +using Zofo.GameCore.ZoFo_grafics; namespace DangerousD.GameCore.Graphics { @@ -27,4 +28,3 @@ namespace DangerousD.GameCore.Graphics } } } -*/ \ No newline at end of file diff --git a/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs b/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs index ee9df51..36596d0 100644 --- a/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs +++ b/ZoFo/GameCore/ZoFo_grafics/AnimationContainer.cs @@ -1,10 +1,10 @@ -/*using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; -namespace DangerousD.GameCore.Graphics +namespace Zofo.GameCore.ZoFo_grafics { [Serializable] public class AnimationContainer @@ -30,4 +30,3 @@ namespace DangerousD.GameCore.Graphics } } -*/ \ No newline at end of file diff --git a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs index 96e50d4..d3e65b2 100644 --- a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs +++ b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs @@ -1,6 +1,6 @@ -/*using ZoFo.GameCore.GameObjects; -using ZoFo.GameCore.Managers; -using ZoFo.GameCore.Network; +using ZoFo.GameCore.GameObjects; +using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.NetworkManager; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -9,8 +9,9 @@ using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; +using Zofo.GameCore.ZoFo_grafics; -namespace DangerousD.GameCore.Graphics +namespace ZoFo.GameCore.ZoFo_graphics { public class GraphicsComponent @@ -274,4 +275,3 @@ namespace DangerousD.GameCore.Graphics public static Point CameraPosition = new Point(-700, 300); } } -*/ \ No newline at end of file diff --git a/ZoFo/ZoFo.csproj b/ZoFo/ZoFo.csproj index a216165..928cf03 100644 --- a/ZoFo/ZoFo.csproj +++ b/ZoFo/ZoFo.csproj @@ -11,19 +11,20 @@ Icon.ico - - + + - - + + - - + + + - - + + \ No newline at end of file From c751d8fdd8f4fe68e29ebb34943f5dba20cad226 Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 15 Aug 2024 10:27:02 +0300 Subject: [PATCH 8/8] minor changes GraficsComponent --- ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs index d3e65b2..6a3572b 100644 --- a/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs +++ b/ZoFo/GameCore/ZoFo_grafics/GraphicsComponent.cs @@ -1,4 +1,4 @@ -using ZoFo.GameCore.GameObjects; +/*using ZoFo.GameCore.GameObjects; using ZoFo.GameCore.GameManagers; using ZoFo.GameCore.GameManagers.NetworkManager; using Microsoft.Xna.Framework; @@ -275,3 +275,4 @@ namespace ZoFo.GameCore.ZoFo_graphics public static Point CameraPosition = new Point(-700, 300); } } +*/ \ No newline at end of file