public void Update() //HEREISUPDATE ----------------------------------------------------------------------------------------------------------
        {
            myHasRaisedThisFrame = false;

            const float DeltaTime = 1.0f / 60.0f;

            if (myIsPaused == false && myHasStarted == true)
            {
                myGameTime         += DeltaTime;
                myGameSpeed         = Math.Min(1.0f + (myGameTime / 60f) + myAdditionalGameSpeed, 10f);
                myModifiedGameSpeed = (float)Math.Log10(myGameSpeed + 1);
            }

            HandleChains(DeltaTime);

            if (IsFrozen() == false && myChainTimer <= 0f)
            {
                if (myGridContainer.IsExceedingRoof() == true)
                {
                    myMercyTimer -= DeltaTime * myModifiedGameSpeed;
                    if (myMercyTimer < 0)
                    {
                        GameInfo.GameInfo.myPlayers[myPlayerIndex].DebugDied(myPlayerIndex);
                        myIsDead = true;
                        DeadFeedback();
                    }
                }
                else
                {
                    float tilesPerSecond = myModifiedGameSpeed;
                    Raise(tilesPerSecond);
                    //reset mercy timer
                    myMercyTimer = MyMaxMercyTimer / myModifiedGameSpeed;
                }
            }

            //if it crashes here there are big chances that they have same position
            myGridContainer.myBlocks.Sort();
            foreach (var angryBundle in myAngryBundles)
            {
                angryBundle.UpdateFallingStatus();
            }

            // just update all blocks, give them an update function to override
            for (int i = 0; i < myGridContainer.myBlocks.Count; i++)
            {
                AbstractBlock block = myGridContainer.myBlocks[i];
                block.Update(myModifiedGameSpeed);
            }
            foreach (var angryBundle in myAngryBundles) // foreach bundle if bundle isDisitergraintigb UpdateDIsintegrate break;
            {
                angryBundle.Update(myModifiedGameSpeed);
            }
            for (int i = 0; i < myBlockIterators.Count; ++i)
            {
                myBlockIterators[i].Update();
                if (myBlockIterators[i].IsFinished())
                {
                    myBlockIterators.RemoveAt(i);
                    i--;
                }
            }

            CheckForMatches();
            ResetCanChain();

            for (int iBundle = 0; iBundle < myAngryBundles.Count(); iBundle++)
            {
                if (myAngryBundles[iBundle].IsDed())
                {
                    myAngryBundles[iBundle].OnDestroy();
                    myAngryBundles.RemoveAt(iBundle);
                    iBundle--;
                }
            }

            myGridContainer.RemoveTopRows();
        }
Esempio n. 2
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            var state = inputManager.HandleInput();

            if (state.isPausePressed)
            {
                paused = !paused;
            }

            if (!paused && !gameLost)
            {
                board.ClearBlock(currBlock);

                if (state.isUpPressed)
                {
                    while (board.BlockCanMove(currBlock, 0, 1))
                    {
                        currBlock.MoveDown(1);
                    }
                    currBlock.IsSet = true;
                }
                if (state.isDownPressed && board.BlockCanMove(currBlock, 0, 1))
                {
                    currBlock.MoveDown(1);
                }
                if (state.isRightPressed && board.BlockCanMove(currBlock, 1, 0))
                {
                    currBlock.HorizontalMove(true);
                }
                if (state.isLeftPressed && board.BlockCanMove(currBlock, -1, 0))
                {
                    currBlock.HorizontalMove(false);
                }
                if (state.isRotateLeftPressed)
                {
                    currBlock.RotateLeft();
                }
                if (state.isRotateRightPressed)
                {
                    currBlock.RotateRight();
                }
                if (state.isHoldPressed)
                {
                    HoldBlock();
                }


                // TODO: Add your update logic here
                var time  = gameTime.TotalGameTime;
                var delta = time - _lastUpdate;
                totalTime += gameTime.ElapsedGameTime;


                if (delta.TotalMilliseconds > blockUpdateDelta)
                {
                    _lastUpdate = time;
                    if (board.BlockCanMove(currBlock, 0, 1))
                    {
                        currBlock.MoveDown(1);
                    }
                }

                currBlock.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds);
                board.UpdateBlock(currBlock);

                if (currBlock.IsSet)
                {
                    currBlock = blockQueue.Dequeue();
                    AddBlock();
                    score   += board.Update();
                    gameLost = board.DidLose();
                }
            }
            nextBlockDisplay.Block = blockQueue.Peek();

            base.Update(gameTime);
        }