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] 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;