From 1ed1dd635f7147b56573a377bf23502c4efcdb5b Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Fri, 18 Aug 2023 17:42:26 +0300 Subject: [PATCH] GhostAdding --- DangerousD/Content/animations/GhostAttack | 2 +- DangerousD/Content/map.tmx | 2 +- .../LivingEntities/Monsters/Ghost.cs | 57 +++++++++++++++---- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/DangerousD/Content/animations/GhostAttack b/DangerousD/Content/animations/GhostAttack index 7ada2dc..8425c93 100644 --- a/DangerousD/Content/animations/GhostAttack +++ b/DangerousD/Content/animations/GhostAttack @@ -1 +1 @@ -{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":2,"isCycle":false,"offset":"0, 0"} +{"id":"GhostAttack","textureName":"MonstersAnimations","startSpriteRectangle":{"X":101,"Y":503,"Width":24,"Height":31},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":50,"framesCount":2,"isCycle":false,"offset":"0, 0"} diff --git a/DangerousD/Content/map.tmx b/DangerousD/Content/map.tmx index bcc7b83..a02975a 100644 --- a/DangerousD/Content/map.tmx +++ b/DangerousD/Content/map.tmx @@ -71,7 +71,7 @@ - + diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs index 214a4c2..57ab2c4 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Ghost.cs @@ -17,11 +17,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters isGoRight = true; monster_speed = 3; name = "Ghost"; - Width = 48; - Height = 62; + Width = 24; + Height = 30; GraphicsComponent.StartAnimation("GhostSpawn"); - acceleration = Vector2.Zero; - + acceleration = new Vector2(0,1); + monster_health = 1; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, "GhostMoveRight"); @@ -38,13 +38,32 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Attack() { - + velocity.X = 0; + isAttack = true; + if (GraphicsComponent.GetCurrentAnimation != "GhostAttack") + { + GraphicsComponent.StartAnimation("GhostAttack"); + } + + AppManager.Instance.GameManager.players[0].Death(name); } public override void Death() { } + public override void OnCollision(GameObject gameObject) + { + if (gameObject is Player) + { + if (AppManager.Instance.GameManager.players[0].IsAlive) + { + Attack(); + + } + } + base.OnCollision(gameObject); + } public override void Move(GameTime gameTime) { @@ -64,17 +83,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } velocity.X = -monster_speed; } - if (Pos.X >= rightBoarder) + var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); + if (isGoRight) { - isGoRight = false; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, Width + 4, 2)); } - else if (Pos.X <= leftBoarder) + else { - isGoRight = true; + getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 3, (int)Pos.Y + Height / 2 - 2, Width + 3, 2)); } - if (true) - { + + foreach (var item in getCols) + { + if (item is MapObject) + { + isGoRight = !isGoRight; + break; + } } } @@ -82,7 +108,16 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters { } + public void TakeDamage() + { + monster_health--; + + if (monster_health <= 0) + { + Death(); + } + } public void Target() { throw new NotImplementedException();