Ejemplo n.º 1
0
    public void StartBattle()
    {
        //For some reason, arrays need to be initialized at runtime
        currentBoardSize = new int[2];
        //Usage of enums to determine which tile configuration we will use. This should hopefully make it more scalable
        tileSet tileSetRef = tileSet.THREExEIGHT;
        //Keeping a reference to the board manager at all times then a holder variable that can be manipulated freely
        Vector3 selfPosition = transform.position;
        Vector3 newPos       = selfPosition;

        //Setting the current size of the board
        currentBoardSize[0] = boardRatios[(int)tileSetRef].x;
        currentBoardSize[1] = boardRatios[(int)tileSetRef].y;
        //BoardManager will be in the top left and tiles will spawn to the right and below it. For loop gets the x THEN the y
        for (int i = 0; i < currentBoardSize[0]; i++)
        {
            for (int j = 0; j < currentBoardSize[1]; j++)
            {
                //Instantiates a tileRef then sets it to the tileBoard
                tileBoard.rows[i].column[j] = Instantiate(tileReference, newPos, Quaternion.identity);
                tileBoard.rows[i].column[j].transform.parent = transform;
                tileBoard.rows[i].column[j].pos = new Vector2Int(i, j);
                newPos += new Vector3(0, 0, 2.5f);
            }
            //Sets the position for the next row
            newPos = selfPosition + (new Vector3(2.5f, 0, 0) * (i + 1));
        }

        if (OnBeginRound != null)
        {
            OnBeginRound();
        }
    }
Ejemplo n.º 2
0
    private void Awake()
    {
        SetUpTiles();
        for (int i = 0; i < tileSetList.Count; i++)
        {
            tileSet tS = tileSetList[i];

            if (i > 0)
            {
                tS.minProp = tileSetList[i - 1].maxProp;
                tS.maxProp = tS.minProp + tS.propability;
            }
            else
            {
                tS.minProp = 0;
                tS.maxProp = tS.minProp + tS.propability;
            }
        }
    }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject foliage = GameObject.Find("foliage");

        fscript            = foliage.GetComponent <flowerSet>();
        flowerRef          = foliage.GetComponent <Tilemap>();
        transform.position = new Vector3(fscript.startX + 2.5f, fscript.startY + 2.5f, -2);
        rend = GetComponent <SpriteRenderer>();

        GameObject ground = GameObject.Find("ground");

        groundtiles = ground.GetComponent <tileSet>();

        GameObject canvas = GameObject.Find("Canvas");

        scoreB = canvas.GetComponent <scoreboard>();

        mainCamera = Camera.main;
        mainCamera.transform.position = new Vector3(transform.position.x, transform.position.y, -10);
    }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject ground      = GameObject.Find("ground");
        tileSet    groundtiles = ground.GetComponent <tileSet>();

        total = groundtiles.total;

        GameObject foliage = GameObject.Find("foliage");

        fscript   = foliage.GetComponent <flowerSet>();
        flowerRef = foliage.GetComponent <Tilemap>();

        GameObject canvas = GameObject.Find("Canvas");

        scoreB = canvas.GetComponent <scoreboard>();

        player = GameObject.Find("player");
        pInfo  = player.GetComponent <playerControls>();

        gauges = new int[children];
        scores = new int[children];


        for (int i = 0; i < children; i++)
        {
            Instantiate(enemies, transform);
            gauges[i] = 0;
            scores[i] = 0;
        }
        startPosX = fscript.startX + 2.5f;
        startPosY = fscript.startY + 2.5f;
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            child.transform.position = new Vector3(startPosX, startPosY, -1);
        }
    }
Ejemplo n.º 5
0
    // Start is called before the first frame update
    void Start()
    {
        Tilemap map = GetComponent <Tilemap>();

        range = 100;

        GameObject ground      = GameObject.Find("ground");
        tileSet    groundtiles = ground.GetComponent <tileSet>();

        total = groundtiles.total;

        player = GameObject.Find("player");
        pInfo  = player.GetComponent <playerControls>();


        small = new Tile[5] {
            sFlower1, sFlower2, sFlower3, mushroom, sRock
        };
        big = new Tile[5] {
            bFlower1, bFlower2, bFlower3, sBush, bRock
        };
        unuseable = new Tile[4] {
            unuseS, unusebigR, unusebigP, unusebigL
        };
        availablegrid = new int[groundtiles.total, groundtiles.total];
        flowerTiles   = new int[groundtiles.total, groundtiles.total];
        for (int y = 0; y < groundtiles.total; y++)
        {
            for (int x = 0; x < groundtiles.total; x++)
            {
                availablegrid[y, x] = 1;
                flowerTiles[y, x]   = 0;
            }
        }

        startX = Random.Range((groundtiles.total / 4), (groundtiles.total / 4) * 3);
        startY = Random.Range((groundtiles.total / 4), (groundtiles.total / 2));
        bool hivePlaced = false;

        while (!hivePlaced)
        {
            if (groundtiles.grid[startY, startX] == 1 && groundtiles.grid[startY, startX + 1] == 1 && groundtiles.grid[startY, startX + 2] == 1 && groundtiles.grid[startY, startX + 3] == 1 && groundtiles.grid[startY, startX + 4] == 1 &&
                groundtiles.grid[startY + 1, startX] == 1 && groundtiles.grid[startY + 1, startX + 1] == 1 && groundtiles.grid[startY + 1, startX + 2] == 1 && groundtiles.grid[startY + 1, startX + 3] == 1 && groundtiles.grid[startY + 1, startX + 4] == 1 &&
                groundtiles.grid[startY + 2, startX] == 1 && groundtiles.grid[startY + 2, startX + 1] == 1 && groundtiles.grid[startY + 2, startX + 2] == 1 && groundtiles.grid[startY + 2, startX + 3] == 1 && groundtiles.grid[startY + 2, startX + 4] == 1 &&
                groundtiles.grid[startY + 3, startX] == 1 && groundtiles.grid[startY + 3, startX + 1] == 1 && groundtiles.grid[startY + 3, startX + 2] == 1 && groundtiles.grid[startY + 3, startX + 3] == 1 && groundtiles.grid[startY + 3, startX + 4] == 1 &&
                groundtiles.grid[startY + 4, startX] == 1 && groundtiles.grid[startY + 4, startX + 1] == 1 && groundtiles.grid[startY + 4, startX + 2] == 1 && groundtiles.grid[startY + 4, startX + 3] == 1 && groundtiles.grid[startY + 4, startX + 4] == 1)
            {
                for (int y = 0; y < 5; y++)
                {
                    for (int x = 0; x < 5; x++)
                    {
                        availablegrid[startY + y, startX + x] = 0;
                    }
                }

                map.SetTile(new Vector3Int(startX, startY, 0), hive);
                hivePlaced = true;
            }
            else if (startX < groundtiles.total - 3)
            {
                startX += 1;
            }
            else
            {
                startX  = 0;
                startY += 1;
            }
        }

        for (int i = 0; i < children; i++)
        {
            Instantiate(worm, transform);
        }

        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child       = transform.GetChild(i);
            int       x           = Random.Range(0, (groundtiles.total / 4) * 3);
            int       y           = Random.Range(0, (groundtiles.total / 4) * 3);
            bool      childPlaced = false;
            while (!childPlaced)
            {
                if (y - 1 >= 0 && x - 1 >= 0 && y + 1 < groundtiles.total && x + 1 < groundtiles.total &&
                    groundtiles.grid[y, x] == 1 && availablegrid[y, x] == 1)
                {
                    child.localPosition         = new Vector3Int(x, y, 0);
                    availablegrid[y, x]         = 0;
                    availablegrid[y - 1, x + 1] = 0;
                    availablegrid[y + 1, x - 1] = 0;
                    availablegrid[y - 1, x - 1] = 0;
                    availablegrid[y + 1, x + 1] = 0;
                    childPlaced = true;
                }
                else if (x < groundtiles.total)
                {
                    x += 1;
                }
                else
                {
                    x  = 0;
                    y += 1;
                }
            }
        }

        Debug.Log(startX);
        Debug.Log(startY);

        for (int y = 0; y < groundtiles.total; y++)
        {
            for (int x = 0; x < groundtiles.total; x++)
            {
                if (availablegrid[y, x] == 1)
                {
                    int choice = Random.Range(0, range);
                    if ((y + 1 < groundtiles.total && availablegrid[y + 1, x] == 1 &&
                         x + 1 < groundtiles.total && availablegrid[y, x + 1] == 1 && availablegrid[y + 1, x + 1] == 1) &&
                        ((choice < 30 && groundtiles.grid[y, x] == 0 && groundtiles.grid[y + 1, x] == 0 && groundtiles.grid[y, x + 1] == 0 && groundtiles.grid[y + 1, x + 1] == 0) ||
                         (choice < 10 && groundtiles.grid[y, x] == 1 && groundtiles.grid[y + 1, x] == 1 && groundtiles.grid[y, x + 1] == 1 && groundtiles.grid[y + 1, x + 1] == 1)))
                    {
                        int which;
                        if (choice >= 1 && groundtiles.grid[y, x] == 1 && groundtiles.grid[y + 1, x] == 1 && groundtiles.grid[y, x + 1] == 1 && groundtiles.grid[y + 1, x + 1] == 1)
                        {
                            which = Random.Range(3, 5);
                            map.SetTile(new Vector3Int(x, y, 0), big[which]);
                        }
                        else
                        {
                            which = Random.Range(0, 3);
                            map.SetTile(new Vector3Int(x, y, 0), big[which]);
                        }
                        for (int plusy = 0; plusy < 2; plusy++)
                        {
                            for (int plusx = 0; plusx < 2; plusx++)
                            {
                                availablegrid[y + plusy, x + plusx] = 0;
                                if (which >= 0 && which < 3)
                                {
                                    flowerTiles[y, x] = 1;
                                    flowerNumbers    += 1;
                                }
                            }
                        }
                    }
                    else if ((groundtiles.grid[y, x] == 0 && choice < 80) || (groundtiles.grid[y, x] == 1 && choice < 15))
                    {
                        if (choice >= 4 && groundtiles.grid[y, x] == 1)
                        {
                            map.SetTile(new Vector3Int(x, y, 0), small[Random.Range(3, 5)]);
                        }
                        else
                        {
                            map.SetTile(new Vector3Int(x, y, 0), small[Random.Range(0, 3)]);
                            flowerTiles[y, x] = 1;
                            flowerNumbers    += 1;
                        }
                        availablegrid[y, x] = 0;
                    }
                    else if ((groundtiles.grid[y, x] == 1 && y + 1 < groundtiles.total && groundtiles.grid[y + 1, x] == 1 && availablegrid[y + 1, x] == 1 && y + 2 < groundtiles.total && groundtiles.grid[y + 2, x] == 1 && availablegrid[y + 2, x] == 1 &&
                              x + 1 < groundtiles.total && groundtiles.grid[y, x + 1] == 1 && availablegrid[y, x + 1] == 1 && groundtiles.grid[y + 1, x + 1] == 1 && availablegrid[y + 1, x + 1] == 1 && groundtiles.grid[y + 2, x + 1] == 1 && availablegrid[y + 2, x + 1] == 1 &&
                              x + 2 < groundtiles.total && groundtiles.grid[y, x + 2] == 1 && availablegrid[y, x + 2] == 1 && groundtiles.grid[y + 1, x + 2] == 1 && availablegrid[y + 1, x + 2] == 1 && groundtiles.grid[y + 2, x + 2] == 1 && availablegrid[y + 2, x + 2] == 1) &&
                             choice >= 50 && choice < 55)
                    {
                        int whichBig = Random.Range(0, 3);
                        if (whichBig == 0)
                        {
                            map.SetTile(new Vector3Int(x, y, 0), bBush);
                            for (int plusy = 0; plusy < 3; plusy++)
                            {
                                for (int plusx = 0; plusx < 3; plusx++)
                                {
                                    availablegrid[y + plusy, x + plusx] = 0;
                                }
                            }
                        }
                        else if (whichBig == 1)
                        {
                            map.SetTile(new Vector3Int(x, y, 0), wide);
                            for (int plusy = 0; plusy < 2; plusy++)
                            {
                                for (int plusx = 0; plusx < 3; plusx++)
                                {
                                    availablegrid[y + plusy, x + plusx] = 0;
                                }
                            }
                        }
                        else
                        {
                            map.SetTile(new Vector3Int(x, y, 0), tall);
                            for (int plusy = 0; plusy < 3; plusy++)
                            {
                                for (int plusx = 0; plusx < 2; plusx++)
                                {
                                    availablegrid[y + plusy, x + plusx] = 0;
                                }
                            }
                        }
                    }
                }
            }
        }
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            int       x     = (int)child.transform.position.x;
            int       y     = (int)child.transform.position.y;
            availablegrid[y - 1, x + 1] = 1;
            availablegrid[y + 1, x - 1] = 1;
            availablegrid[y - 1, x - 1] = 1;
            availablegrid[y + 1, x + 1] = 1;
        }
    }