using System;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for RectangleFloor.
	/// </summary>
	public class RectangleFloor : PhysicsRectangle
	{
		public RectangleFloor()
		{
			this.Description = "Rect-Floor";
		}


        /// <summary>
        /// Performs the necessary operations on a PO
        /// that has collided with this rectangle
        /// </summary>
        /// <param name="po">Physics Object that collided with rectangle</param>
        /// <returns>Action to be taken after collision occurs(ie: remove, doNothing)</returns>
        public override int intersectionAction(PhysicsObject po)
        {
            if(po is PhysicsPlayer)
            {
                //Don't slide after hitting ground while whipping
                if(po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.WhippingRight ||
                    po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.WhippingLeft)
                {
                    po.Velocity.i = 0.0f;
                }

                //Stop a person from moving(walking) once they hit the floor
                if(po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.FallingLeft ||
                   po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.JumpingLeft)
                {
                    if(((PhysicsPlayer)po).StopWalking)
                    {
                        //Reset stopWalking boolean
                        ((PhysicsPlayer)po).StopWalking = false;
                        //Update ActionState
                        po.LastActionState = po.ActionState;
                        po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.StandingLeft;
                        po.Velocity.i = 0.0f;
                    }
                    else
                    {
                        //Update ActionState
                        po.LastActionState = po.ActionState;
                        po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.WalkingLeft;
                    }
                }
                else if(po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.FallingRight ||
                    po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.JumpingRight)                    
                {
                    if(((PhysicsPlayer)po).StopWalking)
                    {
                        //Reset stopWalking boolean
                        ((PhysicsPlayer)po).StopWalking = false;
                        //Update ActionState
                        po.LastActionState = po.ActionState;
                        po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.StandingRight;
                        po.Velocity.i = 0.0f;
                    }
                    else
                    {
                        //Update ActionState
                        po.LastActionState = po.ActionState;
                        po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.WalkingRight;
                    }
                }

                //Make sure he is not moving if he is not supposed to be
                if(po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.StandingLeft ||
                    po.ActionState == (int)PhysicsSettings.enumPlayerActionStates.StandingRight)
                {
                    po.Velocity.i = 0.0f;
                }
            }


            if((po.CollisionBox.BoundingBox.Y + po.CollisionBox.BoundingBoxHeight/2) > (this.Y+this.Height/2))//Move PO up
            {
                po.Location.y = this.Y + this.Height + po.CBYoffset;
            }
            else //Move PO down
            {
                po.Location.y += this.Y - po.CollisionBox.BoundingBox.Y - po.CollisionBox.BoundingBoxHeight;
            }
            po.Velocity.j = 0.0f;
            return (int)PhysicsSettings.enumActions.DoNothing;
            //return (int)PhysicsSettings.enumActions.CheckAgain;
        }

	}
}
