Beispiel #1
0
        private bool IsOverFilledCells(bool below)
        {
            int ox, oy;

            EdGameUtil.CalcCellPos(boardRect, blockPos, CellSize, below, out ox, out oy);
            if (below)
            {
                oy++;
            }
            for (int x = 0; x < blockWH; x++)
            {
                for (int y = 0; y < blockWH; y++)
                {
                    if (block[y, x] == 1)
                    {
                        // idx can be smaller than 0 for new blocks, which starts above board and idx could
                        // be bigger than grid.Length because of empty cells reaching below board
                        int idx = (x + ox) + ((y + oy) * GridWidth);
                        if (idx >= 0 && idx < grid.Length && grid[idx] >= 0)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        private void MoveBubble(float dt)
        {
            bubblePos += moveDir * dt * bubbleMoveSpeed;

            // check if should stick to other bubbles
            int x, y;

            // this is buggy. sometimes a bubble will stop in the air cause not checking for the offset.
            Vector2 p = bubblePos;

            p = p + (moveDir.normalized * CellSizeHalf);

            EdGameUtil.CalcCellPos(boardRect, p, CellSize, true, out x, out y);
            if (y >= 0 && y < GridHeight && grid[y * GridWidth + x] >= 0)
            {
                EdGameUtil.CalcCellPos(boardRect, bubblePos, CellSize, true, out x, out y);
                if (y >= GridHeight || y < 0)
                {
                    gameActive = false;
                    return;
                }

                if (grid[y * GridWidth + x] < 0)
                {
                    grid[y * GridWidth + x] = bubbleType;
                    CheckAndBreakCells(x, y, bubbleType);
                    SelectBubble();
                    return;
                }
            }

            // bounce bubble off left/right edge
            if (bubblePos.x - CellSizeHalf < boardRect.x)
            {
                bubblePos.x = boardRect.x + CellSizeHalf + 1;
                moveDir.x  *= -1;
            }
            else if (bubblePos.x + CellSizeHalf > boardRect.xMax)
            {
                bubblePos.x = boardRect.xMax - (CellSizeHalf + 1);
                moveDir.x  *= -1;
            }

            // stick to top edge
            if (bubblePos.y - CellSizeHalf < boardRect.y)
            {
                bubblePos.y = boardRect.y + CellSizeHalf + 1;
                EdGameUtil.CalcCellPos(boardRect, bubblePos, CellSize, true, out x, out y);
                if (grid[y * GridWidth + x] < 0)
                {
                    grid[y * GridWidth + x] = bubbleType;
                    CheckAndBreakCells(x, y, bubbleType);
                }
                SelectBubble();
            }
        }
Beispiel #3
0
        private bool SnapBlock()
        {
            int ox, oy;

            EdGameUtil.CalcCellPos(boardRect, blockPos, CellSize, true, out ox, out oy);
            for (int x = 0; x < blockWH; x++)
            {
                for (int y = 0; y < blockWH; y++)
                {
                    if (block[y, x] == 1)
                    {
                        int idx = (x + ox) + ((y + oy) * GridWidth);
                        if (idx < 0)
                        {
                            return(true);                                 // if idx invalid then reached top and game over
                        }
                        grid[idx] = blockType;
                    }
                }
            }
            return(false);
        }