public void fall()
    {
        Blick thisBlock = getBlick();

        if (!thisBlock.isSettled())
        {
            if (isControlledByPlayer())
            {
                if (Time.time - GameController.lastFall > GameController.fallDelay)
                {
                    if (checkDown())
                    {
                        moveBlock(new Vector2(blickPos.x, (blickPos.y - 1)));
                        GameController.lastFall = Time.time;
                    }
                }
            }
            else
            {
                if (checkDown())
                {
                    moveBlock(new Vector2(blickPos.x, (blickPos.y - 1)));
                }
            }
        }
    }
    public void update()
    {
        Blick thisBlock = getBlick();

        if (!GameController.accessGameController().blockInPlay&& isControlledByPlayer())
        {
            removePlayerControl();
        }
        if (blickPos.y != 0)
        {
            if (checkDown())
            {
                thisBlock.setSettled(false);
                fall();
            }
            else
            {
                thisBlock.setSettled(true);
                updateBlick();
            }
        }
        else
        {
            thisBlock.setSettled(true);
        }
        if (isControlledByPlayer() && thisBlock.isSettled())
        {
            removePlayerControl();
        }
    }
    public void moveBlock(Vector2 dest)
    {
        Blick oldBlick = getBlick();

        oldBlick.setSettled(false);
        oldBlick.setOccupied(false);
        oldBlick.block = null;
        blickPos       = dest;
        updateBlick();
    }
    void updateBlick()
    {
        Blick thisBlick = getBlick();

        if (!thisBlick.isOccupied())
        {
            thisBlick.setOccupied(true);
            thisBlick.block = this;
        }
    }
Beispiel #5
0
    public static Blick getBlick(Vector2 target)
    {
        Blick ret = null;

        if (isInBlickArray(target))
        {
            ret = GameController.accessGameController().blickGrid[(int)target.x, (int)target.y];
        }
        return(ret);
    }
    public void removeBlock()
    {
        Blick thisBlick = getBlick();

        thisBlick.block = null;
        thisBlick.setSettled(false);
        thisBlick.setOccupied(false);
        GameObject thisBlock = getParentObject();

        thisBlock.tag += "[delete]";
        thisBlock.GetComponent <BlockScript> ().Remove();
    }
Beispiel #7
0
 public Blick[,] setupBlicks()
 {
     Blick[,] blickGrid = new Blick[GameController.cols, GameController.rows];
     for (int i = 0; i < GameController.cols; i++)
     {
         for (int j = 0; j < GameController.rows; j++)
         {
             blickGrid[i, j] = new Blick();
         }
     }
     return(blickGrid);
 }
Beispiel #8
0
    public static bool blockTypeNearby(Block block)
    {
        bool ret = false;

        //Checks 4 surrounding horizontal and vertical blocks for same colour types
        if (Blick.isInBlickArray(new Vector2((block.blickPos.x - 1), block.blickPos.y)))
        {
            if (!block.checkLeft())
            {
                Block other = GameController.accessGameController().blickGrid [(int)(block.blickPos.x - 1), (int)block.blickPos.y].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        if (Blick.isInBlickArray(new Vector2((block.blickPos.x + 1), block.blickPos.y)))
        {
            if (!block.checkRight())
            {
                Block other = GameController.accessGameController().blickGrid [(int)(block.blickPos.x + 1), (int)block.blickPos.y].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        if (Blick.isInBlickArray(new Vector2(block.blickPos.x, (block.blickPos.y + 1))))
        {
            if (!block.checkUp())
            {
                Block other = GameController.accessGameController().blickGrid [(int)block.blickPos.x, (int)(block.blickPos.y + 1)].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        if (Blick.isInBlickArray(new Vector2(block.blickPos.x, (block.blickPos.y - 1))))
        {
            if (!block.checkDown())
            {
                Block other = GameController.accessGameController().blickGrid [(int)block.blickPos.x, (int)(block.blickPos.y - 1)].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        return(ret);
    }
    public bool checkDown()
    {
        bool ret = false;

        if (blickPos.y > 0)
        {
            Blick other = GameController.accessGameController().blickGrid [(int)blickPos.x, (int)(blickPos.y - 1)];
            if (!other.isOccupied())
            {
                ret = true;
            }
        }
        return(ret);
    }
    public bool checkRight()
    {
        bool ret = false;

        if (blickPos.x < (GameController.cols - 1))
        {
            Blick other = GameController.accessGameController().blickGrid [(int)(blickPos.x + 1), (int)blickPos.y];
            if (!other.isOccupied())
            {
                ret = true;
            }
        }
        return(ret);
    }
    //CHECK NEARBY BLICK METHODS
    //ALL METHODS RETURN TRUE IF BLICK IS EMPTY, FALSE IF NOT
    public static bool checkCustom(Vector2 dest)
    {
        bool ret = false;

        if (Blick.isInBlickArray(dest))
        {
            Blick other = GameController.accessGameController().blickGrid [(int)dest.x, (int)dest.y];
            if (!other.isOccupied())
            {
                ret = true;
            }
        }
        return(ret);
    }
 public bool isControlledByPlayer()
 {
     if (controlledByPlayer)
     {
         if (!checkDown())
         {
             Vector2 getBelow = new Vector2(0.0f, -1.0f);
             getBelow += blickPos;
             Blick other = Blick.getBlick(getBelow);
             if (other != null)
             {
                 if (other.isSettled())
                 {
                     removePlayerControl();
                 }
             }
         }
     }
     return(controlledByPlayer);
 }
Beispiel #13
0
    public int findShape(Block block, Vector2[,] map)
    {
        //Returns -1 if block was not found

        //Else returns int signifying in what orientation the shape was found
        //0 = UP
        //1 = RIGHT
        //2 = DOWN
        //3 = LEFT

        int searchResult = -1;

        if (FinishedShapeDetector.blockTypeNearby(block))
        {
            int   connections = 0;
            Block current = new Block(true), next = new Block(true);
            for (int i = 0; i < map.GetLength(0); i++)
            {
                current     = block;
                connections = 0;
                for (int j = 0; j < map.GetLength(1); j++)
                {
                    //IM NOT SURE HOW ASSIGNING WORKS IN C# IT MIGHT F**K UP SO IF SHIT GOES CRAZY LOOK AT WHAT NEXT IS CHANGING
                    Vector2 nextVector = map[i, j];
                    nextVector += current.blickPos;
                    if (Blick.isInBlickArray(nextVector))
                    {
                        if (!Block.checkCustom(nextVector))
                        {
                            next = GameController.accessGameController().blickGrid[(int)nextVector.x, (int)nextVector.y].getBlock();
                            if (Block.CompareTypes(current, next))
                            {
                                connections++;
                                current = next;
                                if (connections == 3)
                                {
                                    searchResult = i;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (connections == 3)
                {
                    break;
                }
            }

            if (searchResult != -1)
            {
                //Remove blocks if shape was found
                current = block;
                for (int i = 0; i < 4; i++)
                {
                    if (i < 3)
                    {
                        Vector2 nextVector = map[searchResult, i] + current.blickPos;
                        next = GameController.accessGameController().blickGrid[(int)nextVector.x, (int)nextVector.y].getBlock();
                    }
                    current.removeBlock();
                    current = null;
                    current = next;
                }
            }
        }
        return(searchResult);
    }