Ejemplo n.º 1
0
    //spawn houses
    void spawnHouses()
    {
        //spawn houses
        while (startingNumberOfHouses > 0)
        {
            // Makes things more random APPARENTLY
            Random.InitState((int)System.DateTime.Now.Ticks);

            //assign x position a random number for spawn
            xPos = Random.Range(offsetDistance + 2, (int)startingWidth + 1);

            //assign y position a random number for spawn
            yPos = Random.Range(offsetDistance + 3, (int)startingHeight - 1);

            //determine if generated position is empty
            if (BuildFunctions.IsGridSpaceEmpty(new Vector3(xPos, yPos, 0)))
            {
                //determine if position already has an instance next to it
                if (BuildFunctions.CheckSurroundingGridSpaces(new Vector3(xPos, yPos, 0), house))
                {
                    //create instance
                    Instantiate(house, new Vector3(xPos, yPos, 0), transform.rotation);

                    //set space in grid
                    BuildFunctions.SetGridSpace(house, new Vector3(xPos, yPos, 0));

                    //decrement counter
                    startingNumberOfHouses--;

                    houseAmount++;
                }
            }
        }
    }
Ejemplo n.º 2
0
    //spawn trees
    void spawnTrees()
    {
        //spawn trees
        while (startingNumberOfTrees > 0)
        {
            //assign x position a random number for spawn
            xPos = Random.Range(offsetDistance + 2, maxWidth);

            //assign y position a random number for spawn
            yPos = Random.Range(offsetDistance + 3, maxHeight);

            //determine if generated position is empty
            if (BuildFunctions.IsGridSpaceEmpty(new Vector3(xPos, yPos, 0)))
            {
                //determine if position already has an instance next to it
                if (BuildFunctions.CheckSurroundingGridSpaces(new Vector3(xPos, yPos, 0), tree))
                {
                    //create instance
                    Instantiate(tree, new Vector3(xPos, yPos, 0), transform.rotation);

                    //set space in grid
                    BuildFunctions.SetGridSpace(tree, new Vector3(xPos, yPos, 0));

                    //decrement counter
                    startingNumberOfTrees--;
                }
            }
        }
    }
Ejemplo n.º 3
0
    public void spawnMoreHouses(int housesToBeAdded)
    {
        int limiter = 50;

        while (housesToBeAdded > 0)
        {
            //determine the amount of usable gridspaces
            currentWidth  = mainCamera.ScreenToWorldPoint(new Vector3(mainCamera.pixelWidth, mainCamera.pixelHeight, 0)).x - .5f;
            currentHeight = mainCamera.ScreenToWorldPoint(new Vector3(mainCamera.pixelWidth, mainCamera.pixelHeight, 0)).y - .5f;



            //assign x position a random number for spawn
            xPos = Random.Range(offsetDistance + 2, (int)currentWidth + 1);

            //assign y position a random number for spawn
            yPos = Random.Range(offsetDistance + 3, (int)currentHeight);

            //determine if generated position is empty
            if (BuildFunctions.IsGridSpaceEmpty(new Vector3(xPos, yPos, 0)))
            {
                //determine if position already has an instance next to it
                if (BuildFunctions.CheckSurroundingGridSpaces(new Vector3(xPos, yPos, 0), house))
                {
                    //create instance
                    Instantiate(house, new Vector3(xPos, yPos, 0), transform.rotation);

                    //set space in grid
                    BuildFunctions.SetGridSpace(house, new Vector3(xPos, yPos, 0));

                    houseAmount++;
                    housesToBeAdded--;
                }
            }

            limiter--;
            if (limiter <= 0)
            {
                break;
            }
        }
    }