예제 #1
0
    public void GenerateMap(ref int[] map, BaseMapContext mapGenContext)
    {
        _context    = (BSPContext)mapGenContext;
        _bspGenData = (BSPGeneratorData)_context.GeneratorData;


        if (_bspGenData.IsSeeded)
        {
            URandom.state = JsonUtility.FromJson <URandom.State>(_bspGenData.Seed);
        }
        else
        {
            Debug.Log("Current state: " + JsonUtility.ToJson(URandom.state));
        }


        int[,] mapAux = new int[_bspGenData.MapSize.x, _bspGenData.MapSize.y];
        mapAux.Fill <int>(_bspGenData.NoTile);

        var tree = new BSPNode();

        _context.Tree = tree;
        tree.context  = _context;
        tree.left     = tree.right = null;
        tree.area     = new BSPRect(1, 1, _bspGenData.MapSize.x - 2, _bspGenData.MapSize.y - 2);

        GenerateRooms(ref mapAux);
        GeneratorUtils.ConvertGrid(mapAux, out map);
    }
예제 #2
0
    public void GenerateMap(ref int[] map, BaseMapContext mapGenContext)
    {
        var context = (Room7DRLGeneratorContext)mapGenContext;

        context.Monsters = new List <MonsterSpawnData>();
        context.Traps    = new List <TrapSpawn>();
        context.Blocks   = new List <BlockSpawn>();

        var genData = (Room7DRLGeneratorData)mapGenContext.GeneratorData;

        if (genData.IsSeeded)
        {
            URandom.state = JsonUtility.FromJson <URandom.State>(genData.Seed);
        }
        else
        {
            Debug.Log("Current state: " + JsonUtility.ToJson(URandom.state));
        }

        var mapAux = new int[genData.MapSize.x, genData.MapSize.y];

        mapAux.Fill(genData.NoTile);

        var rooms = new List <Room7DRL>();

        var first = GenerateRoom(genData, rooms);

        first.coords = new Vector2Int()
        {
            x = (genData.MapSize.x - first.size.x) / 2 - 1,
            y = (genData.MapSize.y - first.size.y) / 2 - 1
        };

        AddRoom(rooms, genData, ref mapAux, first);
        for (int i = 0; rooms.Count < genData.NumRooms && i < genData.BuildAttempts; ++i)
        {
            var         next = GenerateRoom(genData, rooms);
            PlaceResult p    = PlaceRoom(genData.MapSize, genData, ref mapAux, rooms, next);
            if (p != null)
            {
                AddRoom(rooms, genData, ref mapAux, next);
                AddTunnel(p.wallTile, p.direction, p.length, genData.GroundTile, ref mapAux);
                if (rooms.Count >= genData.NumRooms)
                {
                    break;
                }
            }
        }

        List <Vector2Int> offsets = new List <Vector2Int>();

        for (int i = 0; i < first.size.x; ++i)
        {
            for (int j = 0; j < first.size.y; ++j)
            {
                if (first.tiles[i, j] == genData.GroundTile)
                {
                    offsets.Add(new Vector2Int(i, j));
                }
            }
        }
        if (offsets.Count == 0)
        {
            context.PlayerStart = first.coords;
        }
        else
        {
            context.PlayerStart = first.coords + offsets[URandom.Range(0, offsets.Count)];
        }


        //if(genData.IncludeShortcuts)
        //{
        //    AddShortcuts(ref mapAux, genData.MapSize);
        //}
        GeneratorUtils.PlaceWalls(genData.WallTile, genData.GroundTile, genData.NoTile, ref mapAux);
        GeneratorUtils.ConvertGrid(mapAux, out map);
    }