Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().GetPressedKeys().Contains(Keys.Escape))
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            GamePadState  gps = GamePad.GetState(PlayerIndex.One);
            KeyboardState kbs = Keyboard.GetState();

            if (gameState == (int)GAME_STATES.PLAYING)
            {
                if (kbs.GetPressedKeys().Contains(Keys.OemComma) || gps.ThumbSticks.Left.X > 0)
                {
                    leftWheel.spinWheel(-1);
                }
                else if (kbs.GetPressedKeys().Contains(Keys.OemPeriod) || gps.ThumbSticks.Left.X < 0)
                {
                    leftWheel.spinWheel(1);
                }

                if (kbs.GetPressedKeys().Contains(Keys.Left) || gps.ThumbSticks.Right.X > 0)
                {
                    rightWheel.spinWheel(-1);
                }
                else if (kbs.GetPressedKeys().Contains(Keys.Right) || gps.ThumbSticks.Right.X < 0)
                {
                    rightWheel.spinWheel(1);
                }

                if (kbs.GetPressedKeys().Contains(Keys.Space) || gps.IsButtonDown(Buttons.A))
                {
                    oven.takeCupcake(leftWheel.removeCupcake());
                    oven.takeCupcake(rightWheel.removeCupcake());
                }

                if ((kbs.GetPressedKeys().Contains(Keys.Enter) && lastKBS.IsKeyUp(Keys.Enter)) ||
                    (gps.IsButtonDown(Buttons.B) && lastGPS.IsButtonUp(Buttons.B)))
                {
                    comboMessages = oven.cookCupcakes();
                    totalScore   += oven.Score;
                }


                if (timeSinceLastSpawn > CUPCAKE_SPAWN_INTERVAL)
                {
                    makeNewCupcakes();
                    timeSinceLastSpawn = 0;
                }
                else
                {
                    timeSinceLastSpawn += gameTime.ElapsedGameTime.Milliseconds;
                }

                moveCupcakes();

                checkForCupcakeCollisions();


                if (oven.Heat > 100)
                {
                    gameState = (int)GAME_STATES.GAME_OVER;
                }

                if (timeSinceLastHeatReduction > HEAT_REDUCTION_INTERVAL)
                {
                    oven.reduceHeat();
                    timeSinceLastHeatReduction = 0;
                }
                else
                {
                    timeSinceLastHeatReduction += gameTime.ElapsedGameTime.Milliseconds;
                }
            }


            if (gameState == (int)GAME_STATES.GAME_OVER)
            {
                if (gps.IsButtonDown(Buttons.Back) || kbs.IsKeyDown(Keys.R))
                {
                    this.Initialize();
                }
            }

            lastGPS = gps;
            lastKBS = kbs;


            base.Update(gameTime);
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().GetPressedKeys().Contains(Keys.Escape))
            {
                this.Exit();
            }

            GamePadState  gps = GamePad.GetState(PlayerIndex.One);
            KeyboardState kbs = Keyboard.GetState();

            if (gameState == (int)GAME_STATES.PLAYING) //Once gameState switches to "PLAYING" check for the key/button presses to spin the wheels appropriately
            {
                //Left wheel controls
                if (kbs.GetPressedKeys().Contains(Keys.OemComma) || gps.ThumbSticks.Left.X > 0)
                {
                    leftWheel.spinWheel(-1);
                }
                else if (kbs.GetPressedKeys().Contains(Keys.OemPeriod) || gps.ThumbSticks.Left.X < 0)
                {
                    leftWheel.spinWheel(1);
                }

                //Right Wheel Controls
                if (kbs.GetPressedKeys().Contains(Keys.Left) || gps.ThumbSticks.Right.X > 0)
                {
                    rightWheel.spinWheel(-1);
                }
                else if (kbs.GetPressedKeys().Contains(Keys.Right) || gps.ThumbSticks.Right.X < 0)
                {
                    rightWheel.spinWheel(1);
                }

                //Send cupcakes to the oven
                if (kbs.GetPressedKeys().Contains(Keys.Space) || gps.IsButtonDown(Buttons.A))
                {
                    oven.takeCupcake(leftWheel.removeCupcake());
                    oven.takeCupcake(rightWheel.removeCupcake());
                }

                //Cook cupcakes
                if ((kbs.GetPressedKeys().Contains(Keys.Enter) && lastKBS.IsKeyUp(Keys.Enter)) ||
                    (gps.IsButtonDown(Buttons.B) && lastGPS.IsButtonUp(Buttons.B)))
                {
                    comboMessages = oven.cookCupcakes();
                    totalScore   += oven.Score;
                }

                //Send new cupcakes onto the screen if the time interval has passed.
                if (timeSinceLastSpawn > CUPCAKE_SPAWN_INTERVAL)
                {
                    makeNewCupcakes();
                    timeSinceLastSpawn = 0;
                }
                else
                {
                    timeSinceLastSpawn += gameTime.ElapsedGameTime.Milliseconds;
                }

                moveCupcakes();

                checkForCupcakeCollisions();

                //The game ends if the oven temperature exceeds 100
                if (oven.Heat > 100)
                {
                    gameState = (int)GAME_STATES.GAME_OVER;
                }

                //Reduce oven temperature over time
                if (timeSinceLastHeatReduction > HEAT_REDUCTION_INTERVAL)
                {
                    oven.reduceHeat();
                    timeSinceLastHeatReduction = 0;
                }
                else
                {
                    timeSinceLastHeatReduction += gameTime.ElapsedGameTime.Milliseconds;
                }
            }

            //Check for a restart of the game once a GAME OVER has happened
            if (gameState == (int)GAME_STATES.GAME_OVER)
            {
                if (gps.IsButtonDown(Buttons.Back) || kbs.IsKeyDown(Keys.R))
                {
                    this.Initialize();
                }
            }
            lastGPS = gps;
            lastKBS = kbs;

            base.Update(gameTime);
        }