/// <summary> /// When a block on the side of the feild atempts to rotate, this method will then 'Kick' said block away from the wall. /// </summary> /// <param name="blockState"></param> /// <returns></returns> private bool WallKick(Block.BlockState blockState) { if (!CheckForIntersectingBlocks(movingBlock.Y, movingBlock.X, blockState)) { for (int i = 1; i < 3; i++) { if (CheckForIntersectingBlocks(movingBlock.Y, movingBlock.X + i, blockState)) { movingBlock.X += i; return(true); } else if (CheckForIntersectingBlocks(movingBlock.Y, movingBlock.X - i, blockState)) { movingBlock.X -= i; return(true); } } return(false); } return(true); }
/// <summary> /// Used to make sure that we don't intersect any blocks while moving. /// </summary> /// <param name="passedY"></param> /// <param name="passedX"></param> /// <param name="blockState"></param> /// <returns> </returns> private bool CheckForIntersectingBlocks(int passedY, int passedX, Block.BlockState blockState) { // Block area shit. bool[,] currentBlockArea = movingBlock.BlockArea(movingBlock.CurrentBlockState); bool[,] newBlockArea = movingBlock.BlockArea(blockState); editFeild(currentBlockArea, false, movingBlock.X, movingBlock.Y); // Are we rotating in to any blocks? for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { // Does this square exist? if (newBlockArea[y, x]) { if (passedY + y <= 19 && passedY + y >= 0 && passedX + x >= 0 && passedX + x <= 9) { // is it intersecting any blocks? if (feildData[passedY + y, passedX + x]) { editFeild(currentBlockArea, true, movingBlock.X, movingBlock.Y); return(false); } } else { editFeild(currentBlockArea, true, movingBlock.X, movingBlock.Y); return(false); } } } } return(true); }
/// <summary> /// Actually updates the blocks image. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void blockMover_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (!isPaused) { // If we are moving and the block isn't going down this tick. if (movingBlock.IsMoving && tickInterval != 25) { // Update tick. tickInterval++; // Clear old pos. editFeild(blankSquare, lastBlockAreaPos, false, lastMovingBlockX, lastMovingBlockY); // Draw ghost block. if (cheatBools[1]) { // Remove old ghost block. if (movingBlock.X != lastMovingBlockX || movingBlock.CurrentBlockState != lastBlockState) { for (int y = lastMovingBlockY; CheckForIntersectingBlocks(y, lastMovingBlockX, lastBlockState); y++) { if (!CheckForIntersectingBlocks(y + 1, lastMovingBlockX, lastBlockState)) { editFeild(blankSquare, movingBlock.BlockArea(lastBlockState), false, lastMovingBlockX, y); } } } // Draw ghost block. for (int y = movingBlock.Y; CheckForIntersectingBlocks(y, movingBlock.X, movingBlock.CurrentBlockState); y++) { if (!CheckForIntersectingBlocks(y + 1, movingBlock.X, movingBlock.CurrentBlockState)) { editFeild(movingBlock.GhostImage, movingBlock.BlockArea(movingBlock.CurrentBlockState), false, movingBlock.X, y); } } } // Update new pos. editFeild(movingBlock.BlockImage, movingBlock.BlockArea(movingBlock.CurrentBlockState), true, movingBlock.X, movingBlock.Y); // Save last block position in memory. lastBlockAreaPos = movingBlock.BlockArea(movingBlock.CurrentBlockState); lastBlockState = movingBlock.CurrentBlockState; lastMovingBlockX = movingBlock.X; lastMovingBlockY = movingBlock.Y; } // Can we move down again? else if (!CheckForIntersectingBlocks(movingBlock.Y + 1, movingBlock.X, movingBlock.CurrentBlockState)) { // Clear old pos. editFeild(blankSquare, lastBlockAreaPos, false, lastMovingBlockX, lastMovingBlockY); // Update new pos. editFeild(movingBlock.BlockImage, movingBlock.BlockArea(movingBlock.CurrentBlockState), true, movingBlock.X, movingBlock.Y); movingBlock.IsMoving = false; tickInterval = 0; if (softDrop && gameScore != 9999999999) { gameScore++; } } // If we can move down do it. else { movingBlock.Y++; tickInterval = 0; if (softDrop && gameScore != 9999999999) { gameScore++; } } } }