Ejemplo n.º 1
0
    public RoomTile[,] GenerateRoom(int size)
    {
        // instantiate tiles
        size += 2;
        RoomTile[,] tiles = new RoomTile[size, size];
        roomTypes         = new RoomTile.Type[size, size];
        for (int j = 0; j < tiles.GetLength(1); ++j)
        {
            for (int i = 0; i < tiles.GetLength(0); ++i)
            {
                RoomTile _tile = Instantiate(roomTile, Vector2.up * j + Vector2.right * i, Quaternion.Euler(Vector3.zero));
                tiles[i, j] = _tile;
            }
        }

        SetupTileTypes(tiles);
        if (PlayerPrefs.GetInt("Level") % 6 != 5)
        {
            try
            {
                SetupWalls(tiles);
            }
            catch (System.Exception e)
            {
                print(e.Message);
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
        }
        PaintBackground(tiles);
        PaintWalls(tiles);
        //DebugTiles();

        return(tiles);
    }
Ejemplo n.º 2
0
        public int PlaceTemplate(ref RoomTile[,] room, ref float[,] rotations, int seedR, int seedC)
        {
            int nr = room.GetLength(0);
            int nc = room.GetLength(1);
            int tr = Template.GetLength(0);
            int tc = Template.GetLength(1);

            for(int r = 0; r < tr; r++)
            {
                for(int c = 0; c < tc; c++)
                {
                    int x = seedR + r;
                    int y = seedC + c;

                    RoomTile desired = Template[r, c];

                    // Ignore tiles with unspecified conditions
                    if(desired == RoomTile.None)
                    {
                        continue;
                    }

                    bool hasWall = Has(desired, RoomTile.Wall);
                    bool hasOpen = Has(desired, RoomTile.Open);
                    bool hasEdge = Has(desired, RoomTile.Edge);
                    bool onEdge = (x >= nr - 1 || y >= nc - 1 || x < 1 || y < 1);
                    bool outOfBounds = onEdge && (x >= nr  || y >= nc  || x < 0 || y < 0);
                    if(onEdge && !hasEdge)
                    {
                        return -1;
                    }
                    else if(outOfBounds && desired != RoomTile.None)
                    {
                        return -1;
                    }
                    else if(outOfBounds)
                    {
                        continue;
                    }

                    RoomTile curent = room[x, y];

                    bool meetsWallRequirements = !hasWall || (curent == RoomTile.Wall);
                    bool meetsEdgeRequirements = (!hasEdge && !hasWall) || (hasEdge && curent == RoomTile.Edge);
                    bool meetsOpenRequriments = !hasOpen || (curent == RoomTile.Open);
                    bool doesntIntersect = hasEdge || hasWall || curent == RoomTile.Open;

                    // Tiles conflict when walls exist in the BuildRoom already, or other objects
                    // block the template.
                    if (!(((meetsWallRequirements || meetsEdgeRequirements) && meetsOpenRequriments && doesntIntersect)))
                    {
                        return -1;
                    }
                }
            }

            int toReturn = 0;
            // Otherwise, we return the number of tiles which could be successfully placed.
            for(int r = 0; r < tr; r++)
            {
                for(int c = 0; c < tc; c++)
                {
                    int x = seedR + r;
                    int y = seedC + c;

                    if(x >= nr - 1 || y >= nc - 1 || x <= 0 || y <= 0)
                    {
                        continue;
                    }

                    RoomTile desiredTile = Template[r, c];
                    RoomTile unimport = Accessories[r, c];
                    RoomTile currentTile = room[x, y];

                    if((currentTile == RoomTile.Open || currentTile == RoomTile.Edge) && desiredTile != RoomTile.None && !Has(desiredTile, RoomTile.Edge) && ! Has(desiredTile, RoomTile.Wall) && desiredTile != RoomTile.Open)
                    {
                        room[x, y] = desiredTile;
                        rotations[x, y] = Rotation;
                        toReturn++;
                    }

                    if((currentTile != RoomTile.Open && currentTile != RoomTile.Edge) || unimport == RoomTile.Open || unimport == RoomTile.None || unimport == RoomTile.Edge)
                    {
                        continue;
                    }

                    room[x, y] = unimport;
                    toReturn++;
                }
            }

            return toReturn;
        }