Beispiel #1
0
        //given the active GameShape on activation
        private GameShape TryActivateGameShape()
        {
            state.activateNext();

            //if active shape spawned into collision ==> GameOver
            if (MovementManager.CheckForCollisions(state.getGrid(), state.getActiveShape().blocks,
                                                   state.getActiveShape()))
            {
                return(null);
            }


            return(state.getActiveShape());
        }
Beispiel #2
0
        private void processInput(BlockGrid grid, GameShape activeShape)
        {
            InputAction curInput = inputReader.GetLastAction();

            switch (curInput)
            {
            case InputAction.Pause:
                togglePause();
                break;

            case InputAction.Null:
                break;

            default:
                if (!isPaused)
                {
                    Console.WriteLine($"Applying {curInput} to shape: {activeShape}");
                    MovementManager.ApplyAction(curInput, grid, activeShape);
                }

                break;
            }
        }
Beispiel #3
0
        // Author: Stahl Samuel, Yuetao Zhu
        public override void Update()
        {
            AudioEngine.Update();
            if (music.Volume > 0.30f)
            {
                vol_delta = -0.002f;
            }
            else if (music.Volume < 0.00f)
            {
                vol_delta = 0.002f;
            }
            music.Volume += vol_delta;

            // Intentionally disabling sounds for now
            music.Volume = 0.000f;

            inputReader.GetInputs();
            if (!isPaused)
            {
                //--------------------------------------------------------
                // Rotate Sprite -- shows if game paused or not...
                //--------------------------------------------------------
                pRedBird.angle = pRedBird.angle + 0.01f;
                pRedBird.Update();


                BlockGrid grid        = state.getGrid();
                GameShape activeShape = state.getActiveShape();

                // Things we need to check on every update:
                // 1. activeShape is placed => trigger GameState.activateNext() and set active shape to new active shape
                // 2. if timer is expired => reset timer and MovementManager.ApplyAction(InputAction.MoveDown,grid,shape);
                // 3. if timer is not expired => processInput();

                if (activeShape.isPlaced)
                {
                    //Update activeShape, lines, score, level, check game-over
                    UpdateGameState(grid);
                }
                //if shape was placed, timer was just reset (mutually exclusive)
                else if (lineCycleTimer.IsExpired())
                {
                    Console.WriteLine($"Moving shape down: {activeShape}");
                    MovementManager.ApplyAction(InputAction.MoveDown, grid, activeShape);
                    lineCycleTimer.ResetTimer();
                    inputTimer.ResetTimer();
                }
                else
                {
                    if (inputTimer.IsExpired())
                    {
                        processInput(grid, activeShape);
                        inputTimer.ResetTimer();
                    }
                }
            }
            else
            {
                if (inputTimer.IsExpired())
                {
                    // Paused
                    processInput(null, null);
                    inputTimer.ResetTimer();
                }
            }
        }