protected bool HeroInPursueRange(HeroEntity h) => Math.Abs(h.GetRealX() - GetRealX()) <= Radius;
protected bool HeroInAttackRange(HeroEntity h) => Math.Abs(h.GetRealX() - GetRealX()) <= AttackRange;
public virtual void Update(GameTime gameTime, HeroEntity hero) { bool flag; base.Update(gameTime, out flag); if (!flag || this.Destroyed || HealthPoints <= 0) { return; } Vector2 vector; switch (this.BehaviorType) { case MonsterBehaviorType.Patrol: if (HeroInAttackRange(hero)) { if (hero.GetRealX() < GetRealX()) { Effects = SpriteEffects.FlipHorizontally; } if (hero.GetRealX() > GetRealX()) { Effects = SpriteEffects.None; } //if (!hero.IsInvincible) Attack(gameTime, hero); return; } var dir = Direction; if (GetRealX() >= Right) { Direction = MovementDirection.Left; } if (GetRealX() <= Left) { Direction = MovementDirection.Right; } Move(gameTime, hero); if (Direction != dir) { ShouldDraw = false; _frameCount = 0; } break; case MonsterBehaviorType.Pursue: if (HeroInAttackRange(hero)) { if (hero.GetRealX() < GetRealX()) { Effects = SpriteEffects.FlipHorizontally; } if (hero.GetRealX() > GetRealX()) { Effects = SpriteEffects.None; } //if (!hero.IsInvincible) Attack(gameTime, hero); return; } else if (HeroInPursueRange(hero)) { if (hero.GetRealX() < GetRealX()) { Direction = MovementDirection.Left; } if (hero.GetRealX() > GetRealX()) { Direction = MovementDirection.Right; } } else { if (GetRealX() >= Right) { Direction = MovementDirection.Left; } if (GetRealX() <= Left) { Direction = MovementDirection.Right; } } if (GetRealX() <= Right && Direction == MovementDirection.Right) { Move(gameTime, hero); } else if (GetRealX() >= Left && Direction == MovementDirection.Left) { Move(gameTime, hero); } else if ( (GetRealX() <= Left && Direction == MovementDirection.Left) //Can't go left but needs to || (GetRealX() >= Right && Direction == MovementDirection.Right) //Can't go right but needs to ) { WaitForHero(gameTime); } break; } if (Direction == MovementDirection.Left) { Effects = SpriteEffects.FlipHorizontally; } else { Effects = SpriteEffects.None; } }