Пример #1
0
        /// <summary>
        /// Update the world depending on the state.
        /// </summary>
        public void UpdateWorld()
        {
            //Check if anything was inputted in the keyboard
            if (keyboard.CheckInput())
            {
                switch (keyboard.KeyCommand)
                {
                //Change states/data based on specific input from the keyboard
                case "Escape":
                    Environment.Exit(0);
                    break;

                case " ":
                    Player.gameState = Player.States.shooting;
                    break;

                case "R":
                    Player.gameState = Player.States.reset;
                    break;

                case "P":
                    if (worldState == States.play)
                    {
                        worldState = States.paused;
                    }
                    else if (worldState == States.paused)
                    {
                        worldState = States.play;
                    }
                    break;

                case "B":
                    player.PoppedBubble = true;
                    break;

                case "D":
                    worldState = States.designer;
                    break;

                case "Z":
                    if (worldState != States.zoom && worldState == States.play)
                    {
                        worldState = States.zoom;
                    }
                    else if (worldState == States.zoom)
                    {
                        worldState = States.play;
                    }
                    break;

                case "Up":
                    if (worldState == States.zoom)
                    {
                        float zoom = cam.GetZoom();
                        zoom += 0.1f;
                        cam.SetZoom(zoom);
                    }
                    break;

                case "Down":
                    if (worldState == States.zoom)
                    {
                        float zoom = cam.GetZoom();
                        zoom -= 0.1f;
                        cam.SetZoom(zoom);
                    }
                    break;
                }
            }

            //If the world is in the menu
            if (worldState == States.menu)
            {
                //Set the background of the game to be the menu screen
                Texture2D bg = content.Load <Texture2D>("MenuBackground");
                Background.Texture = bg;

                //If the menu is at the start screen
                if (Menu.menuState == Menu.States.start)
                {
                    //Check to see if anything is clicked
                    menu.CheckClick();
                }

                //Update the menu
                menu.Update();
            }

            //If the player wants to zoom in the game
            if (worldState == States.zoom)
            {
                //Change the zoom based on the up and down keys
                if (keyboard.KeyCommand == "Up")
                {
                    //Increase zoom
                    float zoom = cam.GetZoom();
                    zoom += 0.1f;
                    cam.SetZoom(zoom);
                }
                else if (keyboard.KeyCommand == "Down")
                {
                    //Decrease zoom
                    float zoom = cam.GetZoom();
                    zoom -= 0.1f;
                    cam.SetZoom(zoom);
                }
                else
                {
                    //If the Kinect is being used
                    if (kinect.KinectController)
                    {
                        //Calculate the zoom factor from each update where the hand is moved
                        float scalarValue = pointer.GetSprite.GetBounds.Y;
                        scalarValue = scalarValue * 0.003f;
                        cam.SetZoom(scalarValue);
                    }
                }
            }

            //If the player is playing:
            if (worldState == States.play || worldState == States.zoom)
            {
                //Check if the world needs to be reset
                CheckReset();

                //Update the controller being used.
                player.KinectController = kinect.KinectController;

                //Update the player pass it off the the slingshot
                player.Update();
                slingshot.PlayerPos = player.GetSprite.GetPosition;

                //Check what state the player is in the game
                if (Player.gameState == Player.States.setup)
                {
                    //Set the camera to look at the slingshot
                    cam.LookAt(slingshot.GetSprite.GetBounds);
                    //Make sure the player stays within the boundaries
                    map.SetupBoundary();
                }
                else if (Player.gameState == Player.States.flying)
                {
                    //Set the camera to look at the player
                    cam.LookAt(player.GetSprite.GetBounds);
                    //Check collision with the game boundaries and the player
                    BoundaryCollision(player.GetSprite);

                    //Update the bubbles in the map and check if there is any collision between the player and the tiles in the map
                    map.BubbleUpdate();
                    map.CheckPossibleCollision();
                }

                //Update the map
                map.Update();
            }
            //If the player is in the designer
            else if (worldState == States.designer)
            {
                //Check to see if any of the buttons were clicked and update the designer
                menu.ReturnClick();
                levelDesigner.CheckClick();
                levelDesigner.Update(content);
            }

            //If the player is using the kinect or is not currently playing
            if (player.KinectController || worldState != States.play)
            {
                //Update the pointer and make sure its within the boundaries of the screen
                pointer.Update();
                BoundaryCollision(pointer.GetSprite);
            }
        }
Пример #2
0
        /// <summary>
        /// Update the tiles on the screen based on the location were the pointer was clicked
        /// </summary>
        /// <param name="content"></param>
        public void Update(ContentManager content)
        {
            //If the player is clicking to place an object
            if (pointer.IsLeftClicked || kinect.PlaceObject)
            {
                //Find the absolute location of the tile being addded
                Vector2 tilePos = pointer.GetSprite.GetPosition;
                tilePos.X = tilePos.X / TILESIZE;
                tilePos.Y = tilePos.Y / TILESIZE;
                tilePos.X = (float)Math.Truncate(tilePos.X);
                tilePos.Y = (float)Math.Truncate(tilePos.Y);
                tilePos   = tilePos * TILESIZE;

                //Check if a tile can be placed at that location
                bool canPlaceTile = true;
                for (int i = 0; i < listTiles.Count; ++i)
                {
                    //If there is a tile at the choosen location
                    if (listTiles[i].GetSprite.GetPosition == tilePos)
                    {
                        //Remove the tile if the player is trying to remove it
                        if (designerState == States.remove)
                        {
                            listTiles.RemoveAt(i);
                            break;
                        }
                        else
                        {
                            //Set the tile to rotate mode if the player is trying to rotate the tile
                            if (listTiles[i] is Spike || listTiles[i] is Trampoline || listTiles[i] is WCushion)
                            {
                                isRotating   = true;
                                rotatingTile = listTiles[i];
                                break;
                            }
                        }

                        //Otherwise, a tile cannot be placed at that location
                        canPlaceTile = false;
                        break;
                    }
                }

                //Set the kinect to not be placing an object for future updates
                kinect.PlaceObject = false;

                //If the player isn't rotating the tile and one can be placed
                if (!isRotating && canPlaceTile)
                {
                    //Add the tile based on the state of the designer
                    switch (designerState)
                    {
                    case States.brick:
                        listTiles.Add(new Brick(tilePos, content));
                        break;

                    case States.trampoline:
                        listTiles.Add(new Trampoline(tilePos, content, 0));
                        break;

                    case States.spike:
                        listTiles.Add(new Spike(tilePos, content, 0));
                        break;

                    case States.wCushion:
                        listTiles.Add(new WCushion(tilePos, content, 0, null));
                        break;

                    case States.bubble:
                        listTiles.Add(new Bubble(tilePos, content));
                        break;

                    case States.apple:
                        listTiles.Add(new Apple(tilePos, content));
                        break;
                    }
                }
            }
            else
            {
                //Rotate the player with the kinect controller if required
                if (kinect.KinectController)
                {
                    //If the player is rotating the tile
                    if (isRotating && rotatingTile != null)
                    {
                        //Change the text of the button to say rotate
                        if (clickedButton.Text != "Rotate")
                        {
                            buttonText = clickedButton.Text;
                        }
                        clickedButton.Text = "Rotate";

                        //If the kinect is rotating a tile:
                        if (kinect.Rotating)
                        {
                            //Increment the angle of the object
                            if (rotatingTile is Spike)
                            {
                                ((Spike)rotatingTile).Angle += 2;
                            }
                            else if (rotatingTile is Trampoline)
                            {
                                ((Trampoline)rotatingTile).Angle += 2;
                            }
                            else if (rotatingTile is WCushion)
                            {
                                ((WCushion)rotatingTile).Angle += 2;
                            }
                        }
                        //If the mouse is rotating a tile
                        else
                        {
                            //Return to the regular state of the designer
                            isRotating   = false;
                            rotatingTile = null;

                            //Update the text in the button
                            if (buttonText != null)
                            {
                                clickedButton.Text = buttonText;
                            }
                        }
                    }
                }
                else
                {
                    //If the player is rotating the tile
                    if (isRotating && rotatingTile != null)
                    {
                        //Change the text of the button to say rotate
                        if (clickedButton.Text != "Rotate")
                        {
                            buttonText = clickedButton.Text;
                        }
                        clickedButton.Text = "Rotate";

                        //Check for player input
                        if (kb.CheckInput())
                        {
                            //If the player pressed the up or down button and the tile is a spike, trampoline, or a whoopee cushion,
                            //rotate the tile in the direction
                            if (kb.KeyCommand == "Up")
                            {
                                if (rotatingTile is Spike)
                                {
                                    ((Spike)rotatingTile).Angle += 5;
                                }
                                else if (rotatingTile is Trampoline)
                                {
                                    ((Trampoline)rotatingTile).Angle += 5;
                                }
                                else if (rotatingTile is WCushion)
                                {
                                    ((WCushion)rotatingTile).Angle += 5;
                                }
                            }
                            else if (kb.KeyCommand == "Down")
                            {
                                if (rotatingTile is Spike)
                                {
                                    ((Spike)rotatingTile).Angle -= 5;
                                }
                                else if (rotatingTile is Trampoline)
                                {
                                    ((Trampoline)rotatingTile).Angle -= 5;
                                }
                                else if (rotatingTile is WCushion)
                                {
                                    ((WCushion)rotatingTile).Angle -= 5;
                                }
                            }
                            //Check for the player finishing to rotate the tile
                            else if (kb.KeyCommand == "Enter")
                            {
                                //Return to the regular state of the designer
                                isRotating   = false;
                                rotatingTile = null;
                                if (buttonText != null)
                                {
                                    clickedButton.Text = buttonText;
                                }
                            }
                        }
                    }
                }
            }
        }