fixed errors zombie

This commit is contained in:
bmvolf 2023-08-16 09:54:15 +03:00
parent ac1b3b6373
commit 15f0571790
5 changed files with 28 additions and 14 deletions

View file

@ -22,7 +22,7 @@ namespace DangerousD.GameCore.GameObjects
{ {
Vector2 dir = targetPosition - Pos; Vector2 dir = targetPosition - Pos;
dir.Normalize(); dir.Normalize();
Pos += dir * speed; _pos += dir * speed;
} }
base.Update(gameTime); base.Update(gameTime);
} }

View file

@ -12,7 +12,7 @@ namespace DangerousD.GameCore
{ {
public abstract class GameObject : IDrawableObject public abstract class GameObject : IDrawableObject
{ {
private Vector2 _pos; protected Vector2 _pos;
public Vector2 Pos => _pos; public Vector2 Pos => _pos;
public int Width { get; protected set; } public int Width { get; protected set; }
public int Height { get; protected set; } public int Height { get; protected set; }

View file

@ -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) if (monster_health <= 0)
{ {
Death(); Death();
isAlive = false;
} }
base.Update(gameTime); base.Update(gameTime);
} }
public abstract void Death(); public abstract void Death();
public abstract void Attack(Player player); public abstract void Attack();
public abstract void Move(GameTime gameTime); public abstract void Move(GameTime gameTime);
} }

View file

@ -13,40 +13,46 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public class Zombie : CoreEnemy public class Zombie : CoreEnemy
{ {
private bool isGoRight = true; private bool isGoRight = true;
int leftBorder;
int rightBorder;
public Zombie(Vector2 position) : base(position) public Zombie(Vector2 position) : base(position)
{ {
Width = 72; Width = 72;
Height = 120; Height = 120;
monster_speed = 100; monster_speed = 20;
GraphicsComponent.StartAnimation("ZombieLeftAttack"); GraphicsComponent.StartAnimation("ZombieLeftAttack");
name = "Zombie"; name = "Zombie";
leftBorder = (int)position.X;
rightBorder = (int)position.X + 200;
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "ZombieMoveRight", "ZombieMoveLeft", "ZombieRightAttack", "ZombieLeftAttack" }, "ZombieMoveLeft");
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime, Player player)
{ {
//Move(gameTime); Move(gameTime);
if (monster_health <= 0)
if(Pos.X + 20 <= player.Pos.X || Pos.X - 20 >= player.Pos.X)
{ {
isAlive = false; Attack();
Death(); player.Death(name);
} }
base.Update(gameTime); base.Update(gameTime);
} }
public override void Attack(Player player) public override void Attack()
{ {
if (isGoRight) if (isGoRight)
{ {
GraphicsComponent.StopAnimation(); GraphicsComponent.StopAnimation();
GraphicsComponent.StartAnimation("ZombieRightAttack"); GraphicsComponent.StartAnimation("ZombieRightAttack");
player.Death(name); AppManager.Instance.GameManager.Player.Death(name);
} }
else if (!isGoRight) else if (!isGoRight)
{ {
GraphicsComponent.StopAnimation(); GraphicsComponent.StopAnimation();
GraphicsComponent.StartAnimation("ZombieLeftAttack"); 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) public override void Move(GameTime gameTime)
{ {
double delta = gameTime.ElapsedGameTime.TotalSeconds;
if (isGoRight) if (isGoRight)
{ {
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") 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
}
} }
} }

View file

@ -23,7 +23,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public void Death(string monsterName) public void Death(string monsterName)
{ {
//анимация по имени монстра
} }
} }
} }