Example #1
0
    private void CreateRandomTileAt(int row, int col)
    {
        float prob  = 0;
        int   index = Random.Range(0, levelData.tilePrefabs.Length);

        for (int i = 0; i < levelData.tilePrefabs.Length; i++)
        {
            int odds = Random.Range(0, 100); //Spawn will be completely random
            if (odds < ((levelData.tilePrefabs[i].probability + prob) * 10))
            {
                index = i;
                break; //end cicle
            }
            else
            {
                //accumulated probability
                prob += levelData.tilePrefabs[i].probability;
            }
        }
        Vector2  goalPos  = new Vector2(col + (spaceBetween * col), row + (spaceBetween * row));
        Vector2  startPos = new Vector2(col, startTilePosition);
        TileBase b        = SimplePool.instance.Spawn(levelData.tilePrefabs[index].tilePrefab, grid, startPos).GetComponent <TileBase>();

        board[row, col] = new BoardPiece(GridInfo.Playable, b, goalPos);
        b.OnBegin(row, col, startPos, goalPos);
    }
Example #2
0
    private void CreateObstacle(int row, int col)
    {
        GameObject prefab   = levelData.obstacle.tilePrefab;
        Vector2    goalPos  = new Vector2(col + (spaceBetween * col), row + (spaceBetween * row));
        Vector2    startPos = new Vector2(col, startTilePosition);
        TileBase   b        = SimplePool.instance.Spawn(prefab, grid, startPos).GetComponent <TileBase>();

        board[row, col] = new BoardPiece(GridInfo.Obstacle, b, goalPos);
        b.OnBegin(row, col, startPos, goalPos);
    }