Example #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);
    }
Example #2
0
    public void NeighbourLogic(TileDirections closestNeighbour, Wall currentWall, RandomeBackground backgroundScript, int x, int y)
    {
        if (currentWall != null)
        {
            //If its a edge tile this happens
            if (closestNeighbour.edge)
            {
                if (closestNeighbour.wallNeighbours == 4)
                {
                    currentWall.innerWall = true;
                    return;
                }
                if (closestNeighbour.downEdge)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.rightEdge)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.upEdge)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.leftEdge)
                {
                    currentWall.Rotate(4, true);
                }
                return;
            }

            //This happens if you have three neighbours
            if (closestNeighbour.wallNeighbours == 3)
            {
                if (closestNeighbour.up)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.right)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.down)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.left)
                {
                    currentWall.Rotate(4, true);
                }
            }

            //This is the logic for if you have 4 neighbours
            if (closestNeighbour.wallNeighbours == 4)
            {
                currentWall.innerWall = true;
                return;
            }

            //This happens if you have no neighbours
            if (closestNeighbour.wallNeighbours == 0)
            {
                currentWall.SoloWall();
            }

            //This happens if you only have one neighbour
            if (closestNeighbour.wallNeighbours == 1)
            {
                //Pointing up
                if (closestNeighbour.left && closestNeighbour.up && closestNeighbour.right)
                {
                    currentWall.EndWall(1);
                }

                //Pointing right
                if (closestNeighbour.up && closestNeighbour.right && closestNeighbour.down)
                {
                    currentWall.EndWall(2);
                }

                //Pointing down
                if (closestNeighbour.right && closestNeighbour.down && closestNeighbour.left)
                {
                    currentWall.EndWall(3);
                }

                //Pointing left
                if (closestNeighbour.down && closestNeighbour.left && closestNeighbour.up)
                {
                    currentWall.EndWall(4);
                }
            }


            //This happens if you have 2 neighbours
            if (closestNeighbour.wallNeighbours == 2)
            {
                if (closestNeighbour.left && closestNeighbour.up)
                {
                    //Top left corner
                    currentWall.CornerLogic(1);
                }
                if (closestNeighbour.up && closestNeighbour.right)
                {
                    //Top right corner
                    currentWall.CornerLogic(2);
                }
                if (closestNeighbour.right && closestNeighbour.down)
                {
                    //Bottom right corner
                    currentWall.CornerLogic(3);
                }
                if (closestNeighbour.down && closestNeighbour.left)
                {
                    //Bottom left corner
                    currentWall.CornerLogic(4);
                }
                if (closestNeighbour.up && closestNeighbour.down)
                {
                    //up and down is walls
                    currentWall.CornerLogic(5);
                }
                if (closestNeighbour.right && closestNeighbour.left)
                {
                    //left and right is walls
                    currentWall.CornerLogic(6);
                }
            }
        }
        else
        {
            if (closestNeighbour.up)
            {
                backgroundScript.RoofSpikes();
            }
            if (closestNeighbour.down)
            {
                backgroundScript.RandomPlant();
            }

            if (closestNeighbour.up && !closestNeighbour.left && !closestNeighbour.right)
            {
                backgroundScript.canSpawnWater = true;
                waterSpawn.Add(backgroundScript);

                tmpX.Add(x);
                tmpY.Add(y);

                ceilSpawn.Add(new Vector3((-width / 2f + x + 0.5f), (-height / 2f + y), 0) * GameManager.globalScale);
            }
        }
    }
Example #3
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);
        }
    }
Example #4
0
    public void NeighbourLogic(TileDirections closestNeighbour, Wall currentWall, RandomeBackground backgroundScript)
    {
        if (currentWall != null)
        {
            //If its a edge tile this happens
            if (closestNeighbour.edge)
            {
                if (closestNeighbour.wallNeighbours == 4)
                {
                    currentWall.innerWall = true;
                    return;
                }
                if (closestNeighbour.downEdge)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.rightEdge)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.upEdge)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.leftEdge)
                {
                    currentWall.Rotate(4, true);
                }
                return;
            }

            //This happens if you have three neighbours
            if (closestNeighbour.wallNeighbours == 3)
            {
                if (closestNeighbour.up)
                {
                    currentWall.Rotate(1, true);
                }
                if (closestNeighbour.right)
                {
                    currentWall.Rotate(2, true);
                }
                if (closestNeighbour.down)
                {
                    currentWall.Rotate(3, true);
                }
                if (closestNeighbour.left)
                {
                    currentWall.Rotate(4, true);
                }
            }

            //This is the logic for if you have 4 neighbours
            if (closestNeighbour.wallNeighbours == 4)
            {
                currentWall.innerWall = true;
                return;
            }

            //This happens if you have no neighbours
            if (closestNeighbour.wallNeighbours == 0)
            {
                currentWall.SoloWall();
            }

            //This happens if you only have one neighbour
            if (closestNeighbour.wallNeighbours == 1)
            {
                //Pointing up
                if (closestNeighbour.left && closestNeighbour.up && closestNeighbour.right)
                {
                    currentWall.EndWall(1);
                }

                //Pointing right
                if (closestNeighbour.up && closestNeighbour.right && closestNeighbour.down)
                {
                    currentWall.EndWall(2);
                }

                //Pointing down
                if (closestNeighbour.right && closestNeighbour.down && closestNeighbour.left)
                {
                    currentWall.EndWall(3);
                }

                //Pointing left
                if (closestNeighbour.down && closestNeighbour.left && closestNeighbour.up)
                {
                    currentWall.EndWall(4);
                }
            }


            //This happens if you have 2 neighbours
            if (closestNeighbour.wallNeighbours == 2)
            {
                if (closestNeighbour.left && closestNeighbour.up)
                {
                    //Top left corner
                    currentWall.CornerLogic(1);
                }
                if (closestNeighbour.up && closestNeighbour.right)
                {
                    //Top right corner
                    currentWall.CornerLogic(2);
                }
                if (closestNeighbour.right && closestNeighbour.down)
                {
                    //Bottom right corner
                    currentWall.CornerLogic(3);
                }
                if (closestNeighbour.down && closestNeighbour.left)
                {
                    //Bottom left corner
                    currentWall.CornerLogic(4);
                }
            }
        }
        else
        {
            if (closestNeighbour.up)
            {
                backgroundScript.RoofSpikes();
            }
            if (closestNeighbour.down)
            {
                backgroundScript.RandomPlant();
            }
        }
    }