try to move enemy

This commit is contained in:
bmvolf 2023-08-16 13:36:57 +03:00
parent 8815d65e85
commit 4925b11ab3
9 changed files with 32 additions and 21 deletions

View file

@ -22,7 +22,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
//здесь я не понял //здесь я не понял
} }
public virtual void Update(GameTime gameTime, Player player) public virtual void Update(GameTime gameTime)
{ {
if (monster_health <= 0) if (monster_health <= 0)
{ {
@ -30,7 +30,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
isAlive = false; isAlive = false;
} }
Move(gameTime, AppManager.Instance.GameManager.Player); Move(gameTime);
base.Update(gameTime); base.Update(gameTime);
} }
@ -38,6 +38,6 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
public abstract void Attack(); public abstract void Attack();
public abstract void Move(GameTime gameTime, Player player); public abstract void Move(GameTime gameTime);
} }
} }

View file

@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "FlameSkullMoveLeft", "FlameSkullMoveRight" }, "FlameSkullMoveRight"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "FlameSkullMoveLeft", "FlameSkullMoveRight" }, "FlameSkullMoveRight");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -29,7 +29,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
} }

View file

@ -23,7 +23,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "FrankMoveRight", "FrankMoveLeft" }, "FrankMoveRight");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -33,7 +33,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
/* if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20) /* if (player.Pos.X - _pos.X <= 20 || player.Pos.X - _pos.X <= -20)
{ {

View file

@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, ""); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "GhostMoveRight", "GhostMoveLeft", "GhostSpawn", "GhostAttack" }, "");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
} }

View file

@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight"); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "HunchmanMoveLeft", "HunchmanMoveRight", "HunchmanAttackLeft", "HunchmanAttackRight" }, "HunchmanMoveRight");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
} }

View file

@ -20,7 +20,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
"SlimeMoveRightBottom", "SlimeReadyJumpRightBottom", "SlimeReadyJumpRightTop", "SlimeReadyJumpLeftBottom", "SlimeReadyJumpLeftTop", "SlimeJumpRightBottom", "SlimeMoveRightBottom", "SlimeReadyJumpRightBottom", "SlimeReadyJumpRightTop", "SlimeReadyJumpLeftBottom", "SlimeReadyJumpLeftTop", "SlimeJumpRightBottom",
"SlimeJumpRightTop", "SlimeJumpLeftBottom", "SlimeJumpLeftTop" }, ""); "SlimeJumpRightTop", "SlimeJumpLeftBottom", "SlimeJumpLeftTop" }, "");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -30,7 +30,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
} }

View file

@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "SpiderMoveRight", "SpiderMoveLeft", "SpiderDown", "SpiderUp" }, ""); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "SpiderMoveRight", "SpiderMoveLeft", "SpiderDown", "SpiderUp" }, "");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
} }

View file

@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, ""); protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "WolfMoveRight", "WolfMoveLeft", "WolfJumpRight", "WolfJumpLeft" }, "");
public override void Attack(Player player) public override void Attack()
{ {
} }
@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
} }

View file

@ -27,10 +27,10 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
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, Player player) public override void Update(GameTime gameTime)
{ {
Move(gameTime); Move(gameTime);
var player = AppManager.Instance.GameManager.Player;
if(Pos.X + 20 <= player.Pos.X || Pos.X - 20 >= player.Pos.X) if(Pos.X + 20 <= player.Pos.X || Pos.X - 20 >= player.Pos.X)
{ {
Attack(); Attack();
@ -61,15 +61,16 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Move(GameTime gameTime, Player player) public override void Move(GameTime gameTime)
{ {
double delta = gameTime.ElapsedGameTime.TotalSeconds; float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;
if (isGoRight) if (isGoRight)
{ {
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight") if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
{ {
GraphicsComponent.StartAnimation("ZombieMoveRight"); GraphicsComponent.StartAnimation("ZombieMoveRight");
velocity = new Vector2(monster_speed, 0); velocity = new Vector2(monster_speed, 0);
_pos = new Vector2(Pos.X + monster_speed * (delta), Pos.Y);
} }
} }
@ -79,8 +80,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
GraphicsComponent.StartAnimation("ZombieMoveLeft"); GraphicsComponent.StartAnimation("ZombieMoveLeft");
velocity = new Vector2(-monster_speed, 0); velocity = new Vector2(-monster_speed, 0);
_pos = new Vector2(Pos.X - monster_speed * (delta), Pos.Y);
} }
} }
if(Pos.X <= leftBorder)
{
isGoRight = true;
}
if(Pos.X >= rightBorder)
{
isGoRight = false;
}
} }
public void TakeDamage(int damage) public void TakeDamage(int damage)