Example #1
0
    public static GameObject SpawnArrowForLane(int col, int row, Types.LaneMovementType dir, int orderNumber)
    {
        Sprite newSpr;

        switch (orderNumber)
        {
        case 0:
            newSpr = firstArrow;
            break;

        case 1:
            newSpr = secondArrow;
            break;

        case 2:
            newSpr = thirdArrow;
            break;

        default:
            Debug.Log("SpawnArrow(): Error! Wrong order number!!");
            newSpr = null;
            break;
        }

        Vector3 slotPosition, rotation;

        slotPosition = GetArrowPosition(col, row, dir);
        rotation     = GetArrowRotation(dir);

        GameObject newArrow = Instantiate(arrow, slotPosition + offset, Quaternion.Euler(rotation));

        newArrow.GetComponent <ArrowIndicator>().Initialize(newSpr);
        return(newArrow);
    }
Example #2
0
    public void SetUncollapsedTile(Vector3 startPos, Types.LaneMovementType dir)
    {
        Vector3 scale;

        switch (dir)
        {
        case Types.LaneMovementType.LEFT:
        case Types.LaneMovementType.RIGHT:
            scale = new Vector3(0f, transform.localScale.y, transform.localScale.z);
            break;

        case Types.LaneMovementType.UP:
        case Types.LaneMovementType.DOWN:
            scale = new Vector3(transform.localScale.x, 0f, transform.localScale.z);
            break;

        default:
            scale = Vector3.zero;
            Debug.Log("ERROR!! Scale for uncollapsed tile is wrong!");
            break;
        }

        transform.position   = startPos;
        transform.localScale = scale;
    }
Example #3
0
    public static Vector3 GetArrowRotation(Types.LaneMovementType dir)
    {
        Vector3 newRot;
        float   rotVal;

        switch (dir)
        {
        case Types.LaneMovementType.RIGHT:
            rotVal = 0;
            break;

        case Types.LaneMovementType.LEFT:
            rotVal = 180;
            break;

        case Types.LaneMovementType.UP:
            rotVal = 90;
            break;

        case Types.LaneMovementType.DOWN:
            rotVal = 270;
            break;

        default:
            rotVal = 0;
            break;
        }

        newRot = new Vector3(0, 0, rotVal);

        return(newRot);
    }
Example #4
0
    public void CollapseTile(Types.LaneMovementType direction)
    {
        Vector3 collapseEndPoint = GetBoardSlotBorder(this, direction, true);

        objInSlot.GetComponent <Tile>().ProceedCollapse(direction, collapseEndPoint);
        ResetSlot();
    }
Example #5
0
    private Vector3 GetBoardSlotBorder(GameBoardSlot slot, Types.LaneMovementType dir, bool collapse)
    {
        Vector3 startPos = slot.transform.position;
        int     dirMult  = (collapse) ? -1 : 1;

        switch (dir)
        {
        case Types.LaneMovementType.LEFT:
            startPos += new Vector3((slot.slotSprite.bounds.size.x / 2) * dirMult, 0, 0);
            break;

        case Types.LaneMovementType.RIGHT:
            startPos -= new Vector3((slot.slotSprite.bounds.size.x / 2) * dirMult, 0, 0);
            break;

        case Types.LaneMovementType.UP:
            startPos -= new Vector3(0, (slot.slotSprite.bounds.size.y / 2) * dirMult, 0);
            break;

        case Types.LaneMovementType.DOWN:
            startPos += new Vector3(0, (slot.slotSprite.bounds.size.y / 2) * dirMult, 0);
            break;

        default:
            startPos = Vector3.zero;
            break;
        }

        return(startPos);
    }
Example #6
0
 public LaneMovementOrder(int col, int row, Types.LaneMovementType movType, GameObject arrow)
 {
     rowToMove    = row;
     columnToMove = col;
     movementType = movType;
     orderArrow   = arrow;
 }
Example #7
0
    public void ProceedUncollapse(Types.LaneMovementType dir, Vector3 endPos)
    {
        SetAxis(dir);

        collapseMultiplier = 1;
        transferEndPos     = endPos;
        uncollapsing       = true;
    }
Example #8
0
    public void UncollapseTile(Types.LaneMovementType direction, GameBoardSlot transferTo, Tile tile)
    {
        Vector3 uncollapseEndPoint = GetBoardSlotBorder(transferTo, direction, false);

        tile.SetUncollapsedTile(uncollapseEndPoint, direction);

        transferTo.objInSlot  = tile.gameObject;
        transferTo.isOccupied = true;
        transferTo.objInSlot.GetComponent <Tile>().ProceedUncollapse(direction, transferTo.transform.position);
    }
Example #9
0
    private void SetAxis(Types.LaneMovementType dir)
    {
        switch (dir)
        {
        case Types.LaneMovementType.LEFT:
        case Types.LaneMovementType.RIGHT:
            xAxis = true;
            break;

        case Types.LaneMovementType.UP:
        case Types.LaneMovementType.DOWN:
            xAxis = false;
            break;
        }
    }
Example #10
0
    public int CountTilesInLane(int colIndex, int rowIndex, Types.LaneMovementType movType)
    {
        int  counter = 0;
        bool isRow;

        switch (movType)
        {
        case Types.LaneMovementType.RIGHT:
        case Types.LaneMovementType.LEFT:
            isRow = true;
            break;

        case Types.LaneMovementType.UP:
        case Types.LaneMovementType.DOWN:
            isRow = false;
            break;

        default:
            Debug.Log("Error! Wrong movement type!");
            return(-1);
        }

        if (isRow)
        {
            for (int x = 0; x < columnSize; x++)
            {
                if (boardSize[x, rowIndex].isOccupied)
                {
                    counter++;
                }
            }
        }
        else
        {
            for (int x = 0; x < rowSize; x++)
            {
                if (boardSize[colIndex, x].isOccupied)
                {
                    counter++;
                }
            }
        }


        return(counter);
    }
Example #11
0
    public static Vector3 GetArrowPosition(int col, int row, Types.LaneMovementType dir)
    {
        GameBoard     board = GameObject.FindGameObjectWithTag(GameConsts.GAME_BOARD_TAG).GetComponent <GameBoard>();
        GameBoardSlot slot;
        Vector3       pos, offset;

        switch (dir)
        {
        case Types.LaneMovementType.RIGHT:
            slot   = board.GetSlot(GameConsts.GAME_BOARD_COLUMNS - 1, row);
            offset = new Vector3(offsetValue, 0, 0);
            break;

        case Types.LaneMovementType.LEFT:
            slot   = board.GetSlot(0, row);
            offset = new Vector3(-offsetValue, 0, 0);
            break;

        case Types.LaneMovementType.UP:
            slot   = board.GetSlot(col, GameConsts.GAME_BOARD_ROWS - 1);
            offset = new Vector3(0, offsetValue, 0);
            break;

        case Types.LaneMovementType.DOWN:
            slot   = board.GetSlot(col, 0);
            offset = new Vector3(0, -offsetValue, 0);
            break;

        default:
            pos    = new Vector3(0, 0, 0);
            slot   = null;
            offset = new Vector3(0, 0, 0);
            Debug.Log("GetPositionForArrow: ERROR! No slot selected, returning 0,0,0 position for arrow!");
            break;
        }

        if (!slot)
        {
            Debug.Log("FUCKUP!");
        }
        pos = slot.transform.position + offset;

        return(pos);
    }
Example #12
0
    private void FindLaneForOrder(out int col, out int row, out Types.LaneMovementType dir)
    {
        List <Types.LaneMovementType> potentialDirections = new List <Types.LaneMovementType>();

        List <int> columns = new List <int>();
        List <int> rows    = new List <int>();

        GetValidLanes(ref columns, ref rows, ref potentialDirections);

        int rand;

        if (potentialDirections.Count != 0)
        {
            dir = potentialDirections[Random.Range(0, potentialDirections.Count)];

            switch (dir)
            {
            case Types.LaneMovementType.DOWN:
            case Types.LaneMovementType.UP:
                rand = Random.Range(0, columns.Count);
                col  = columns[rand];
                row  = GameConsts.GAME_LOGIC_INVALID;
                break;

            case Types.LaneMovementType.LEFT:
            case Types.LaneMovementType.RIGHT:
                rand = Random.Range(0, rows.Count);
                row  = rows[rand];
                col  = GameConsts.GAME_LOGIC_INVALID;
                break;

            default:
                col = row = GameConsts.GAME_LOGIC_INVALID;
                break;
            }
        }
        else
        {
            col = row = GameConsts.GAME_LOGIC_INVALID;
            //INVALID
            dir = Types.LaneMovementType.DOWN;
        }
    }
Example #13
0
    private void RandomizeLaneForOrder(out int col, out int row, out Types.LaneMovementType dir)
    {
        dir = (Types.LaneMovementType)Random.Range(0, System.Enum.GetValues(typeof(Types.LaneMovementType)).Length);

        switch (dir)
        {
        case Types.LaneMovementType.DOWN:
        case Types.LaneMovementType.UP:
            col = Random.Range(0, columnSize);
            row = GameConsts.GAME_LOGIC_INVALID;
            break;

        case Types.LaneMovementType.LEFT:
        case Types.LaneMovementType.RIGHT:
            row = Random.Range(0, rowSize);
            col = GameConsts.GAME_LOGIC_INVALID;
            break;

        default:
            col = row = GameConsts.GAME_LOGIC_INVALID;
            break;
        }
    }
Example #14
0
    public void MoveLane(int columnIndex, int rowIndex, Types.LaneMovementType movType)
    {
        Tile tempTile = null;

        switch (movType)
        {
        case Types.LaneMovementType.RIGHT:
            #region MOVING LANE RIGHT
            for (int x = columnSize - 1; x >= 0; x--)
            {
                if (boardSize[x, rowIndex].isOccupied)
                {
                    if (x == columnSize - 1)
                    {
                        SubscribeOnTileMovementEnded(boardSize[x, rowIndex].objInSlot.GetComponent <Tile>());
                        tempTile = FindObjectOfType <TilesManager>().CopyTile(boardSize[x, rowIndex].GetTile());
                        boardSize[x, rowIndex].CollapseTile(movType);
                    }
                    else if (x + 1 < columnSize)
                    {
                        MoveTile(boardSize[x, rowIndex].objInSlot, boardSize[x, rowIndex], boardSize[x + 1, rowIndex]);
                    }
                }

                if (x == 0)
                {
                    if (tempTile != null)
                    {
                        boardSize[x, rowIndex].UncollapseTile(movType, boardSize[x, rowIndex], tempTile);
                    }
                }
            }
            #endregion
            break;

        case Types.LaneMovementType.LEFT:
            #region MOVING LANE LEFT
            for (int x = 0; x < columnSize; x++)
            {
                if (boardSize[x, rowIndex].isOccupied)
                {
                    if (x == 0)
                    {
                        SubscribeOnTileMovementEnded(boardSize[x, rowIndex].objInSlot.GetComponent <Tile>());
                        tempTile = FindObjectOfType <TilesManager>().CopyTile(boardSize[x, rowIndex].GetTile());
                        boardSize[x, rowIndex].CollapseTile(movType);
                    }
                    else if (x < columnSize)
                    {
                        MoveTile(boardSize[x, rowIndex].objInSlot, boardSize[x, rowIndex], boardSize[x - 1, rowIndex]);
                    }
                }

                if (x == columnSize - 1)
                {
                    if (tempTile != null)
                    {
                        boardSize[x, rowIndex].UncollapseTile(movType, boardSize[x, rowIndex], tempTile);
                    }
                }
            }
            #endregion
            break;

        case Types.LaneMovementType.UP:
            #region MOVING LANE UP
            for (int x = rowSize - 1; x >= 0; x--)
            {
                if (boardSize[columnIndex, x].isOccupied)
                {
                    if (x == rowSize - 1)
                    {
                        SubscribeOnTileMovementEnded(boardSize[columnIndex, x].objInSlot.GetComponent <Tile>());
                        tempTile = FindObjectOfType <TilesManager>().CopyTile(boardSize[columnIndex, x].GetTile());
                        boardSize[columnIndex, x].CollapseTile(movType);
                    }
                    else if (x + 1 < rowSize)
                    {
                        MoveTile(boardSize[columnIndex, x].objInSlot, boardSize[columnIndex, x], boardSize[columnIndex, x + 1]);
                    }
                }

                if (x == 0)
                {
                    if (tempTile != null)
                    {
                        boardSize[columnIndex, x].UncollapseTile(movType, boardSize[columnIndex, x], tempTile);
                    }
                }
            }
            #endregion
            break;

        case Types.LaneMovementType.DOWN:
            #region MOVING LANE DOWN
            for (int x = 0; x < rowSize; x++)
            {
                if (boardSize[columnIndex, x].isOccupied)
                {
                    // COLLAPSING TILE
                    if (x == 0)
                    {
                        SubscribeOnTileMovementEnded(boardSize[columnIndex, x].objInSlot.GetComponent <Tile>());
                        tempTile = FindObjectOfType <TilesManager>().CopyTile(boardSize[columnIndex, x].GetTile());
                        boardSize[columnIndex, x].CollapseTile(movType);
                    }
                    // MOVING TILES
                    else if (x < rowSize)
                    {
                        MoveTile(boardSize[columnIndex, x].objInSlot, boardSize[columnIndex, x], boardSize[columnIndex, x - 1]);
                    }
                }

                // UNCOLLAPSING TILE
                if (x == rowSize - 1)
                {
                    if (tempTile != null)
                    {
                        boardSize[columnIndex, x].UncollapseTile(movType, boardSize[columnIndex, x], tempTile);
                    }
                }
            }
            #endregion
            break;
        }
    }
Example #15
0
    public static LaneMovementOrder CreateLaneMovementOrder(int colToMove, int rowToMove, Types.LaneMovementType dirToMove, int orderNumber)
    {
        GameObject newArrow = ArrowManager.SpawnArrowForLane(colToMove, rowToMove, dirToMove, orderNumber);

        LaneMovementOrder newOrder = new LaneMovementOrder(colToMove, rowToMove, dirToMove, newArrow);

        return(newOrder);
    }