using System;

using Icarus.Graphics.Animation;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for PhysicsTuxRobot.
	/// </summary>
	public class PhysicsTuxRobot : PhysicsPlayer
	{
		public PhysicsTuxRobot()
		{
            //Set edo's health
            this.GameStats.Health = 100;

            //Set main world object initial animation
			this.SetAnimation("edo/robot/left/robot_lower_body.gif", AnimationType.LoopForever, 1);

            //Main bounding
            this.CollisionBox = new CollisionBoxEnemyDefault();
            this.CollisionBox.BoundingBox.X = 0;
            this.CollisionBox.BoundingBox.Y = 0;
            this.CollisionBox.BoundingBox.Width = 545;
            this.CollisionBox.BoundingBox.Height = 225;
            this.CollisionBox.BoundingBoxWidth = 545;
            this.CollisionBox.BoundingBoxHeight = 225;
            this.CBXoffset = 290;
            this.CBYoffset = 210;
            this.po_gravity.j = PhysicsSettings.Instance.sv_mercGravity.j;
            this.CollisionBox.Damage = 5;

            
            //Adding parts together
            Icarus.Logic.ChildObject upper_body = new PhysicsTuxHead();//Icarus.Logic.ChildObject();
            Icarus.Logic.ChildObject upper_arm = new Icarus.Logic.Physics.PhysicsTuxHand();
            Icarus.Logic.ChildObject lower_arm = new Icarus.Logic.Physics.PhysicsTuxHand();
            Icarus.Logic.ChildObject jumpBlock = new ChildObject();
            this.Children = new Icarus.Logic.ChildObject[] { upper_body };
            upper_body.Children = new Icarus.Logic.ChildObject[] { upper_arm };
            upper_arm.Children = new Icarus.Logic.ChildObject[] { lower_arm };
            lower_arm.Children = new Icarus.Logic.ChildObject[] { jumpBlock };

            

            //Upper body
            upper_body.AnchorPoint = new Icarus.Logic.Physics.Point(-15, -285, 0);
			upper_body.SetAnimation("edo/robot/left/robot_upper_body.gif", AnimationType.LoopForever, 1);

            //Upper body collision data
            upper_body.CollisionBox = new CollisionBoxEnemyDefault();//CollisionBoxEnemyDefault();
            ((CollisionBoxEnemyDefault)upper_body.CollisionBox).ThrowDirection = (int)PhysicsSettings.enumDirection.Left;
            upper_body.CollisionBox.BoundingBox.X = 0;
            upper_body.CollisionBox.BoundingBox.Y = 0;
            upper_body.CollisionBox.BoundingBox.Width = 250;
            upper_body.CollisionBox.BoundingBox.Height = 350;
            upper_body.CollisionBox.BoundingBoxWidth = 250;
            upper_body.CollisionBox.BoundingBoxHeight = 350;
            upper_body.CBXoffset = 130;
            upper_body.CBYoffset = 280;
            upper_body.CollisionBox.Damage = 5;

            //Upper arm
            upper_arm.AnchorPoint = new Icarus.Logic.Physics.Point(-140, -75, 0);
			upper_arm.SetAnimation("edo/robot/left/arm_upper.gif", AnimationType.LoopForever, 1);
            
            //Upper arm collision data
            upper_arm.CollisionBox.BoundingBox.X = 0;
            upper_arm.CollisionBox.BoundingBox.Y = 0;
            upper_arm.CollisionBox.BoundingBox.Width = 215;
            upper_arm.CollisionBox.BoundingBox.Height = 60;
            upper_arm.CollisionBox.BoundingBoxWidth = 215;
            upper_arm.CollisionBox.BoundingBoxHeight = 60;
            upper_arm.CBXoffset = 210;
            upper_arm.CBYoffset = 35;

            //lower arm
			lower_arm.AnchorPoint = new Icarus.Logic.Physics.Point(-215, -10, 0);
			lower_arm.SetAnimation("edo/robot/left/arm_lower.gif", AnimationType.LoopForever, 1);
            
            //Lower arm collision data
            lower_arm.CollisionBox.BoundingBox.X = 0;
            lower_arm.CollisionBox.BoundingBox.Y = 0;
            lower_arm.CollisionBox.BoundingBox.Width = 245;
            lower_arm.CollisionBox.BoundingBox.Height = 120;
            lower_arm.CollisionBox.BoundingBoxWidth = 245;
            lower_arm.CollisionBox.BoundingBoxHeight = 125;
            lower_arm.CBXoffset = 240;
            lower_arm.CBYoffset = 30;


            //JumpBlock - invisible object above tux so you can't jump over him
            jumpBlock.AnchorPoint = new Icarus.Logic.Physics.Point(0 , 0, 0);
            jumpBlock.SetAnimation(@"\null\null_fset.png", Icarus.Graphics.Animation.AnimationType.LoopOnce, 1);
            jumpBlock.CollisionBox = new CollisionBoxEnemyDefault();
            ((CollisionBoxEnemyDefault)jumpBlock.CollisionBox).ThrowDirection = (int)PhysicsSettings.enumDirection.Left;
            jumpBlock.CollisionBox.BoundingBox.X = 0;
            jumpBlock.CollisionBox.BoundingBox.Y = 0;
            jumpBlock.CollisionBox.BoundingBox.Width = 100;
            jumpBlock.CollisionBox.BoundingBox.Height = 500;
            jumpBlock.CollisionBox.BoundingBoxWidth = 100;
            jumpBlock.CollisionBox.BoundingBoxHeight = 500;
            jumpBlock.CBYoffset = 650;
            jumpBlock.CBXoffset = -300;
		}

        public override int specificUpdates()
        {
            if(!this.Vulnerable)
            {
                this.InvulnerableIterationCount++;
                if(this.InvulnerableIterationCount > this.InvulnerableIterationLimit)
                {
                    this.Vulnerable = true;
                    this.InvulnerableIterationCount = 0;
                }
            }

            //TOD0: check to see if tux is dead and make his parts fly away if so.
            //check to see if we are dead
            if(this.GameStats.Health <= 0)
            {
                //Fly apart
                //Place parts with velocites to fly apart
                PhysicsShortLife pslTreds = new PhysicsShortLife();
                pslTreds.Location = this.Location;
                pslTreds.SetAnimation("edo/robot/left/robot_lower_body.gif", AnimationType.LoopForever, 1);
                pslTreds.FlickerAnimationId = "edo/robot/left/robot_lower_body.gif";
                pslTreds.po_gravity = PhysicsSettings.Instance.sv_mercGravity;
                pslTreds.Velocity.j = PhysicsSettings.Instance.JumpVelocity;
                pslTreds.Velocity.i = -1;

                PhysicsShortLife pslBody = new PhysicsShortLife();
                pslBody.Location = this.Children[0].Location;
                pslBody.SetAnimation("edo/robot/left/robot_upper_body.gif", AnimationType.LoopForever, 1);
                pslBody.FlickerAnimationId = "edo/robot/left/robot_upper_body.gif";
                pslBody.po_gravity = PhysicsSettings.Instance.sv_mercGravity;
                pslBody.Velocity.j = PhysicsSettings.Instance.JumpVelocity;
                pslBody.Velocity.i = 5;
                
                PhysicsShortLife pslArm = new PhysicsShortLife();
                pslArm.Location = this.Children[0].Children[0].Location;
                pslArm.SetAnimation("edo/robot/left/arm_upper.gif", AnimationType.LoopForever, 1);
                pslArm.FlickerAnimationId = "edo/robot/left/arm_upper.gif";
                pslArm.po_gravity = PhysicsSettings.Instance.sv_mercGravity;
                pslArm.Velocity.j = PhysicsSettings.Instance.JumpVelocity;
                pslArm.Velocity.i = -5;
                
                PhysicsShortLife pslHand = new PhysicsShortLife();
                pslHand.Location = this.Children[0].Children[0].Children[0].Location;
                pslHand.SetAnimation("edo/robot/left/arm_lower.gif", AnimationType.LoopForever, 1);
                pslHand.FlickerAnimationId = "edo/robot/left/arm_lower.gif";
                pslHand.po_gravity = PhysicsSettings.Instance.sv_mercGravity;
                pslHand.Velocity.j = PhysicsSettings.Instance.JumpVelocity;
                pslHand.Velocity.i = -7;

                int i;
                for(i = 0; i < Logic.GameEngine.GameSettings.Instance.sv_maxActors; i++)
                {
                    if(PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i] == null) break;
                }
                //is there room?
                if((Logic.GameEngine.GameSettings.Instance.sv_maxActors - 4) > i)
                {
                    PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i] = pslTreds;
                    PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i+1] = pslBody;
                    PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i+2] = pslArm;
                    PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i+3] = pslHand;
                }



                //Remove tux
                return (int)Icarus.Logic.Physics.PhysicsSettings.enumActions.Remove;
            }


            return (int)Icarus.Logic.Physics.PhysicsSettings.enumActions.DoNothing;

        }



	}
}
