using System;
using System.Xml.Serialization;

using Icarus.Graphics.Animation;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for MovingPlatform.
	/// </summary>
	public class MovingPlatform : WorldObject
	{ 
        /// <summary>
        /// The distance this platform moves before reversing direction
        /// </summary>
        private int iDistance;

        /// <summary>
        /// The speed at which the platform moves
        /// </summary>
        private double iSpeed;

        /// <summary>
        /// The direction this platform is moving currently
        /// </summary>
        private int iDirection;

        /// <summary>
        /// The initial position of this moving platform
        /// </summary>
        private Icarus.Logic.Physics.Point pntInitial;

        /// <summary>
        /// Collision box for this 
        /// </summary>
        private CollisionBox cb;

        /// <summary>
        /// gets or sets the distance the platform moves before reversing direction
        /// </summary>
        public int Distance
        {
            get { return this.iDistance; }
            set { this.iDistance = value; }
        }

        /// <summary>
        /// gets or sets the speed at which this platform moves
        /// </summary>
        public double Speed
        {
            get { return this.iSpeed; }
            set { this.iSpeed = value;}
        }

        /// <summary>
        /// gets for sets the initial point of this moving platform
        /// </summary>
        public Icarus.Logic.Physics.Point InitialPoint
        {
            get { return this.pntInitial; }
            set { this.pntInitial = value; }
        }

        /// <summary>
        /// gets or sets the current direction
        /// </summary>
        public int Direction
        {
            get { return this.iDirection; }
            set { this.iDirection = value; }
        }

        //[XmlIgnore]
        public override CollisionBox CollisionBox
        {
            get 
            {
                //Setting the current bounding rectangle of the bounding box.
                PhysicsRectangle rect = this.cb.BoundingBox;
                rect.X = (int)this.Location.x - this.CBXoffset;
                rect.Y = (int)this.Location.y - this.CBYoffset;
                rect.Width = this.cb.BoundingBoxWidth;
                rect.Height = this.cb.BoundingBoxHeight;
                this.cb.BoundingBox = rect;
                ((CollisionBoxMobile)(this.cb)).WO = this;
                return this.cb;
            }
            set { this.cb = value; }
        }

		public MovingPlatform()
		{
			this.cb = new CollisionBoxMobile();
			this.SetAnimation("explosions/explosion1.png", AnimationType.LoopForever, 1);
            this.cb.BoundingBoxWidth = 30;
            this.cb.BoundingBoxHeight = 25;
            this.CBXoffset = 11;
            this.CBYoffset = 15;
            this.po_gravity.j = 0.0f;
		}
	}
}
