Exemplo n.º 1
0
        /// <summary>
        /// Handles the movement of the enemy
        /// </summary>
        protected virtual void MoveEnemy(GameTime gameTime)
        {
            Vector2 previousPosition = Position;

            //Update velocity
            velocity.X = direction.X * MaxVelocity.X;
            velocity.Y = GamePhysics.GetFallSpeed(Velocity.Y, gameTime);

            //Apply velocity to enemy
            position += Velocity;

            HandleCollisions();

            // If the collision stopped us from moving, reset the velocity to zero.
            if (Position.X == previousPosition.X)
            {
                velocity.X = 0;
            }
            if (Position.Y == previousPosition.Y)
            {
                velocity.Y = 0;
            }
        }