Пример #1
0
    private void GenerateRoom()
    {
        if (map != null)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Vector3 pos = (new Vector3(-width / 2 + x + 0.5f, -height / 2 + y + 0.5f, 0)) / 2.1f;
                    if (map[x, y] == 1)
                    {
                        SpawnWall(pos, x, y);
                    }
                    else if (map[x, y] == 0)
                    {
                        GameObject background     = Instantiate(openArea, pos + mapOffset, transform.rotation, transform);
                        int        neighbourTiles = GetSurroundingWallCount(x, y);

                        if (neighbourTiles == 8)
                        {
                            SpawnWall(pos, x, y);
                            Destroy(background);
                        }

                        TileDirections    closestNeighbour = GetClosestNeighbours(x, y, 1);
                        RandomeBackground backgroundScript = background.GetComponent <RandomeBackground>();

                        if (closestNeighbour.down && !closestNeighbour.right && !closestNeighbour.left)
                        {
                            backgroundScript.isAboveGround = true;
                            spawnLocations.Add(backgroundScript.gameObject.transform);
                        }

                        backgroundScript.RandomSprite();

                        NeighbourLogic(closestNeighbour, null, backgroundScript);
                    }
                }
            }
        }
        //This happens when the room is done spawning in... maybe
        if (startArea)
        {
            mySpawner.SpawnPlayer(spawnLocations);
        }
        mySpawner.StartSpawning(spawnLocations);
    }
Пример #2
0
    private void GenerateRoom()
    {
        if (map != null)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Vector3 pos = (new Vector3(-width / 2 + x + 0.5f, -height / 2 + y + 0.5f, 0)) / 2.1f;
                    if (map[x, y] == 1)
                    {
                        SpawnWall(pos, x, y);
                    }
                    else if (map[x, y] == 0 /*|| map[x, y] == 2*/)
                    {
                        GameObject background     = Instantiate(openArea, pos + mapOffset, transform.rotation, transform);
                        int        neighbourTiles = GetSurroundingWallCount(x, y);

                        ///This adds random one spot walls
                        if (addExtraOneTiles)
                        {
                            int neighbours = GetMoreSouroundingWallCount(x, y);
                            int tmpRandom  = UnityEngine.Random.Range(0, 1000);
                            if (tmpRandom <= 6 && neighbours < 1)
                            {
                                SpawnWall(pos, x, y);
                                Destroy(background);
                            }
                        }
                        ///

                        if (neighbourTiles == 8)
                        {
                            SpawnWall(pos, x, y);
                            Destroy(background);
                        }

                        TileDirections    closestNeighbour = GetClosestNeighbours(x, y, 1);
                        RandomeBackground backgroundScript = background.GetComponent <RandomeBackground>();

                        if (closestNeighbour.down && !closestNeighbour.right && !closestNeighbour.left && !closestNeighbour.up)
                        {
                            backgroundScript.isAboveGround = true;
                            spawnLocations.Add(backgroundScript.transform);
                            floorCoords.Add(new Coord(x, y));

                            //TEmp
                            list.Add(backgroundScript.transform.position);
                        }

                        backgroundScript.RandomSprite();

                        NeighbourLogic(closestNeighbour, null, backgroundScript, x, y);
                    }
                }
            }

            WaterSpawner WS = GetComponentInChildren <WaterSpawner>();
            WS.roomGen = this;

            int tmp = UnityEngine.Random.Range(0, tmpX.Count);

            int momentaryX = tmpX[tmp];
            int momentaryY = tmpY[tmp];

            if (spawnWater)
            {
                WS.spawnLocations = waterSpawn;
                WS.SetList(momentaryX, momentaryY);
            }
        }

        //This is all happens after the room has fully spawned in!
        GetComponent <CompositeCollider2D>().GenerateGeometry();

        endCoord   = floorCoords[floorCoords.Count - 1];
        startCoord = floorCoords[0];

        mySpawner.StartSpawning(spawnLocations);

        if (startArea)
        {
            mySpawner.SpawnPlayer(spawnLocations);
        }
    }