diff --git a/DangerousD/GameCore/GameObjects/Entity.cs b/DangerousD/GameCore/GameObjects/Entity.cs index 685ffae..6699710 100644 --- a/DangerousD/GameCore/GameObjects/Entity.cs +++ b/DangerousD/GameCore/GameObjects/Entity.cs @@ -22,7 +22,7 @@ namespace DangerousD.GameCore.GameObjects { Vector2 dir = targetPosition - Pos; dir.Normalize(); - Pos += dir * speed; + _pos += dir * speed; } base.Update(gameTime); } diff --git a/DangerousD/GameCore/GameObjects/GameObject.cs b/DangerousD/GameCore/GameObjects/GameObject.cs index 3eb584d..52c96c1 100644 --- a/DangerousD/GameCore/GameObjects/GameObject.cs +++ b/DangerousD/GameCore/GameObjects/GameObject.cs @@ -12,7 +12,7 @@ namespace DangerousD.GameCore { public abstract class GameObject : IDrawableObject { - private Vector2 _pos; + protected Vector2 _pos; public Vector2 Pos => _pos; public int Width { get; protected set; } public int Height { get; protected set; } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs b/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs index c49c08b..c5b7230 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/CoreEnemy.cs @@ -22,17 +22,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities //здесь я не понял } - public override void Update(GameTime gameTime) + public virtual void Update(GameTime gameTime, Player player) { if (monster_health <= 0) { Death(); + isAlive = false; } base.Update(gameTime); } public abstract void Death(); - public abstract void Attack(Player player); + public abstract void Attack(); public abstract void Move(GameTime gameTime); } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs index 73c4943..68e2881 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Monsters/Zombie.cs @@ -13,40 +13,46 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public class Zombie : CoreEnemy { private bool isGoRight = true; + int leftBorder; + int rightBorder; public Zombie(Vector2 position) : base(position) { Width = 72; Height = 120; - monster_speed = 100; + monster_speed = 20; GraphicsComponent.StartAnimation("ZombieLeftAttack"); name = "Zombie"; + leftBorder = (int)position.X; + rightBorder = (int)position.X + 200; } protected override GraphicsComponent GraphicsComponent { get; } = new(new List { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); - public override void Update(GameTime gameTime) + public override void Update(GameTime gameTime, Player player) { - //Move(gameTime); - if (monster_health <= 0) + Move(gameTime); + + if(Pos.X + 20 <= player.Pos.X || Pos.X - 20 >= player.Pos.X) { - isAlive = false; - Death(); + Attack(); + player.Death(name); } + base.Update(gameTime); } - public override void Attack(Player player) + public override void Attack() { if (isGoRight) { GraphicsComponent.StopAnimation(); GraphicsComponent.StartAnimation("ZombieRightAttack"); - player.Death(name); + AppManager.Instance.GameManager.Player.Death(name); } else if (!isGoRight) { GraphicsComponent.StopAnimation(); GraphicsComponent.StartAnimation("ZombieLeftAttack"); - player.Death(name); + AppManager.Instance.GameManager.Player.Death(name); } } @@ -57,6 +63,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters public override void Move(GameTime gameTime) { + double delta = gameTime.ElapsedGameTime.TotalSeconds; if (isGoRight) { if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") @@ -75,5 +82,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters } } } + + public void TakeDamage(int damage) + { + monster_health -= damage; + //play take damage animation + } } } diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs index 9683e16..dd0e96e 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player.cs @@ -23,7 +23,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities public void Death(string monsterName) { - + //анимация по имени монстра } } }