Пример #1
0
        public void updateGamePlay(GameTime gameTime)
        {
            fizzyoDevice.Update(gameTime);
            inputState.Update(gameTime);


            score += 1;
            KeyboardState keys = Keyboard.GetState();

            if (keys.IsKeyDown(Keys.Up))
            {
                Player.StartMovingUp();
            }
            else
            {
                Player.StopMovingUp();
            }

            if (keys.IsKeyDown(Keys.Down))
            {
                Player.StartMovingDown();
            }
            else
            {
                Player.StopMovingDown();
            }
            float startRightMovement = Player.xPosition;

            if (/*keys.IsKeyDown(Keys.G)*/ breathRecogniser.isLastBreathGood)
            {
                Player.GoodBreath(startRightMovement);
            }
            if (keys.IsKeyDown(Keys.B))
            {
                Player.BadBreath(startRightMovement);
            }
            if (Player.xPosition < screenWidth / 1000)
            {
                GameOver();
            }

            PlayerTexture();
            EnemyTextureSelector();
            foreach (Enemies enemy in e)
            {
                double dx = (Player.xPosition - enemy.position.X);
                double dy = (Player.yPosition - enemy.position.Y);
                if ((Math.Sqrt((dx * dx) + (dy * dy))) < (enemy.texture.Width))
                {
                    long TimeBetweenLastCollison = stopwatch.ElapsedMilliseconds;
                    if (TimeBetweenLastCollison == 0 || TimeBetweenLastCollison > 3000)
                    {
                        stopwatch.Reset();
                        stopwatch.Start();
                        ReduceOrEnd();
                    }
                }
            }
            foreach (Enemies enemy in e)
            {
                enemy.Update(graphics.GraphicsDevice);
            }

            foreach (Player s in gameSprites)
            {
                s.Update(1.0f / 60.0f);
            }
            ///
            /// FIZZYO IN GAME LOOP
            ///

            InputState inputstate = new InputState(this);

            breathRecogniser.AddSample(gameTime.ElapsedGameTime.Milliseconds, fizzyoDevice.Pressure());
        }
Пример #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)
        {
            joyState = Joystick.GetState(0);
            fizzyo.Update(gameTime);
            inputState.Update(gameTime);
            PlayerIndex playerIndex = PlayerIndex.One;

            // Allows the game to exit
            if (inputState.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out playerIndex) || inputState.IsNewKeyPress(Keys.Escape))
            {
                Exit();
            }

            float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

            if (currentGameState == GameState.Loading)
            {
                if (inputState.IsNewKeyPress(Keys.Enter) ||
                    inputState.IsNewButtonPress(Buttons.Start, PlayerIndex.One, out playerIndex))
                {
                    roundTimer       = roundTime;
                    currentGameState = GameState.Running;
                }
            }

            if ((currentGameState == GameState.Running))
            {
                fuelCarrier.Update(barriers);
                gameCamera.Update(fuelCarrier.ForwardDirection,
                                  fuelCarrier.Position, aspectRatio);
                retrievedFuelCells = 0;
                foreach (FuelCell fuelCell in fuelCells)
                {
                    fuelCell.Update(fuelCarrier.BoundingSphere);
                    if (fuelCell.Retrieved)
                    {
                        retrievedFuelCells++;
                    }
                }
                if (retrievedFuelCells == GameConstants.NumFuelCells)
                {
                    currentGameState = GameState.Won;
                }
                CanMove = !breathRecogniser.IsExhaling;
                //Timer only counts down when the player has finished a breath
                if (CanMove)
                {
                    roundTimer -= gameTime.ElapsedGameTime;
                }

                if ((roundTimer < TimeSpan.Zero) &&
                    (retrievedFuelCells != GameConstants.NumFuelCells))
                {
                    currentGameState = GameState.Lost;
                }
            }

            if ((currentGameState == GameState.Won) ||
                (currentGameState == GameState.Lost))
            {
                // Reset the world for a new game
                if (inputState.IsNewKeyPress(Keys.Enter) ||
                    inputState.IsNewButtonPress(Buttons.Start, PlayerIndex.One, out playerIndex))
                {
                    ResetGame(gameTime, aspectRatio);
                }
            }

            HandleInput(gameTime);

            // TODO: Add your update logic here

            base.Update(gameTime);
        }