From b9d259bfa0d00ad141d16a0a2a10e40004d96209 Mon Sep 17 00:00:00 2001 From: polten0 Date: Thu, 17 Aug 2023 13:05:16 +0300 Subject: [PATCH] fixesAdnSomeHunchManAdditions --- .../LivingEntities/Monsters/Hunchman.cs | 73 ++++++++++++++++--- .../LivingEntities/Monsters/Knife.cs | 19 +++++ DangerousD/GameCore/Levels/Level1.cs | 11 +-- 3 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Knife.cs diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Hunchman.cs index f180842..be5563b 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,51 +14,104 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { public class Hunchman : CoreEnemy { + GameManager gameManager; + bool isAttacking; public Hunchman(Vector2 position) : base(position) { - Width = 72; - Height = 72; - monster_speed = 5; + 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"); + { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveLeft"); public override void Update(GameTime gameTime) { - Move(gameTime); + gameManager = AppManager.Instance.GameManager; + + if (!isAttacking) + { + Attack(); + Move(gameTime); + + } + Death(); base.Update(gameTime); + } 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; + 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) { + 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("HunchmanMoveRight"); + { + GraphicsComponent.StartAnimation("HunchmanMoveLeft"); + } } + } - public override void OnCollision() - { + public override void OnCollision(GameObject gameObject) + { monster_speed *= -1; + _pos.X += 5 * monster_speed; + Debug.WriteLine("Collision"); } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Knife.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Knife.cs new file mode 100644 index 0000000..cba749d --- /dev/null +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Knife.cs @@ -0,0 +1,19 @@ +using DangerousD.GameCore.Graphics; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters +{ + class Knife : Entity + { + public Knife(Vector2 position) : base(position) + { + } + + protected override GraphicsComponent GraphicsComponent => throw new NotImplementedException(); + } +} diff --git a/DangerousD/GameCore/Levels/Level1.cs b/DangerousD/GameCore/Levels/Level1.cs index 1b4fb03..8295e68 100644 --- a/DangerousD/GameCore/Levels/Level1.cs +++ b/DangerousD/GameCore/Levels/Level1.cs @@ -10,17 +10,12 @@ namespace DangerousD.GameCore.Levels { public void InitLevel() { - new Player(new Vector2(0,0)); + new Player(new Vector2(50,100)); var Zombie = new Zombie(new Vector2(140, 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)); - var Werewolf = new Werewolf(new Vector2(640, 0)); - var Ghost = new Ghost(new Vector2(730, 0)); - var FrankBalls = new FrankBalls(new Vector2(Frank.Pos.X, Frank.Pos.Y)); - var HunchMan = new Hunchman(new Vector2(100, 100)); + + var HunchMan = new Hunchman(new Vector2(300, 100)); //Spider down-up new GrassBlock(new Vector2(0, 224));