/// <summary> /// Allows the end game to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { Random r = new Random(); // Create timer and first explosion on first update if (timer == null) { pc.AddExplosion(particleTexture, RandomPosition(), 10, r.Next(3, 10), 1000, RandomColor(), gameTime); timer = new Timer(game, 1000); } // Monitor touches to complete the scene foreach (GestureSample gs in InputHandler.Instance.Taps()) Complete = true; // Clear input every frame InputHandler.Instance.Clear(); // Monitor the back button if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Complete = true; return; } // Update time and particles timer.Update(gameTime); pc.Update(gameTime); // Add explosions and reset timer when timer is up if (timer.IsDone()) { pc.AddExplosion(particleTexture, RandomPosition(), 10, r.Next(3, 10), 1500, RandomColor(), gameTime); timer = new Timer(game, 1000); } base.Update(gameTime); }
/// <summary> /// Allows the level to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { // Monitor the back button to quit level if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Quit = true; return; } // Update entities exit.Update(gameTime); player.Update(gameTime); // Handles early input cancelling if (timer == null) timer = new Timer(game, 500); timer.Update(gameTime); if (!timer.IsDone()) { InputHandler.Instance.Clear(); return; } // Set state of level based on player state = LevelState.Idle; if (player.State == PlayerState.Moving) state = LevelState.Moving; // Check for win condition if (state == LevelState.Idle) { if (player.Position.Intersects(exit.Position)) Complete = true; } // Update the HUD HUD.Update(gameTime); // Check for reset if (HUD.Reset) { // Don't show instructions on reset Initialize(false); timer = null; return; } // Check for Exit() if (HUD.Exit) { Quit = true; return; } // Update blocks for (int y = 0; y < map.GetLength(0); y++) { for (int x = 0; x < map.GetLength(1); x++) { if (map[y, x] != null) map[y, x].Update(gameTime); } } // Update lightning effects lc.Update(gameTime); // Handle new gestures if (state == LevelState.Idle && inst == null) { // Handle player movement Direction direction = InputHandler.Instance.DragDirection(); if (direction != Direction.None) ProcessPlayerMove(direction); // Handle block push Vector2 doubleTap = InputHandler.Instance.DoubleTap(); if (doubleTap != Vector2.Zero) ProcessPush(doubleTap); } // Handle inputs to instructions else if (state == LevelState.Idle && inst != null) { inst.Update(gameTime); if (inst.Complete) inst = null; } // Clear the input this frame InputHandler.Instance.Clear(); base.Update(gameTime); }
/// <summary> /// Allows the splash screen to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { // If there is any touch or gesture on the screen, complete the splash screen foreach (GestureSample gs in InputHandler.Instance.Taps()) { InputHandler.Instance.Clear(); Complete = true; } // Update the splash screen for alpha fading switch (state) { // Fade in the screen case SplashState.FadeIn: alpha += 0.05f; if (alpha >= 1) state = SplashState.Display; break; // Display normally case SplashState.Display: // Create and update timer if (timer == null) timer = new Timer(game, totalTime); timer.Update(gameTime); // Time to fade out? if (timer.IsDone()) state = SplashState.FadeOut; break; // Fade out screen case SplashState.FadeOut: alpha -= 0.05f; if (alpha <= 0) Complete = true; break; } base.Update(gameTime); }