From 8e464223de39a308f9ca0695583f5d6fc6661c9a Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Thu, 17 Aug 2023 16:24:35 +0300 Subject: [PATCH 1/4] FrankB --- .../LivingEntities/Monsters/FrankBalls.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs index a235c3b..6ae475d 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs @@ -29,7 +29,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters name = "FrankBalls"; Width = 40; Height = 40; - monster_speed = 3; + monster_speed = 2; acceleration = Vector2.Zero; } @@ -37,17 +37,27 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Update(GameTime gameTime) { - if(!isAttacking) + collision = new Rectangle((int)position.X, (int)position.Y, 40, 40); + + if (!isAttacking) { Move(gameTime); } + if(GraphicsComponent.GetCurrentAnimation == "FrankMoveRight") + { + isFlyRight = true; + } + else if(GraphicsComponent.GetCurrentAnimation == "FrankMoveLeft") + { + isFlyRight = false; + } + base.Update(gameTime); } public override void Attack() { - collision = new Rectangle((int)position.X, (int)position.Y, 40, 40); isAttacking = true; if(isFlyRight) From 89ae5551029696023b722449a701b2f900aae349 Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Fri, 18 Aug 2023 00:31:46 +0300 Subject: [PATCH 2/4] Huchman_1 --- .../AnimationsFileCreator.csproj | 3 +- AnimationsFileCreator/Program.cs | 8 --- DangerousD/Content/map.tmx | 59 +++++++++++++++++++ DangerousD/GameCore/GameObjects/GameObject.cs | 7 +++ .../LivingEntities/Monsters/Frank.cs | 6 +- .../LivingEntities/Monsters/FrankBalls.cs | 45 ++++++++------ .../LivingEntities/Monsters/Hunchman.cs | 12 ++++ DangerousD/GameCore/Managers/AppManager.cs | 2 +- DangerousD/GameCore/Managers/GameManager.cs | 1 + DangerousD/GameCore/Managers/MapManager.cs | 2 +- .../GameCore/Managers/PhysicsManager.cs | 4 ++ 11 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 DangerousD/Content/map.tmx diff --git a/AnimationsFileCreator/AnimationsFileCreator.csproj b/AnimationsFileCreator/AnimationsFileCreator.csproj index 9e982a1..296b0a7 100644 --- a/AnimationsFileCreator/AnimationsFileCreator.csproj +++ b/AnimationsFileCreator/AnimationsFileCreator.csproj @@ -2,8 +2,7 @@ Exe - net6.0-windows - true + net6.0 diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index 9a712a0..1fc3f13 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -2,7 +2,6 @@ using Microsoft.Xna.Framework; using Newtonsoft.Json; using System; -using System.Windows.Forms; using System.IO; using System.Linq; using System.Reflection.Metadata; @@ -17,13 +16,6 @@ namespace AnimationsFileCreator Console.WriteLine("Добро пожаловать в костыльную программу по созданию файлов анимации для игры DungerousD"); Console.Write("Введите название текстуры (нажмите enter, чтобы выбрать файл во всплывающем окошке): "); string textureName = Console.ReadLine(); - if (textureName == "") - { - OpenFileDialog dialog = new OpenFileDialog(); - dialog.ShowDialog(); - textureName = dialog.FileName.Split('\\').Last(); - textureName = textureName.Split('.')[0]; - } Console.WriteLine("Введите количество кадров анимации: "); int framesCount = int.Parse(Console.ReadLine()); Console.WriteLine("Введите длительность кадра в анимации: "); diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx new file mode 100644 index 0000000..b6b3b95 --- /dev/null +++ b/DangerousD/Content/map.tmx @@ -0,0 +1,59 @@ + + + + + + +294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +294,294,294,294,294,294,294,294,294,294,294,294,294,294,294,294 + + +294,294,294,294,294,321,321,321,321,321,321,321,321,321,321,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,321,321,321,321,321,321,321,321,321,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,321, +294,294,294,294,321,321,321,321,321,321,321,321,321,321,321,321 + + + + + + + + + + + + + + + + + + + diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index ae5cd2c..777e096 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -36,6 +36,12 @@ namespace DangerousD.GameCore { } + protected int obsticles = 0; + public virtual void OnCollisionWithObsticle(GameObject gameObject) + { + obsticles++;//SD + } + public virtual void Initialize() { } @@ -47,6 +53,7 @@ namespace DangerousD.GameCore public virtual void Update(GameTime gameTime) { + obsticles = 0; GraphicsComponent.Update(); } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs index b67dd12..27ab55f 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Frank.cs @@ -20,13 +20,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters get { return position; } } - public Frank(Vector2 position) : base(position) + public Frank(Vector2 position) : base(new Vector2(300, 200)) { - this.position = position; + //position = new Vector2(300, 200); Width = 112; Height = 160; GraphicsComponent.StartAnimation("FrankMoveLeft"); - monster_speed = 1; + monster_speed = 3; name = "Frank"; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight"); diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs index 6ae475d..0538c4b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/FrankBalls.cs @@ -7,37 +7,37 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using DangerousD.GameCore.GameObjects.MapObjects; namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class FrankBalls : CoreEnemy { private Rectangle collision; - private Vector2 position; - private int healthBall; private bool isFlyRight = true; private bool isAttacking = false; - public Rectangle Collision { get { return collision; } } - public FrankBalls(Vector2 position) : base(position) + public FrankBalls(Vector2 position) : base(new Vector2(300, 200)) { - this.position = position; + name = "FrankBalls"; Width = 40; Height = 40; monster_speed = 2; + monster_health = 13; acceleration = Vector2.Zero; + velocity = new Vector2(monster_speed, monster_speed); } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "BallMoveRight" }, "BallMoveRight"); public override void Update(GameTime gameTime) { - collision = new Rectangle((int)position.X, (int)position.Y, 40, 40); + collision = new Rectangle((int)_pos.X, (int)_pos.Y, 40, 40); if (!isAttacking) { @@ -53,6 +53,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters isFlyRight = false; } + var foundObj = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)_pos.X-1, (int)_pos.Y-1, Width+2, Height+2), typeof(StopTile)); + + if (foundObj != null && foundObj.Count > 0) + { + + float av = foundObj.Sum(x => x.Rectangle.X)/foundObj.Count; + float avy = foundObj.Sum(x => x.Rectangle.Y)/foundObj.Count; + + if (avy <= _pos.Y) + velocity.Y = monster_speed; + else if (avy >= _pos.Y) + velocity.Y = -monster_speed; + if (av <= _pos.X) + velocity.X = -monster_speed; + else if (av >= _pos.X) + velocity.X = monster_speed; + monster_health--; + } + base.Update(gameTime); } @@ -78,19 +97,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { - velocity.X = 0; - velocity.Y = 0; - - if(isFlyRight) - { - velocity.X += monster_speed; - velocity.Y += monster_speed; - } - else if(!isFlyRight) - { - velocity.X -= monster_speed; - velocity.Y -= monster_speed; - } + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs index cc6ecd5..7d3e939 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs @@ -12,8 +12,16 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Hunchman : CoreEnemy { + private bool isGoRight = true; + public Hunchman(Vector2 position) : base(position) { + Width = 20; + Height = 30; + name = "Hunchman"; + GraphicsComponent.StartAnimation(""); + monster_speed = 3; + } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight"); @@ -30,7 +38,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { + var player = AppManager.Instance.GameManager.players[0]; + if(player.Pos.X > 0) + { + } } } } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index f800998..0993679 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -166,7 +166,7 @@ namespace DangerousD.GameCore case GameState.Lobby: break; case GameState.Game: - GameManager.mapManager.LoadLevel("lvl"); + GameManager.mapManager.LoadLevel("map"); break; case GameState.GameOver: break; diff --git a/DangerousD/GameCore/Managers/GameManager.cs b/DangerousD/GameCore/Managers/GameManager.cs index f2ce8c8..caae816 100644 --- a/DangerousD/GameCore/Managers/GameManager.cs +++ b/DangerousD/GameCore/Managers/GameManager.cs @@ -46,6 +46,7 @@ namespace DangerousD.GameCore internal void Register(GameObject gameObject) { + GetAllGameObjects.Add(gameObject); if (gameObject is Player) { livingEntities.Add(gameObject as LivingEntity); diff --git a/DangerousD/GameCore/Managers/MapManager.cs b/DangerousD/GameCore/Managers/MapManager.cs index 36a0f6b..593383c 100644 --- a/DangerousD/GameCore/Managers/MapManager.cs +++ b/DangerousD/GameCore/Managers/MapManager.cs @@ -63,7 +63,7 @@ namespace DangerousD.GameCore.Managers { if (tiles[i] != 0) { - Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale, + Vector2 pos = new(((chunkX+ i % chunkW) * tileSize.X + offsetX) * _scale + 400, ((chunkY + i / chunkW) * tileSize.Y + offsetY) * _scale); //pos *= _scale; Rectangle sourceRect = new(new Point((tiles[i] -1) % _columns, (tiles[i] -1) / _columns) * tileSize.ToPoint(), tileSize.ToPoint()); diff --git a/DangerousD/GameCore/Managers/PhysicsManager.cs b/DangerousD/GameCore/Managers/PhysicsManager.cs index 28ecf14..edaad38 100644 --- a/DangerousD/GameCore/Managers/PhysicsManager.cs +++ b/DangerousD/GameCore/Managers/PhysicsManager.cs @@ -97,6 +97,10 @@ namespace DangerousD.GameCore.Managers if (!isYNormalise) currentEntity.velocity.Y = 0; currentEntity.SetPosition(new Vector2(oldRect.X, oldRect.Y)); + if (!isXNormalise || !isYNormalise) + { + currentEntity.OnCollisionWithObsticle(mapObjects[i]); + } } } From 323932e945718f615ef0a8a775aaf38af3d187c2 Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Fri, 18 Aug 2023 13:54:31 +0300 Subject: [PATCH 3/4] Prepare for Merge --- .../Content/animations/HunchmanMoveLeft.crash | 1 + .../animations/HunchmanMoveRight.crash | 1 + DangerousD/Content/map.tmx | 6 +- DangerousD/DangerousD.sln | 25 ++++ .../LivingEntities/Monsters/Hunchman.cs | 115 ++++++++++++++++-- .../LivingEntities/Monsters/HunchmanDagger.cs | 28 ++++- .../GameCore/Graphics/GraphicsComponent.cs | 2 +- 7 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 DangerousD/Content/animations/HunchmanMoveLeft.crash create mode 100644 DangerousD/Content/animations/HunchmanMoveRight.crash create mode 100644 DangerousD/DangerousD.sln diff --git a/DangerousD/Content/animations/HunchmanMoveLeft.crash b/DangerousD/Content/animations/HunchmanMoveLeft.crash new file mode 100644 index 0000000..d924010 --- /dev/null +++ b/DangerousD/Content/animations/HunchmanMoveLeft.crash @@ -0,0 +1 @@ +{"id":"HunchmanMoveLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":124,"Width":24,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanMoveRight.crash b/DangerousD/Content/animations/HunchmanMoveRight.crash new file mode 100644 index 0000000..0fc3798 --- /dev/null +++ b/DangerousD/Content/animations/HunchmanMoveRight.crash @@ -0,0 +1 @@ +{"id":"HunchmanMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":100,"Width":24,"Height":23},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx index b6b3b95..ec7c203 100644 --- a/DangerousD/Content/map.tmx +++ b/DangerousD/Content/map.tmx @@ -42,7 +42,7 @@ - + @@ -51,8 +51,8 @@ - - + + diff --git a/DangerousD/DangerousD.sln b/DangerousD/DangerousD.sln new file mode 100644 index 0000000..29f2a38 --- /dev/null +++ b/DangerousD/DangerousD.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 25.0.1705.7 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DangerousD", "DangerousD.csproj", "{A51FB3C2-D16C-42DF-B65A-6EC67AF07506}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A51FB3C2-D16C-42DF-B65A-6EC67AF07506}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F6C9C555-FA45-4C6A-BEB3-8352B2653CB0} + EndGlobalSection +EndGlobal diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs index 7d3e939..7ac5e02 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs @@ -4,45 +4,144 @@ using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Security.Authentication.ExtendedProtection; using System.Text; using System.Threading.Tasks; +using DangerousD.GameCore.Managers; namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Hunchman : CoreEnemy { - private bool isGoRight = true; + private bool isGoRight = false; + private bool isAttaking = false; + private bool isTarget = false; + private bool isVisible = true; + float leftBoarder; + float rightBoarder; + PhysicsManager physicsManager; public Hunchman(Vector2 position) : base(position) { Width = 20; Height = 30; + leftBoarder = (int)position.X - 100; + rightBoarder = (int)position.X + 100; name = "Hunchman"; - GraphicsComponent.StartAnimation(""); + GraphicsComponent.StartAnimation("HunchmanMoveLeft"); monster_speed = 3; - + physicsManager = new PhysicsManager(); } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight"); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List + { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanDaggerLeft", "HunchmanDaggerRight" }, "HunchmanMoveLeft"); + + + public override void Update(GameTime gameTime) + { + if (!isAttaking) + { + Target(); + Move(gameTime); + } + base.Update(gameTime); + } public override void Attack() { + var animation = GraphicsComponent.GetCurrentAnimation; + isAttaking = true; + if (isGoRight) + { + if (animation != "HunchmanDaggerRight") + { + GraphicsComponent.StartAnimation("HunchmanDaggerRight"); + } + } + else + { + if (animation != "HunchmanDaggerLeft") + { + GraphicsComponent.StartAnimation("HunchmanDaggerLeft"); + } + } } public override void Death() { - + if (monster_health <= 0) + { + isVisible = false; + } } public override void Move(GameTime gameTime) { - var player = AppManager.Instance.GameManager.players[0]; - if(player.Pos.X > 0) + velocity.X = 0; + var animation = GraphicsComponent.GetCurrentAnimation; + if (isGoRight) { + if (animation != "HunchmanMoveRight") + { + GraphicsComponent.StartAnimation("HunchmanMoveRight"); + } + velocity.X = monster_speed; + } + else + { + if (animation != "HunchmanMoveLeft") + { + GraphicsComponent.StartAnimation("HunchmanMoveLeft"); + } + velocity.X = -monster_speed; + } + if (_pos.X >= rightBoarder) + { + isGoRight = false; + } + else if (_pos.X <= leftBoarder) + { + isGoRight = true; } } + + public override void OnCollision(GameObject gameObject) + { + if (gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + } + } + + base.OnCollision(gameObject); + } + + public void Target() + { + var player = AppManager.Instance.GameManager.players[0]; + + if (physicsManager.RayCast(this, player) == null) + { + if(this._pos.X <= player.Pos.X) + { + isTarget = true; + leftBoarder = Pos.X - 10; + rightBoarder = player.Pos.X; + } + else if(this._pos.X >= player.Pos.X) + { + isTarget = true; + rightBoarder = Pos.X + 10; + leftBoarder = player.Pos.X; + } + } + } + } -} +} \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs index 9e616ed..9a83189 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs @@ -12,10 +12,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class HunchmanDagger : CoreEnemy { + private bool isGoRight = false; + public HunchmanDagger(Vector2 position) : base(position) { name = "Hunchman"; - monster_speed = 1; + monster_speed = 4; Width = 9; Height = 6; } @@ -34,7 +36,31 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { + velocity.X = 0; + var animation = GraphicsComponent.GetCurrentAnimation; + if (animation == "HunchmanDaggerRight") + { + velocity.X = monster_speed; + } + else if (animation == "HunchmanDaggerLeft") + { + velocity.X = -monster_speed; + } + } + + public override void OnCollision(GameObject gameObject) + { + if (gameObject is Player) + { + AppManager.Instance.GameManager.players[0].Death(name); + } + else + { + Death(); + } + + base.OnCollision(gameObject); } } } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index beb6928..54b87f1 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -204,7 +204,7 @@ namespace DangerousD.GameCore.Graphics private void SetInterval() { - Tuple i = currentAnimation.FrameTime.Find(x => x.Item1 == currentFrame); + Tuple i = currentAnimation.FrameTime.Find(x => x.Item1 == currentFrame); if (i != null) { interval = i.Item2; From 33331e83ee597b3526b34630898da600ef5b14b8 Mon Sep 17 00:00:00 2001 From: MARKPRO44 <119742977+MARKPRO4444@users.noreply.github.com> Date: Fri, 18 Aug 2023 18:14:01 +0300 Subject: [PATCH 4/4] Hunchman --- DangerousD/Content/lvl.tmx | 2 +- .../LivingEntities/Monsters/Hunchman.cs | 38 +++++-------------- .../LivingEntities/Monsters/HunchmanDagger.cs | 31 ++++++++++----- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/DangerousD/Content/lvl.tmx b/DangerousD/Content/lvl.tmx index 5fcea6a..e03bd77 100644 --- a/DangerousD/Content/lvl.tmx +++ b/DangerousD/Content/lvl.tmx @@ -700,7 +700,7 @@ - + diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs index 1ca0b17..9ba700b 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs @@ -36,7 +36,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } protected override GraphicsComponent GraphicsComponent { get; } = new(new List - { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanDaggerLeft", "HunchmanDaggerRight" }, "HunchmanMoveLeft"); + { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveLeft"); public override void Update(GameTime gameTime) @@ -56,17 +56,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters isAttaking = true; if (isGoRight) { - if (animation != "HunchmanDaggerRight") + if (animation != "HunchmanAttackRight") { - GraphicsComponent.StartAnimation("HunchmanDaggerRight"); + GraphicsComponent.StartAnimation("HunchmanAttackRight"); } + HunchmanDagger hunchmanDagger = new HunchmanDagger(Pos,isGoRight); } else { - if (animation != "HunchmanDaggerLeft") + if (animation != "HunchmanAttackLeft") { - GraphicsComponent.StartAnimation("HunchmanDaggerLeft"); + GraphicsComponent.StartAnimation("HunchmanAttackLeft"); } + HunchmanDagger hunchmanDagger = new HunchmanDagger(Pos, isGoRight); } } @@ -117,18 +119,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } } - public override void OnCollision(GameObject gameObject) - { - if (gameObject is Player) - { - if (AppManager.Instance.GameManager.players[0].IsAlive) - { - Attack(); - } - } - - base.OnCollision(gameObject); - } + public void Target() { @@ -136,18 +127,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters if (physicsManager.RayCast(this, player) == null) { - if(this._pos.X <= player.Pos.X) - { - isTarget = true; - leftBoarder = Pos.X - 10; - rightBoarder = player.Pos.X; - } - else if(this._pos.X >= player.Pos.X) - { - isTarget = true; - rightBoarder = Pos.X + 10; - leftBoarder = player.Pos.X; - } + Attack(); } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs index 9699ad6..11cfe8a 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/HunchmanDagger.cs @@ -14,8 +14,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { private bool isGoRight = false; - public HunchmanDagger(Vector2 position) : base(position) + public HunchmanDagger(Vector2 position, bool isGoRight) : base(position) { + this.isGoRight = isGoRight; name = "Hunchman"; monster_speed = 4; Width = 9; @@ -36,22 +37,36 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Death() { - + AppManager.Instance.GameManager.Remove(this); } public override void Move(GameTime gameTime) { velocity.X = 0; - var animation = GraphicsComponent.GetCurrentAnimation; - - if (animation == "HunchmanDaggerRight") + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle(0, 0, 0, 0)); + if (isGoRight) { + StartCicycleAnimation("HunchmanDaggerRight"); velocity.X = monster_speed; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y, Width+5, Height)); + if(getCols.Count>0) + { + Death(); + } } - else if (animation == "HunchmanDaggerLeft") + + else if (!isGoRight) { + StartCicycleAnimation("HunchmanDaggerLeft"); velocity.X = -monster_speed; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X-5, (int)Pos.Y, Width + 5, Height)); + if (getCols.Count > 0) + { + Death(); + } } + + } public override void OnCollision(GameObject gameObject) @@ -60,10 +75,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { AppManager.Instance.GameManager.players[0].Death(name); } - else - { - Death(); - } base.OnCollision(gameObject); }