Example #1
0
        protected override void Update(GameTime gameTime)
        {
            DeleteLines(loadedBoard);

            oldKeyState     = currentKeyState;
            currentKeyState = Keyboard.GetState();

            lastMouseState = newMouseState;
            newMouseState  = Mouse.GetState();
            int blocked = (int)GameBoard.BlockStates.Blocked;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            if (j < 4 && blockstate != blocked)
            {
                blockstate = (int)gbObj.CheckPlacement(loadedBoard, shape, xcoords[j], ycoords[j]);
                j++;
            }
            else
            {
                j = 0;
            }


            //Checks for what keys are pressed, Moves or rotates block
            if (blockstate != blocked || (oldKeyState.IsKeyDown(Keys.Enter) && currentKeyState.IsKeyUp(Keys.Enter)))
            {
                MoveKeys();
            }
            Console.WriteLine("blockstate: {0}", blockstate);
            //Console.WriteLine("posX, posY: {0}, {1}", posX, posY);
            if (blockstate == blocked)
            {
                //DeleteLines(loadedBoard);
                for (int i = 0; i < 4; i++)
                {
                    Array.Copy(gbObj.LoadBoard(loadedBoard, shape, xcoords[i], ycoords[i]), loadedBoard, loadedBoard.Length);
                }
                gbObj.ShowBoard(loadedBoard);
                blockstate = -1;
                SpawnShape();
            }
            // TODO: Add your update logic here

            //Testing menu
            switch (currentScreen)
            {
            case menuScreen:

                if ((playGameButton.update(new Vector2(newMouseState.X, newMouseState.Y)) == true && (newMouseState != lastMouseState) && (newMouseState.LeftButton == ButtonState.Pressed)) ||
                    ((currentKeyState != oldKeyState) && currentKeyState.IsKeyDown(Keys.Enter)))
                {    //play the game
                    NewGame();
                    currentScreen = game;
                }
                if (optionButton.update(new Vector2(newMouseState.X, newMouseState.Y)) == true && newMouseState != lastMouseState && newMouseState.LeftButton == ButtonState.Pressed)
                {    //goto options screen
                    currentScreen = optionScreen;
                }
                break;

            case game:
                if (currentKeyState != oldKeyState && currentKeyState.IsKeyDown(Keys.Escape))
                {
                    currentScreen = menuScreen;
                }
                if (GameOver(loadedBoard))
                {
                    currentScreen = menuScreen;
                }
                Fall(calculateTimer(level));
                break;
            }
            DeleteLines(loadedBoard);
            base.Update(gameTime);
        }