예제 #1
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;
        }
    }
예제 #2
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);
    }