diff --git a/DangerousD/Content/animations/HunchmanAttackLeft b/DangerousD/Content/animations/HunchmanAttackLeft new file mode 100644 index 0000000..f6b0634 --- /dev/null +++ b/DangerousD/Content/animations/HunchmanAttackLeft @@ -0,0 +1 @@ +{"id":"HunchmanAttackLeft","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":124,"Width":40,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":3,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanAttackRight b/DangerousD/Content/animations/HunchmanAttackRight new file mode 100644 index 0000000..482d7f3 --- /dev/null +++ b/DangerousD/Content/animations/HunchmanAttackRight @@ -0,0 +1 @@ +{"id":"HunchmanAttackRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":99,"Width":40,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":3,"isCycle":true,"offset":"0, 0"} diff --git a/DangerousD/Content/animations/HunchmanMoveLeft b/DangerousD/Content/animations/HunchmanMoveLeft new file mode 100644 index 0000000..47d627e --- /dev/null +++ b/DangerousD/Content/animations/HunchmanMoveLeft @@ -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 b/DangerousD/Content/animations/HunchmanMoveRight index 614e684..a289fa5 100644 --- a/DangerousD/Content/animations/HunchmanMoveRight +++ b/DangerousD/Content/animations/HunchmanMoveRight @@ -1 +1,3 @@ -{"id":"HunchmanMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":99,"Width":24,"Height":24},"frameSecond":[{"Item1":0,"Item2":12}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} + +{"id":"HunchmanMoveRight","textureName":"MonstersAnimations","startSpriteRectangle":{"X":1,"Y":99,"Width":24,"Height":24},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":4,"isCycle":true,"offset":"0, 0"} + diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs index cc6ecd5..ed8a92c 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs @@ -4,7 +4,9 @@ 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; @@ -12,25 +14,114 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Hunchman : CoreEnemy { + GameManager gameManager; + bool isAttacking; public Hunchman(Vector2 position) : base(position) { + Width = 48; + Height = 48; + monster_speed = -2; + monster_health = 1; + name = "HunchMan"; + velocity = new Vector2(monster_speed, 0); + gameManager = AppManager.Instance.GameManager; + isAttacking = false; + isAlive = true; } - protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight"); + protected override GraphicsComponent GraphicsComponent { get; } = new(new List + { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveLeft"); + + public override void Update(GameTime gameTime) + { + // P.S. Всё в классе можешь смело удалять и переписывать с нуля. + gameManager = AppManager.Instance.GameManager; + + if (!isAttacking) + { + Attack(); + Move(gameTime); + } + else + { + velocity.X = 0; + } + Death(); + + } public override void Attack() { - + GameObject gameObject; + foreach (var player in gameManager.players) + { + if (player.Pos.Y + player.Height >= Pos.Y && player.Pos.Y <= Pos.Y + Height) + { + gameObject = gameManager.physicsManager.RayCast(this, player); + if (gameObject is null) + { + isAttacking = true; + GraphicsComponent.StopAnimation(); + if (velocity.X > 0) + { + if (GraphicsComponent.GetCurrentAnimation != "HunchmanAttackRight") + { + GraphicsComponent.StartAnimation("HunchmanAttackRight"); + } + } + else if (velocity.X < 0) + { + if (GraphicsComponent.GetCurrentAnimation != "HunchmanAttackLeft") + { + GraphicsComponent.StartAnimation("HunchmanAttackLeft"); + } + } + } + } + } } public override void Death() { + if (monster_health <= 0) + { + } } public override void Move(GameTime gameTime) { + if (gameManager.physicsManager.RayCast(this, new Vector2(Pos.X + Width + 10, Pos.Y + Height)) is not null) + { + monster_speed *= -1; + } + + velocity.X = monster_speed; + if (velocity.X > 0) + { + if (GraphicsComponent.GetCurrentAnimation != "HunchmanMoveRight") + { + GraphicsComponent.StartAnimation("HunchmanMoveRight"); + } + + } + + else if (velocity.X < 0) + { + if (GraphicsComponent.GetCurrentAnimation != "HunchmanMoveLeft") + { + GraphicsComponent.StartAnimation("HunchmanMoveLeft"); + } + } + + } + + public override void OnCollision(GameObject gameObject) + { + monster_speed *= -1; + _pos.X += 5 * monster_speed; + Debug.WriteLine("Collision"); } } } diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs index 7a0f8d9..b8f5c14 100644 --- a/DangerousD/GameCore/Levels/Level1.cs +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -10,8 +10,10 @@ namespace DangerousD.GameCore.Levels { public void InitLevel() { + new Player(new Vector2(350,0)); var Zombie = new Zombie(new Vector2(100, 128)); + //var Frank = new Frank(new Vector2(384, 128)); //var Spider = new Spider(new Vector2(112, 0)); //var FlameSkull = new FlameSkull(new Vector2(512, 0)); @@ -20,16 +22,15 @@ namespace DangerousD.GameCore.Levels //var FrankBalls = new FrankBalls(new Vector2(Frank.Pos.X, Frank.Pos.Y)); //var SilasHand = new SilasHands(new Vector2(200,64)); //var SilasMaster = new SilasMaster(new Vector2(400, 64)); + + var HunchMan = new Hunchman(new Vector2(300, 100)); + new GrassBlock(new Vector2(0, 224)); for (int i = 0; i < 50; i++) { new GrassBlock(new Vector2(i*32, 256)); } new GrassBlock(new Vector2(500, 224)); - Player player = new Player(new Vector2(400, 64)); - player.Jump(); - - //new GrassBlock(new Vector2(500, 224)); } } }