Пример #1
0
 /// <summary>
 /// Loads an instruction in for the current level.
 /// </summary>
 private void LoadInstruction()
 {
     switch (LevelNumber)
     {
         case 1:
         case 2:
         case 4:
         case 5:
         case 7:
             inst = new Instruction(game, spriteBatch, LevelNumber);
             break;
         default:
             inst = null;
             break;
     }
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// Updates all components in the settings view.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        private void UpdateSettings(GameTime gameTime)
        {
            // Update the reset button
            reset.Update(gameTime);

            // Monitor the back button to go back to main menu
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                state = MenuState.Main;
                UnloadSettings();
                LoadMainMenu();
                return;
            }

            // Letting the user know they reset the levels
            if (inst != null)
            {
                inst.Update(gameTime);
                if (inst.Complete)
                    inst = null;
                return;
            }

            // Handle the reset button to reset levels back to 1
            if (reset.State == TouchButtonState.Clicked)
            {
                FileHandler.ResetLevels();
                inst = new Instruction(game, spriteBatch, -1);
            }

            // Update the sound buttons
            soundYes.Update(gameTime);
            soundNo.Update(gameTime);

            // Handle the enable sound button
            if (soundYes.State == TouchButtonState.Clicked)
            {
                // Force a sound to play when sound gets turned on intially
                if (SoundMixer.Instance(game).Muted)
                    SoundMixer.Instance(game).PlayButton(true);
                SoundMixer.Instance(game).Muted = false;
            }

            // Handle sound off button
            if (soundNo.State == TouchButtonState.Clicked)
                SoundMixer.Instance(game).Muted = true;
        }
Пример #4
0
        /// <summary>
        /// Creates the lightning controller, heads up display, calls to load
        /// the current level, and calls to create instructions as needed.
        /// </summary>
        /// <param name="showInstructions">If true, instructions will be shown on level load if they exist.</param>
        public void Initialize(bool showInstructions)
        {
            // Create the lightning controller
            lc = new LightningController(game, spriteBatch);

            /// Create the HUD
            HUD = new HeadsUpDisplay(game, spriteBatch);
            HUD.Level = LevelNumber;

            // Initialize map and load level
            map = new Block[18, 12];
            LoadLevel();

            // Show instructions as needed
            inst = null;
            if(showInstructions)
                LoadInstruction();

            base.Initialize();
        }
Пример #5
0
 /// <summary>
 /// Unloads all components needed for settings view.
 /// </summary>
 private void UnloadSettings()
 {
     soundYes = null;
     soundNo = null;
     reset = null;
     inst = null;
 }