Esempio 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);
     }
 }
Esempio n. 2
0
    private Room_ST createRoom(int roomSize, int roomNumber)
    {
        Room_ST newRoom = Instantiate(roomPrefab) as Room_ST;

        newRoom.transform.parent = transform;
        newRoom.name             = "Room " + roomNumber;
        minimizeOverlap(newRoom, roomSize);

        return(newRoom);
    }
Esempio n. 3
0
    private void makeWallTile(Vector3 indexFloat, Room_ST room)
    {
        Wall_ST newWall = Instantiate(wallPrefab) as Wall_ST;

        map[(int)indexFloat.x, (int)indexFloat.z] = newWall;
        newWall.name = "Wall " + indexFloat.x + ", " + indexFloat.z;
        //newWall.setIndex((int)indexFloat.x, (int)indexFloat.z);
        newWall.transform.parent        = room.transform;
        newWall.transform.localPosition = new Vector3(indexFloat.x - size * 0.5f + 0.5f, 0, indexFloat.z - size * 0.5f + 0.5f);
    }
Esempio n. 4
0
    private void makeFloorTile(Vector3 mapCoordFloat, Room_ST room)
    {
        Floor_ST newFloor = Instantiate(floorPrefab) as Floor_ST;

        map[(int)mapCoordFloat.x, (int)mapCoordFloat.z] = newFloor;
        newFloor.name = "Floor " + mapCoordFloat.x + ", " + mapCoordFloat.z;
        newFloor.setIndex((int)mapCoordFloat.x, (int)mapCoordFloat.z);
        newFloor.transform.parent        = room.transform;
        newFloor.transform.localPosition = new Vector3(mapCoordFloat.x - size * 0.5f + 0.5f, 0, mapCoordFloat.z - size * 0.5f + 0.5f);
    }
Esempio n. 5
0
    private Tile_ST[] sweep(Tile_ST[,] oMap, int x, int z, Tile_ST wallPrefab, Room_ST room)
    {
        Tile_ST[] nearTiles = new Tile_ST[8];

        for (int i = 0; i < nearTiles.Length; i++)
        {
            nearTiles[i] = findTile(oMap, x, z, i, wallPrefab, room);
        }

        return(nearTiles);
    }
Esempio n. 6
0
    private void wallAround(Tile_ST floor, Room_ST room)
    {
        for (int a = 0; a < 8; a++)
        {
            Vector3 index = floor.getIndex();

            if (!isFloor(a, ref index))
            {
                makeWallTile(index, room);
            }
        }
    }
Esempio n. 7
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;
        }
    }
Esempio n. 8
0
    private void minimizeOverlap(Room_ST room, int roomSize)
    {
        Room_ST[] allCreatedRooms = GetComponentsInChildren <Room_ST>();
        Vector3   areaCorner      = new Vector3(Random.Range(1, size), 0, Random.Range(1, size));
        bool      allClear        = false;
        int       index           = 0;

        room.setArea(areaCorner, roomSize, size);

        while (!allClear)
        {
            if (allCreatedRooms[index].name == room.name)
            {
                allClear = true;
            }

            if (!allClear)
            {
                float   centerOffset      = roomSize * 0.5f;
                Vector3 currentRoomCenter = room.getCenter();
                Vector3 testRoomCenter    = allCreatedRooms[index].getCenter();
                Vector3 vector            = testRoomCenter - currentRoomCenter;

                if (Mathf.Abs(vector.magnitude) <= centerOffset)
                {
                    areaCorner = new Vector3(Random.Range(1, roomSize), 0, Random.Range(1, roomSize));
                    room.setArea(areaCorner, roomSize, size);
                    index = 0;
                }
                else
                {
                    index++;
                }
            }
        }
    }
Esempio n. 9
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);
    }
Esempio n. 10
0
    private Tile_ST findTile(Tile_ST[,] tempMap, int x, int z, int index, Tile_ST wallPrefab, Room_ST room)
    {
        Tile_ST aTile = null;
        int     tempx = 0;
        int     tempz = 0;
        int     size  = 6;

        switch (index)
        {
        case 0:
            tempx = x;
            tempz = z + 1;
            aTile = tempMap[tempx, tempz];
            break;

        case 1:
            tempx = x + 1;
            tempz = z + 1;
            aTile = tempMap[tempx, tempz];
            break;

        case 2:
            tempx = x + 1;
            tempz = z;
            aTile = tempMap[x + 1, tempz];
            break;

        case 3:
            tempx = x + 1;
            tempz = z - 1;
            aTile = tempMap[tempx, tempz];
            break;

        case 4:
            tempx = x;
            tempz = z - 1;
            aTile = tempMap[tempx, tempz];
            break;

        case 5:
            tempx = x - 1;
            tempz = z - 1;
            aTile = tempMap[tempx, tempz];
            break;

        case 6:
            tempx = x - 1;
            tempz = z;
            aTile = tempMap[tempx, tempz];
            break;

        case 7:
            tempx = x - 1;
            tempz = z + 1;
            aTile = tempMap[tempx, tempz];
            break;
        }

        if (aTile == null)
        {
            aTile = Instantiate(wallPrefab) as Wall_ST;
            tempMap[tempx, tempz]         = aTile;
            aTile.name                    = "Wall " + tempx + ", " + tempz;
            aTile.transform.parent        = room.transform;
            aTile.transform.localPosition = new Vector3(tempx - size * 0.5f + 0.5f, 0, tempz - size * 0.5f + 0.5f);
        }

        return(aTile);
    }
Esempio n. 11
0
    public void addSurroundings(Tile_ST[,] originalMap, int x, int z, Tile_ST wallPrefab, Room_ST room)
    {
        mapIndex = new Vector3(x, 0, z);
        Tile_ST[] adjTiles = sweep(originalMap, x, z, wallPrefab, room);

        for (int k = 0; k < surroundings.Length; k++)
        {
            surroundings[k] = adjTiles[k];
            if (surroundings[k].tag == "Floor")
            {
                surroundings[k].addTile(this);
            }
        }
    }
Esempio n. 12
0
    private bool validTile(int direction, ref Vector3 coord, Room_ST room)
    {
        Vector3 tempCoord = new Vector3(coord.x, coord.y, coord.z);

        switch (direction)
        {
        case 1:
            // North: +z
            tempCoord.z += 1;
            if ((int)tempCoord.z < Mathf.Max((int)room.getC1Z(), (int)room.getC3Z()))
            {
                if (map[(int)tempCoord.x, (int)tempCoord.z] == null)
                {
                    coord.z = tempCoord.z;
                    return(true);
                }
            }
            break;

        case 2:
            // East: +x
            tempCoord.x += 1;
            if ((int)tempCoord.x < Mathf.Max((int)room.getC1X(), (int)room.getC3X()))
            {
                if (map[(int)tempCoord.x, (int)tempCoord.z] == null)
                {
                    coord.x = tempCoord.x;
                    return(true);
                }
            }
            break;

        case 3:
            // South: -z
            tempCoord.z -= 1;
            if ((int)tempCoord.z > Mathf.Min((int)room.getC1Z(), (int)room.getC3Z()))
            {
                if (map[(int)tempCoord.x, (int)tempCoord.z] == null)
                {
                    coord.z = tempCoord.z;
                    return(true);
                }
            }
            break;

        case 4:
            // West: -x
            tempCoord.x -= 1;
            if ((int)tempCoord.x > Mathf.Min((int)room.getC1X(), (int)room.getC3X()))
            {
                if (map[(int)tempCoord.x, (int)tempCoord.z] == null)
                {
                    coord.x = tempCoord.x;
                    return(true);
                }
            }
            break;
        }

        return(false);
    }