public int Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            space.Update(); // udpdate space, ball dropping , hit the posts, etc
            model.Update(gameTime);

            if (skeleton != null)
            {

                if (skeleton.Joints != null)
                {

                    joints = skeleton.Joints;        // copy the jointCollection to joints

                    rightHand = joints[JointType.HandRight];     // get the right hand of skeleton being tracked
                    leftHand = joints[JointType.HandLeft];  // get position of left hand

                    HEAD = joints[JointType.Head];     // know yourself

                    hipCentre = joints[JointType.HipCenter];

                    if (state == State.leftOrRightHand)
                    {
                        hipHeight = skeleton.Joints[JointType.HipCenter].Position.Y;  // initial hipHeight

                       // rotation = MathHelper.ToDegrees((float)Math.Atan((modulus(ball.sphere.Position.X - camSpot.X)) / (ball.sphere.Position.Z)));

                        //wind.X = (float)(((originWind.X) * Math.Cos(MathHelper.ToRadians(rotation))) - ((originWind.Y) * Math.Sin(MathHelper.ToRadians(rotation))));
                        //wind.Y = (float)(((originWind.X) * Math.Sin(MathHelper.ToRadians(rotation))) - ((originWind.Y) * Math.Cos(MathHelper.ToRadians(rotation))));

                        //calcWindRotate();

                        //camPosition.X += (sliotharPosition.X);
                        //camPosition.Z += (sliotharPosition.Z);

                        if (rightHand.Position.Z >= (leftHand.Position.Z + .3))
                        {

                            hand = HandCordination.leftHanded;
                            state = State.confimHand;

                        }
                        if ((leftHand.Position.Z) >= (rightHand.Position.Z + .3))
                        {

                            hand = HandCordination.rightHanded;
                            state = State.confimHand;

                        }

                    }
                }

                if (state == State.confimHand)
                {

                    Vector2 positionLeft = new Vector2(Convert.ToInt32(((0.5f * leftHand.Position.X) + 0.5f) * graphics.PreferredBackBufferWidth), Convert.ToInt32(((-0.5f * leftHand.Position.Y) + 0.5f) * graphics.PreferredBackBufferHeight));
                    Vector2 positionRight = new Vector2(Convert.ToInt32(((0.5f * rightHand.Position.X) + 0.5f) * graphics.PreferredBackBufferWidth), Convert.ToInt32(((-0.5f * rightHand.Position.Y) + 0.5f) * graphics.PreferredBackBufferHeight));

                    if ((positionLeft.X > 300) && (positionLeft.X < 400) && (positionLeft.Y < 460) && (positionLeft.Y > 360))
                    {

                        state = State.leftOrRightHand;

                    }
                    else if ((positionRight.X > 600) && (positionRight.X < 700) && (positionRight.Y < 460) && (positionRight.Y > 360))
                    {

                        state = State.rotate;

                    }

                }

                if (state == State.rotate)
                {
                    if ((rightHand.Position.Y >= HEAD.Position.Y) && (leftHand.Position.Y < HEAD.Position.Y))
                    {
                        camSpot.X += 0.1f;
                    }

                    if ((leftHand.Position.Y >= HEAD.Position.Y) && (rightHand.Position.Y < HEAD.Position.Y))
                    {
                        camSpot.X -= 0.1f;
                    }

                   // camPosition.X -= (sliotharPosition.X);
                    //camPosition.Y -= (sliotharPosition.Y);

                    rotation = MathHelper.ToDegrees((float)Math.Atan((modulus(ball.sphere.Position.X - camSpot.X)) / (ball.sphere.Position.Z)));

                   // arrowRotation = windRotation + MathHelper.ToRadians(rotation);

                    //camPosition.X += (sliotharPosition.X);
                    //camPosition.Z += (sliotharPosition.Z);

                    calcWindRotate();

                    if (ball.sphere.Position.X > camSpot.X)
                    {
                        camPosition.X = (float)(((camOrigin.Z - sliotharPosition.Z) * Math.Sin(MathHelper.ToRadians(rotation))) + ((camOrigin.X - sliotharPosition.X) * Math.Cos(MathHelper.ToRadians(rotation)))) + sliotharPosition.X;
                        camPosition.Z = (float)(((camOrigin.Z - sliotharPosition.Z) * Math.Cos(MathHelper.ToRadians(rotation))) - ((camOrigin.X - sliotharPosition.X) * Math.Sin(MathHelper.ToRadians(rotation)))) + sliotharPosition.Z;
                        // rotate the camera behind the player in line with where we are looking at
                    }

                    else
                    {
                        camPosition.X = (float)(((camOrigin.Z - sliotharPosition.Z) * Math.Sin(MathHelper.ToRadians(-rotation))) + ((camOrigin.X - sliotharPosition.X) * Math.Cos(MathHelper.ToRadians(-rotation)))) + sliotharPosition.X;
                        camPosition.Z = (float)(((camOrigin.Z - sliotharPosition.Z) * Math.Cos(MathHelper.ToRadians(-rotation))) - ((camOrigin.X - sliotharPosition.X) * Math.Sin(MathHelper.ToRadians(-rotation)))) + sliotharPosition.Z;

                    }

                    if ((leftHand.Position.Y >= HEAD.Position.Y) && (rightHand.Position.Y >= HEAD.Position.Y))
                    {

                        state = State.confirmRotate;

                    }
                }

                if (state == State.confirmRotate)
                {

                    Vector2 positionLeft = new Vector2(Convert.ToInt32(((0.5f * leftHand.Position.X) + 0.5f) * graphics.PreferredBackBufferWidth), Convert.ToInt32(((-0.5f * leftHand.Position.Y) + 0.5f) * graphics.PreferredBackBufferHeight));
                    Vector2 positionRight = new Vector2(Convert.ToInt32(((0.5f * rightHand.Position.X) + 0.5f) * graphics.PreferredBackBufferWidth), Convert.ToInt32(((-0.5f * rightHand.Position.Y) + 0.5f) * graphics.PreferredBackBufferHeight));

                    if ((positionLeft.X > 300) && (positionLeft.X < 400) && (positionLeft.Y < 460) && (positionLeft.Y > 360))
                    {

                        state = State.rotate;
                    }
                    else if ((positionRight.X > 600) && (positionRight.X < 700) && (positionRight.Y < 460) && (positionRight.Y > 360))
                    {

                        state = State.trajectory;
                    }

                }

                if (state == State.trajectory)
                {

                    gameTimer++;

                    double opposite = 0;
                    double adjacent = 0;

                    if (hand == HandCordination.rightHanded)
                    {
                        opposite = skeleton.Joints[JointType.HandRight].Position.Y - skeleton.Joints[JointType.ShoulderRight].Position.Y;
                        adjacent = skeleton.Joints[JointType.ShoulderRight].Position.Z - skeleton.Joints[JointType.HandRight].Position.Z;
                    }

                    if (hand == HandCordination.leftHanded)
                    {
                        opposite = skeleton.Joints[JointType.HandLeft].Position.Y - skeleton.Joints[JointType.ShoulderLeft].Position.Y;
                        adjacent = skeleton.Joints[JointType.ShoulderLeft].Position.Z - skeleton.Joints[JointType.HandLeft].Position.Z;
                    }

                    trajectory = (float)Math.Atan(opposite / adjacent);
                    trajectory = MathHelper.ToDegrees(trajectory);
                    if (trajectory < 0) // unless you want to drill it into the ground
                        trajectory *= -1;

                    if (gameTimer > 350)
                    {

                        state = State.standParallel;
                    }

                }

                /*
                if (state == State.power)
                {
                    gameTimer++;

                    double MaxPower = skeleton.Joints[JointType.Head].Position.Y - skeleton.Joints[JointType.HipCenter].Position.Y;
                    double currentPowerRight = skeleton.Joints[JointType.HandRight].Position.Y - skeleton.Joints[JointType.HipCenter].Position.Y;
                    double currentPowerLeft = skeleton.Joints[JointType.HandLeft].Position.Y - skeleton.Joints[JointType.HipCenter].Position.Y;

                    double avgPower = (currentPowerLeft + currentPowerRight) / 2;

                    double actualPower = (avgPower / MaxPower) * 100;

                    if (actualPower > 100)
                        actualPower = 100;

                    if (actualPower < 10)
                        actualPower = 10;

                    powerToball = (float)actualPower;
                    if (gameTimer > 700)
                    {
                        powerToball = (float)actualPower;
                        calcPowerValues(powerToball, rotation, trajectory);
                        state = State.standParallel;
                        print = "Stand To Strike";
                    }

                }
                 * */

                if (state == State.standParallel)
                {

                    if (((skeleton.Joints[JointType.HipRight].Position.X) >= ((skeleton.Joints[JointType.HipLeft].Position.X) - .14)) && (skeleton.Joints[JointType.HipRight].Position.X) <= ((skeleton.Joints[JointType.HipLeft].Position.X) + .14))
                    {

                        state = State.squatTransition;
                    }

                }

                if (state == State.squatTransition)
                {

                    double x1 = Convert.ToDouble(skeleton.Joints[JointType.HipCenter].Position.X);
                    double y1 = Convert.ToDouble(skeleton.Joints[JointType.HipCenter].Position.Y);

                    double x2 = Convert.ToDouble(skeleton.Joints[JointType.KneeLeft].Position.X);
                    double y2 = Convert.ToDouble(skeleton.Joints[JointType.KneeLeft].Position.Y);

                    double distance = Math.Sqrt( ((x1-x2)*(x1-x2)) + ( (y1-y2)*(y1-y2)) );

                    double height = 0;
                    height = mod(mod(y2) - mod(y1));

                  height = mod(y2 - y1);

                    if (y1 < hipHeight-0.18f)
                    {

                        state = State.squatPick;
                    }
                }

                if (state == State.squatPick)
                {

                    double x1 = Convert.ToDouble(skeleton.Joints[JointType.HipCenter].Position.X);
                    double y1 = Convert.ToDouble(skeleton.Joints[JointType.HipCenter].Position.Y);

                    double x2 = Convert.ToDouble(skeleton.Joints[JointType.KneeLeft].Position.X);
                    double y2 = Convert.ToDouble(skeleton.Joints[JointType.KneeLeft].Position.Y);

                    double distance = Math.Sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));

                    double height = 0;
                    height=mod(mod(y2)-mod(y1));

                    if (y1 < hipHeight - 0.18f)
                    {
                        powerToball+=0.5f;
                    }

                    else
                    {

                        if (powerToball < 10)
                            powerToball = 10;

                        if (powerToball > 100)
                            powerToball = rand.Next(20, 80);

                        calcPowerValues(powerToball, rotation, trajectory);
                        state = State.strikePosition;
                    }

                }

                if (state == State.strikePosition)
                {
                    //drawBall = true;
                    yellowBallPos.Y += 1;

                    if ((leftHand.Position.Z < hipCentre.Position.Z) && (rightHand.Position.Z < hipCentre.Position.Z) && (((joints[JointType.WristLeft].Position.X > joints[JointType.WristRight].Position.X) && (joints[JointType.WristLeft].Position.X > 0)) || ((joints[JointType.WristLeft].Position.X < joints[JointType.WristRight].Position.X) && (joints[JointType.WristLeft].Position.X < 0))))
                    {
                        // ballStruck = true;
                        AnimationClip clip = animation.Clips[0];

                        AnimationPlayer player = model.PlayClip(clip);
                        player.Looping = false;     // play the animation once
                        gameTimer = 0;
                        state = State.struck;

                    }

                }

                if (state == State.struck)
                {
                    accuracy = 400 - (int)yellowBallPos.Y;

                    gameTimer++;

                    if (gameTimer > 110)
                    {

                        power[0] += (accuracy / 5);  // screw up the accuracy a bit
                        ball.sphere.LinearVelocity = new Vector3(power[0], power[1], power[2]);

                        puckInstance.Volume = .99f;
                          puckInstance.IsLooped = false;
                        puckInstance.Play();
                        //puckInstance.IsLooped = false;
                        space.ForceUpdater.Gravity = new Vector3(-Xwind/10, -9.81f, -Zwind/10);  // apply the wind

                        /*
                        if (accuracy == 0)
                           // print = "     PERFECT";

                        else if((accuracy>10) || (accuracy<-10))
                           // print="MIS-HIT";
                        */
                        state = State.watch;
                    }

                    if (gameTimer > 70)
                    {
                        sliotharPosition.Y += 0.029f;   // moving the ball up to be hit
                        sliotharPosition.X += 0.022f;

                       sliotharPosition.X = (float)(((sliotharPosition.Z-sliotharOrigin.Z) * Math.Sin(MathHelper.ToRadians(rotation))) + ((sliotharPosition.X-sliotharOrigin.X) * Math.Cos(MathHelper.ToRadians(rotation)))) + sliotharOrigin.X;
                        sliotharPosition.Z = (float)(((sliotharPosition.Z-sliotharOrigin.Z) * Math.Cos(MathHelper.ToRadians(rotation))) - ((sliotharPosition.X-sliotharOrigin.X) * Math.Sin(MathHelper.ToRadians(rotation)))) + sliotharOrigin.Z;
                       // moves properly to the player and angle

                        ball.sphere.Position = sliotharPosition;
                        ball.position = sliotharPosition;
                    }
                }

                if (state == State.watch)
                {
                    levelEndTimer++;
                    camSpot = ball.sphere.Position;
                    camPosition.X = ball.position.X;
                    camPosition.Y = ball.position.Y + 10;
                    camPosition.Z = ball.position.Z + 10;
                }

                if ((ball.position.Y > 10) && (first==false))
                {

                    first = true;
                   // space.ForceUpdater.Gravity = new Vector3(Xwind, -9.81f, Zwind);
                }

                if((ball.position.Y <10 ) && (first==true))
                {
                    space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);
                }

            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                camPosition.Z++;

            }
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                camPosition.X++;

            }

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                camPosition.X--;

            }

            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                camPosition.Z--;

            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                kinect.ElevationAngle = (kinect.ElevationAngle + 1) % 15;

            }

            if (Keyboard.GetState().IsKeyDown(Keys.Z))
            {
                kinect.ElevationAngle = (kinect.ElevationAngle - 1) % 15;

            }

            if ((ball.position.Z >-1) && ( ball.position.Z<1) && ((score==false) && (wide==false)) )
            {
                if ((ball.position.X < 96.5f) && (ball.position.X > 83.5f))
                    score = true;         //
                else
                    wide = true;

            }

            increment++;

            if (speed % increment == 0)
            {
                increment = 1;
                frame++;
            }

            if (frame == 3)
                frame = 0;

            ball.Update();

            if (levelEndTimer > 500)
            {
                stopCrowd();
                return 1;
            }
            else
            {
                return 0;
            }

            //base.Update(gameTime);
        }
        public void Initializes(KinectSensor kinect, Skeleton skeleton,Skeleton[] skelData)
        {
            // TODO: Add your initialization logic here

            this.kinect = kinect;        // copy over all the kinect stuff
            this.skeleton = skeleton;
            this.skeletonData = skelData;

            rotation = 0;                  // player rotation is set to zero at start
            //print = "Raise Preferred Hand Forward";
            hand = HandCordination.undefined;
            state = State.leftOrRightHand;

            yellowBallPos = new Vector2(400, 300);

            space = new Space();
            rand = new Random();

            sliotharPosition = new Vector3(rand.Next(10, 170),.1f, rand.Next(40, 150));
            camPosition.X = sliotharPosition.X;
            camPosition.Y = 0.5f;
            camPosition.Z = sliotharPosition.Z+5;  // place camera behnd sliothar
            camOrigin = camPosition;

            playerPosition = new Vector3(sliotharPosition.X - 0.5f, 0, sliotharPosition.Z); // and player to the side
            sliotharOrigin = sliotharPosition;

            Xwind = rand.Next(-20, 20);  // supposedly random wind
            Zwind = rand.Next(-20, 20);  // applied like gravity

            hipHeight = 0;       // reference taken at start, for the squatting part
            frame = 0;
            increment = 0;
            windRotation = (float)Math.Atan(mod(Zwind) / mod(Xwind));  // get rotation to apply to the arrow
            // applies to 1st quadrant, below fixes it depending on wind values

            wind = new Vector2(Xwind, Zwind);
            originWind = new Vector2(Xwind, Zwind);
            double Windspeed = Math.Sqrt((Xwind * Xwind) + (Zwind * Zwind));   // give player a wind speed

            if (Windspeed >= 5)
                speed = 10;

            if (Windspeed > 10)
                speed = 5;

            if (speed < 5)
                speed = 15;

            calcWindRotate();
            //base.Initialize();
        }