using System;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for MovingPlatformHorizontal.
	/// </summary>
	public class MovingPlatformHorizontal : MovingPlatform
	{
		public MovingPlatformHorizontal()
		{
            this.InitialPoint = new Icarus.Logic.Physics.Point(0,0,0);
			this.Direction = (int)PhysicsSettings.enumDirection.Right;
		}

        /// <summary>
        /// controls the movement of this moving platform
        /// </summary>
        /// <returns></returns>
        public override int specificUpdates()
        {
            if(this.InitialPoint.x == 0)
            {
                this.InitialPoint.x = this.Location.x;
            }
            if(this.Location.x - this.InitialPoint.x >= this.Distance)
            {
                //Correct location incase it is slightly off
                this.Location.x = this.InitialPoint.x + this.Distance;

                //Reverse Direction
                if(this.Direction == (int)PhysicsSettings.enumDirection.Right)
                {
                    this.Direction = (int)PhysicsSettings.enumDirection.Left;
                }
                else
                {
                    this.Direction = (int)PhysicsSettings.enumDirection.Right;
                }
            }
            else if(this.InitialPoint.x > this.Location.x)
            {
                //Correct location incase it is slightly off
                this.Location.x = this.InitialPoint.x;

                //Reverse Direction
                if(this.Direction == (int)PhysicsSettings.enumDirection.Right)
                {
                    this.Direction = (int)PhysicsSettings.enumDirection.Left;
                }
                else
                {
                    this.Direction = (int)PhysicsSettings.enumDirection.Right;
                }
            }

            //Set speed
            if(this.Direction == (int)PhysicsSettings.enumDirection.Right)
            {
                this.Velocity.i = (float)this.Speed;
            }
            else
            {
                this.Velocity.i = -1 * (float)this.Speed;
            }
         
            return (int)PhysicsSettings.enumActions.DoNothing;
        }

	}
}
