/// <summary>
        /// Handle the behaviour of the enemy when it is following the player.
        /// </summary>
        /// <param name="context">Context of the enemy.</param>
        public void Handle(EnemyContext context)
        {
            float distanceX = (float)Math.Round(context.Player.Position.X - context.Enemy.Position.X, 0);

            // If the distance if below 0, the player is on the left
            if (distanceX < 0)
            {
                Vector3 rotation = context.Enemy.DModel.Rotation;
                context.Enemy.Rotation = new Vector3(MathHelper.ToRadians(270), rotation.Y, rotation.Z);

                if (context.Enemy.PlayerXDirection != Enemy.XDirection.Left)
                {
                    context.Enemy.LastPlayerXDirection = context.Enemy.PlayerXDirection;
                    context.Enemy.PlayerXDirection     = Enemy.XDirection.Left;
                }
                context.Enemy.Speed = new Vector2(-context.Enemy.MaxSpeed.X, context.Enemy.Speed.Y);
            }
            // If the distance if above 0, the player is on the right
            else if (distanceX > 0)
            {
                Vector3 rotation = context.Enemy.DModel.Rotation;
                context.Enemy.Rotation = new Vector3(MathHelper.ToRadians(90), rotation.Y, rotation.Z);

                if (context.Enemy.PlayerXDirection != Enemy.XDirection.Right)
                {
                    context.Enemy.LastPlayerXDirection = context.Enemy.PlayerXDirection;
                    context.Enemy.PlayerXDirection     = Enemy.XDirection.Right;
                }
                context.Enemy.Speed = new Vector2(context.Enemy.MaxSpeed.X, context.Enemy.Speed.Y);
            }
        }
Example #2
0
 /// <summary>
 /// Handle the behaviour of the enemy when it is waking up.
 /// </summary>
 /// <param name="context">Context of the enemy.</param>
 public void Handle(EnemyContext context)
 {
     if (((AnimatedModel)context.Enemy.DModel).Animation.Done == true)
     {
         context.ChangeState(Inactive.Instance);
     }
 }
 /// <summary>
 /// Handle the behaviour of the attacked enemy. When the attacked
 /// animation finish, change the behaviour of the last behaviour.
 /// </summary>
 /// <param name="context"></param>
 public void Handle(EnemyContext context)
 {
     if (((AnimatedModel)context.Enemy.DModel).Animation.Done == true)
     {
         ((AnimatedModel)context.Enemy.DModel).Damaged = false;
         context.ChangeState(context.LastState);
     }
 }
        /// <summary>
        /// Start the animation of the Following enemy.
        /// </summary>
        /// <param name="context">Context of the enemy.</param>
        public void StartAnimation(EnemyContext context)
        {
            ((AnimatedModel)context.Enemy.DModel).TimeSpeed = 0.75f;
            ((AnimatedModel)context.Enemy.DModel).Animation.StartClip("Walking", true);

            // Start a new sound when the enemy detect the player
            SoundManager.GetSound("EnemyPlayerDetected").Volume =
                GameSettings.DefaultInstance.SoundVolume;
            SoundManager.GetSound("EnemyPlayerDetected").Play(true, false);
        }
Example #5
0
 /// <summary>
 /// Handle the behaviour of the enemy when it is dying.
 /// </summary>
 /// <param name="context"></param>
 public void Handle(EnemyContext context)
 {
     // Change the current speed for disappear in the ground.
     context.Enemy.Speed = new Vector2(1f, 0f);
 }
Example #6
0
 /// <summary>
 /// Start the animation of the Dying enemy.
 /// </summary>
 /// <param name="context">Context of the enemy.</param>
 public void StartAnimation(EnemyContext context)
 {
     ((AnimatedModel)context.Enemy.DModel).TimeSpeed = 1f;
     ((AnimatedModel)context.Enemy.DModel).Animation.StartClip("Dying", false);
 }
Example #7
0
 /// <summary>
 /// Handle the behaviour of the enemy when it is attacking.
 /// </summary>
 /// <param name="context"></param>
 public void Handle(EnemyContext context)
 {
     // Change the current speed of the enemy for avoid the horizontal
     // position change.
     context.Enemy.Speed = new Vector2(0f, context.Enemy.Speed.Y);
 }
Example #8
0
 /// <summary>
 /// Start the animation of the attacking enemy.
 /// </summary>
 /// <param name="context">Context of the enemy.</param>
 public void StartAnimation(EnemyContext context)
 {
     ((AnimatedModel)context.Enemy.DModel).TimeSpeed = 5f;
     ((AnimatedModel)context.Enemy.DModel).Animation.StartClip("RepeatAttack", true);
 }
 /// <summary>
 /// Start the animation of the attacked enemy.
 /// </summary>
 /// <param name="context">Context of the enemy.</param>
 public void StartAnimation(EnemyContext context)
 {
     // Set the animation speed and play the Attacked animation.
     ((AnimatedModel)context.Enemy.DModel).TimeSpeed = 2f;
     ((AnimatedModel)context.Enemy.DModel).Animation.StartClip("Attacked", false);
 }
 /// <summary>
 /// Handle the behaviour of the enemy when it is inactive.
 /// </summary>
 /// <param name="context">Context of the enemy.</param>
 public void Handle(EnemyContext context)
 {
     context.Enemy.Speed = new Vector2(0, context.Enemy.Speed.Y);
 }
 /// <summary>
 /// Start the animation of the Inactive enemy.
 /// </summary>
 /// <param name="context">Context of the enemy.</param>
 public void StartAnimation(EnemyContext context)
 {
     ((AnimatedModel)context.Enemy.DModel).TimeSpeed = 0.25f;
     ((AnimatedModel)context.Enemy.DModel).Animation.StartClip("Waiting", true);
 }