Пример #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)
        {
            //Esc to quit program
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape) || Exit == true)
            {
                Exit();
            }

            //If player is dead the game stops
            if (state == GameState.GameOver)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.R))
                {
                    Restart();
                }
                return;
            }
            else if (state == GameState.Game)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.R))
                {
                    Restart();
                }
                //Rock spawn
                RockDelayElapsed -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (RockDelayElapsed <= 0f)
                {
                    Debug.WriteLine("Spawninwg");
                    sprites.Add(new Rock(rockTexture));
                    RockDelayElapsed = RockDelay;
                }
                //Meteor spawn
                MeteorDelayElapsed -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (MeteorDelayElapsed <= 0f)
                {
                    Debug.WriteLine("Spawning");
                    sprites.Add(new Meteor(rockTexture));
                    MeteorDelayElapsed = MeteorDelay;
                }

                //Updates the sprites
                foreach (var sprite in sprites.ToArray())
                {
                    sprite.Update(gameTime, sprites);
                }
            }
            else if (state == GameState.Menu)
            {
                menu.Update(gameTime);
            }
            PostUpdate(); //Removes all dead sprites
        }
Пример #2
0
 public static state MenuUpdate(GameTime gameTime)
 {
     return((state)menu.Update(gameTime, menuUSelect, menuDSelect, hsSound, bgSound));
 }
 public static State MenuUpdate(GameTime gameTime)
 {
     return((State)menu.Update(gameTime));            // Get the new state from Update method in menu object
 }