Exemplo n.º 1
0
 private void createWalls(Room_ST room)
 {
     Tile_ST[] roomFloor = room.GetComponentsInChildren <Tile_ST>();
     for (int e = 0; e < roomFloor.Length; e++)
     {
         wallAround(roomFloor[e], room);
     }
 }
Exemplo n.º 2
0
    private void createFloors(Room_ST room)
    {
        int availableTiles = totalRoomNum * totalRoomNum;
        int tilesToBeUsed  = Random.Range(Mathf.RoundToInt(availableTiles * 0.5f), Mathf.RoundToInt(availableTiles * 0.75f));

        Vector3 newTileCoord = new Vector3(Random.Range(Mathf.Min((int)room.getC1X(), (int)room.getC3X()), Mathf.Max((int)room.getC1X(), (int)room.getC3X())), 0, Random.Range(Mathf.Min((int)room.getC1Z(), (int)room.getC3Z()), Mathf.Max((int)room.getC1Z(), (int)room.getC3Z())));

        while (map[(int)newTileCoord.x, (int)newTileCoord.z] != null)
        {
            newTileCoord = Vector3.zero;
            newTileCoord = new Vector3(Random.Range(Mathf.Min((int)room.getC1X(), (int)room.getC3X()), Mathf.Max((int)room.getC1X(), (int)room.getC3X())), 0, Random.Range(Mathf.Min((int)room.getC1Z(), (int)room.getC3Z()), Mathf.Max((int)room.getC1Z(), (int)room.getC3Z())));
        }

        Vector3 coordCheck = new Vector3(newTileCoord.x, newTileCoord.y, newTileCoord.z);
        int     index      = 0;

        while (index < tilesToBeUsed)
        {
            makeFloorTile(newTileCoord, room);
            newTileCoord = chooseNextTile(newTileCoord, room);

            if (coordCheck.x == newTileCoord.x && coordCheck.z == newTileCoord.z)
            {
                Tile_ST[] floors = room.GetComponentsInChildren <Floor_ST>();
                if (floors.Length == 1)
                {
                    Destroy(floors[0].gameObject);
                    newTileCoord = new Vector3(Random.Range(Mathf.Min((int)room.getC1X(), (int)room.getC3X()), Mathf.Max((int)room.getC1X(), (int)room.getC3X())), 0, Random.Range(Mathf.Min((int)room.getC1Z(), (int)room.getC3Z()), Mathf.Max((int)room.getC1Z(), (int)room.getC3Z())));

                    while (map[(int)newTileCoord.x, (int)newTileCoord.z] != null)
                    {
                        newTileCoord = Vector3.zero;
                        newTileCoord = new Vector3(Random.Range(Mathf.Min((int)room.getC1X(), (int)room.getC3X()), Mathf.Max((int)room.getC1X(), (int)room.getC3X())), 0, Random.Range(Mathf.Min((int)room.getC1Z(), (int)room.getC3Z()), Mathf.Max((int)room.getC1Z(), (int)room.getC3Z())));
                    }
                    index = -1;
                }
                else
                {
                    break;
                }
            }

            coordCheck.x = newTileCoord.x;
            coordCheck.z = newTileCoord.z;

            index += 1;
        }
    }
Exemplo n.º 3
0
    private Vector3 chooseNextTile(Vector3 mapCoordFloat, Room_ST room)
    {
        int rand;

        int[]   choices1  = { 1, 2, 3, 4 };
        Vector3 nextCoord = new Vector3(mapCoordFloat.x, mapCoordFloat.y, mapCoordFloat.z);

        for (int w = 0; w < choices1.Length; w++)
        {
            rand = Random.Range(w, choices1.Length);

            if (validTile(choices1[rand], ref nextCoord, room))
            {
                return(nextCoord);
            }
            choices1[rand] = choices1[w];
        }

        Tile_ST[] floorTiles = room.GetComponentsInChildren <Floor_ST>();

        for (int j = 0; j < floorTiles.Length; j++)
        {
            int[] choices2 = { 1, 2, 3, 4 };
            nextCoord = floorTiles[j].getIndex();

            for (int k = 0; k < choices2.Length; k++)
            {
                if (validTile(choices2[k], ref nextCoord, room))
                {
                    return(nextCoord);
                }
            }
        }

        return(mapCoordFloat);
    }