Beispiel #1
0
        /// <summary>
        /// Updates the pointer location
        /// </summary>
        public void Update()
        {
            //If the game is not being played
            if (World.worldState != World.States.play)
            {
                //If there is a player currently recognized by the kinect or if the game is not in setup
                if (Player.gameState != Player.States.noplayer || Player.gameState != Player.States.setup)
                {
                    //Create variable to hold pointer location
                    Vector2 curPos;

                    //Set the pointer location to the current controller
                    if (kinect.KinectController)
                    {
                        SkeletonPoint rightHand = kinect.ScaledHand("right").Position;
                        curPos = new Vector2(rightHand.X, rightHand.Y);
                    }
                    else
                    {
                        curPos = mouse.CheckInput();
                    }

                    //Check to see if the pointer is currently being used
                    if (Math.Abs(curPos.X - prevPos.X) > 10 && Math.Abs(curPos.Y - prevPos.Y) > 10)
                    {
                        prevPos    = curPos;
                        clickTimer = 0;

                        if (kinect.KinectController)
                        {
                            IsLeftClicked = false;
                        }
                    }
                    else
                    {
                        ++timer;
                        ++clickTimer;
                    }

                    if (clickTimer >= 3 * Driver.REFRESH_RATE)
                    {
                        IsLeftClicked = true;
                        clickTimer    = 0;
                    }

                    sprite.SetPosition(curPos);
                    clicking.SetPosition(sprite.GetPosition);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Update the player's properties and the player's location based on the state it is in
        /// </summary>
        public void Update()
        {
            switch (gameState)
            {
            //If the player is in the reset state:
            case States.reset:

                if (Lives > 1)
                {
                    //Reset the player location
                    sprite.SetBounds("X", lives * sprite.Texture.Height);
                    sprite.SetBounds("Y", (slingshot.GetSprite.GetBounds.Y + slingshot.GetSprite.GetBounds.Height) - sprite.Texture.Height);

                    //Reset the player properties and change the state to setup
                    --Lives;
                    mouse.IsLeftClicked = false;
                    Direction           = 1;
                    CancelGravity       = false;
                    gameState           = States.setup;
                }
                else
                {
                    World.GameOutcome = "LEVEL FAILED!";
                    World.worldState  = World.States.finished;
                }
                break;

            //If the player is in the setup state
            case States.setup:

                //Update the player location based on the controller being used
                if (isKinectController)
                {
                    SkeletonPoint leftHand = kinect.ScaledHand("left").Position;
                    sprite.SetPosition(new Vector2(leftHand.X, leftHand.Y));
                }
                else
                {
                    //Update the player's location or shoot the player if the left mouse button is clicked
                    if (mouse.IsLeftClicked)
                    {
                        gameState = States.shooting;
                    }
                    else
                    {
                        Vector2 mousePos = mouse.CheckInput();

                        //Make sure the player is within boundaries
                        if (mousePos.X < 16)
                        {
                            mousePos.X = 16;
                        }
                        else if (mousePos.Y < 16)
                        {
                            mousePos.Y = 16;
                        }
                        else if (mousePos.X > slingshot.GetPosition.X - sprite.GetBounds.Width)
                        {
                            mousePos.X = slingshot.GetPosition.X - sprite.GetBounds.Width;
                        }
                        else if (mousePos.Y > (slingshot.GetPosition.Y + slingshot.GetSprite.GetBounds.Height) - sprite.GetBounds.Height - sprite.GetBounds.Height * 0.5f)
                        {
                            mousePos.Y = (slingshot.GetPosition.Y + slingshot.GetSprite.GetBounds.Height) - sprite.GetBounds.Height - sprite.GetBounds.Height * 0.5f;
                        }

                        //Set the player's location to the mouse position
                        sprite.SetPosition(mousePos);
                    }
                }

                //Calculate the distance between the slingshot and the player
                float xDiff = slingshot.GetPosition.X - sprite.GetPosition.X;
                float yDiff = slingshot.GetPosition.Y - sprite.GetPosition.Y;
                distance = Math.Sqrt(Math.Pow(xDiff, 2) + Math.Pow(yDiff, 2)) * scale;

                //Calculate the velocity based on the distance
                vel = (float)distance / (Driver.REFRESH_RATE / scale);

                //Calculate the angle based on the player's position relative to the slingshot
                angle = CalcAngle(slingshot.GetPosition, sprite.GetPosition);

                //Call the procedure to calculate the player's rotated corners
                CalcCorners();
                break;

            //If the player is in the shooting state
            case States.shooting:

                //Calculate the player's starting trajectory based on the angle, direction, and velocity calculated
                startingTraj = CalcTrajectory(angle, dir, vel);

                //Store the starting trajectory calculated to be used while the player is flying
                traj = startingTraj;

                //Calculate the player's destination for rotation during air time
                float time = (float)Math.Sqrt(Math.Abs((2 * startingTraj.Y) / (GRAVITY * Driver.REFRESH_RATE)));
                destination.X = (startingTraj.X * time) + sprite.GetPosition.X;
                destination.Y = sprite.GetPosition.Y;
                //Set the player's state to flying since all required properties and trajectories have been calcuated
                gameState = States.flying;
                break;

            //If the player is in the flying state
            case States.flying:

                //Check if the player is in the bubble and change his trajectory based on that
                if (isInBubble)
                {
                    //Change the player's trajectory so that he floats and make sure no particles appear
                    NoParticles = true;
                    traj.Y     -= GRAVITY / (scale * scale);
                }
                else
                {
                    //Check whether or not the gravity was canceled
                    if (!CancelGravity)
                    {
                        //Increment the player's trajectory by gravity
                        traj.Y += GRAVITY;
                    }
                    else
                    {
                        //Make sure the player has no Y trajectory
                        traj.Y = 0;
                    }
                }

                //Update the player's particle emittor location and the particles themselves
                particleEngine.EmitterLocation = sprite.GetPosition;
                particleEngine.Update();

                //Check to see if new particles should be generated
                if (NoParticles)
                {
                    //Change the particle engine's porperties so that no new particles are created
                    particleEngine.Generate = false;
                }
                else
                {
                    //Continue generating new particles as the player flies around
                    particleEngine.Generate = true;
                }

                //Update the player's location based on the trajectory
                sprite.SetPosition(sprite.GetPosition + (traj * scale));

                //If the player hit the top of the screen, reset it's trajectory so that it bounces off
                if (HitTop)
                {
                    gameState = States.shooting;
                }

                //angle = CalcAngle(destination, sprite.GetPosition);

                //Check if the player might still move, if not the level is failed
                if (traj == Vector2.Zero)
                {
                    gameState = States.reset;
                }

                //Recalculate the player's rotated corner's for future collision detection
                CalcCorners();
                break;
            }
        }