示例#1
0
    public void OnPiecePlaced(RepairPiece placedPiece)
    {
        for (int i = 0; i < _createdPieces.Length; i++)
        {
            RepairPiece item = _createdPieces[i];
            if (item != placedPiece)
            {
                Destroy(item.gameObject);
            }
            _createdPieces[i] = null;
        }

        CreatePieces();
    }
示例#2
0
    public void OnPiecePlacedCorrectly(RepairPiece piece)
    {
        _currentScore += piece.BoxPositions.Length;
        _completePerc  = (float)_currentScore / BuildingController.Instance.ScoreAvailable;
        PieceFactory.Instance.OnPiecePlaced(piece);

        if (DoneThreshold < _completePerc && !DoneButton.isActiveAndEnabled)
        {
            Debug.Log("Enable");
            DoneButton.gameObject.SetActive(true);
        }

        if (_completePerc == 1f)
        {
            EndGame(true);
        }
    }
示例#3
0
 private void DisposePiece(RepairPiece p)
 {
     Destroy(p.gameObject);
 }
示例#4
0
    public bool TryPlacingPiece(RepairPiece piece, out Vector2 snapPos)
    {
        //piece.PiecePattern.LeadPosition
        float   distance = float.PositiveInfinity;
        Vector2 piecePos = piece.LeadingBox.position;
        float   tempDist;
        int     y = 0, x = 0;

        for (int i = 0; i < _grid.Length; i++)
        {
            GridSlot[] item = (GridSlot[])_grid[i];
            for (int j = 0; j < item.Length; j++)
            {
                GridSlot slot = (GridSlot)item[j];
                tempDist = Vector2.Distance(slot.Pos, piecePos);
                if (tempDist < distance)
                {
                    //Debug.Log(i + "/" + j + " closest distance " + tempDist);
                    distance = tempDist;
                    y        = i;
                    x        = j;
                }
            }
        }
        GridSlot gs = _grid[y][x];

        bool inSlot = false;

        if (distance < MaxPlacementDistance && gs.Value == 0)
        {
            snapPos = gs.Pos;
            inSlot  = true;
        }
        else
        {
            snapPos = Vector2.zero;
            inSlot  = false;
            return(false);
        }
        Vector2Int        coord = new Vector2Int(x, y);
        List <Vector2Int> sum   = new List <Vector2Int>();

        //sum my bitch up DUUUUU du du duuu dududu
        foreach (Vector2 boxPos in piece.PiecePattern.BoxPositions)
        {
            Vector2 diff = piece.PiecePattern.PositionalDifference(boxPos);
            diff = coord - diff;
            int value = _grid[(int)diff.y][(int)diff.x].Value;

            //Debug.Log(value);
            if (value > 0)
            {
                Debug.Log("OVERLAPPING!");
                return(false);
            }
            else
            {
                sum.Add(new Vector2Int((int)diff.y, (int)diff.x));
            }
        }
        bool grounded = false;

        foreach (var boxPos in piece.PiecePattern.BoxPositions)
        {
            Vector2    p    = piece.PiecePattern.PositionalDifference(boxPos);
            Vector2Int pInt = new Vector2Int((int)p.x, (int)p.y);
            pInt    = coord - pInt;
            pInt.y -= 1;
            if (_grid[pInt.y][pInt.x].Value > 0)
            {
                grounded = true;
            }
        }
        if (!grounded)
        {
            Debug.Log("NOT GROUNDED!");
            return(false);
        }

        foreach (var item in sum)
        {
            _grid[item.x][item.y].Value++;
        }
        Debug.Log("yes");
        return(inSlot);
    }