Пример #1
0
    public void CreateWorld()
    {
        if (worldCreateAttempts >= maxWorldCreateAttempts)
        {
            Debug.Log(string.Format(
                          "Mapgen couldn't create a world with at least {0} rooms with doors. Tried {1} times. Please re-evaluate your configuration.",
                          config.MinimumNumberOfRooms,
                          worldCreateAttempts
                          ));
            return;
        }
        RemoveOldWorld();
        worldCreateAttempts += 1;
        worldSprite          = CreateRoomSprite(world, Color.gray);

        mazeCarver = InitializeCarver();

        PlaceRooms(config.BigRooms, config.BigRoomPlacementAttempts);
        PlaceRooms(config.MediumRooms, config.MediumRoomPlacementAttempts);
        PlaceRooms(config.SmallRooms, config.SmallRoomPlacementAttempts);
        if (rooms.Count < config.MinimumNumberOfRooms)
        {
            CreateWorld();
        }
        else
        {
            mazeCarver.StartCarving();
        }
    }
        public IMazeCarver GetMazeCarver(IModelBuilder modelBuilder)
        {
            var carver = new MazeCarver();

            carver.Initialise(_modelsWrapperFactory.Make(modelBuilder), _directionsFlagParser, _movementHelper, _pointValidity, _randomPointGenerator);
            return(carver);
        }
Пример #3
0
    public void LoadBaseLevel()
    {
        loading = true;
        MazeRoom         mainRoom    = new MazeRoom(new Rect(5, 5, 11, 11));
        LevelDepthConfig depthConfig = generalLevelConfig.GetLevelDepthConfiguration(-1);
        LevelConfig      levelConfig = Resources.Load <LevelConfig>("LevelConfigs/base");

        levelConfig.Randomize();

        MapGenerator.Initialize(levelConfig, depthConfig, ReadyWithBase);
        //MazeCarver carver = mapGenerator.InitializeCarver(worldRect, mapGenerator, levelConfig, depthConfig);
        MazeCarver carver = MapGenerator.InitializeCarver();

        MapGenerator.PlaceRoom(mainRoom);
        carver.FillWithHallway();
        //carver.RemoveFalseWalls();
        carver.Create3DWalls();
        carver.CreateNavMeshes();
        mapPopulator = MapGenerator.InitializeMapPopulator();
        //mapPopulator.SpawnKeyAt(mapGenerator.GetScaled(new Vector3(10, 10, 0)));

        SpawnWandAt(new Vector3(9, 9, 0), depthConfig.PowerLevel);
        SpawnWandAt(new Vector3(7, 9, 0), depthConfig.PowerLevel);
        SpawnWandAt(new Vector3(9, 7, 0), depthConfig.PowerLevel);
        Dummy dummyPrefab = Resources.Load <Dummy>("Dummy");

        Dummy dummy = Instantiate(dummyPrefab, MapGenerator.transform);

        dummy.transform.position = MapGenerator.GetScaled(new Vector3(13, 13, 0));

        mapPopulator.SpawnEndAt(MapGenerator.GetScaled(new Vector3(10, 10, 0)));
        player = mapPopulator.SpawnPlayerAt(MapGenerator.GetScaled(new Vector3(7, 7, 0)));
        mapPopulator.SetUpCamera(player);
        //fullscreenFade.FadeOut(ReadyWithBase);
    }
Пример #4
0
    Coordinate carveMaze()
    {
        int startX = MAZE_SIZE / 2;
        int startY = startX;
        MazeCarver[] carvers = new MazeCarver[100];
        carvers [0] = new MazeCarver (startX, startY, this);
        int nextIndex = 1;
        int activeIndex = 0;
        int carverCount = 1;
        System.Random rand = new System.Random();
        while (carverCount > 0) {
            MazeCarver carver = carvers[activeIndex];
            bool lived = carver.update();

            if (lived) { //avoids out-of-bounds error, probability at 30 = 0%) {
                if (rand.Next(1,100) < (carvers.Length - nextIndex)) {
                    carvers[nextIndex++] = new MazeCarver(carver.x, carver.y, this);
                    carverCount++;
                }
            }
            else {
                if (rand.Next(10) < 4) {
                    for(int i = carver.x - 2; i <= carver.x + 2; i++) {
                        for(int j = carver.y - 2; j <= carver.y + 2; j++) {
                            if(i >= 0 && i < MAZE_SIZE && j >= 0 && j < MAZE_SIZE) {
                                isCarved[i,j] = true;
                            }
                        }
                    }
                }
                carverCount--;
                activeIndex++;
            }
        }

        return new Coordinate(carvers[activeIndex-1].x, carvers[activeIndex-1].y, carvers[activeIndex-1].prevDir);

        //		int startDir = -1;
        //
        //		switch (carvers[activeIndex-1].prevDir) {
        //		case 0:
        //			startDir = 1;
        //			break;
        //		case 1:
        //			startDir = 0;
        //			break;
        //		case 2:
        //			startDir = 3;
        //			break;
        //		case 3:
        //			startDir = 2;
        //			break;
        //		}
        //
        //		Coordinate startpt = new Coordinate(carvers[activeIndex-1].x, carvers[activeIndex-1].y, startDir);
    }
Пример #5
0
 public MazeCarver InitializeCarver()
 {
     if (mazeCarverPrefab == null)
     {
         mazeCarverPrefab = Resources.Load <MazeCarver>("MazeCarver");
     }
     mazeCarver = Instantiate(mazeCarverPrefab, Vector2.zero, Quaternion.identity);
     mazeCarver.Initialize(world, this, config, depthConfig);
     return(mazeCarver);
 }
Пример #6
0
        protected override void _runAlgorithm(IAlgorithmContext context)
        {
            context.D.Tiles.SetAllToo(Tile.MoveType.Wall, context.Mask);
            foreach (var cb in this.Callbacks)
            {
                RoomBuilder?.AttachCallback(cb);
                MazeCarver?.AttachCallback(cb);
                DeadEndFiller?.AttachCallback(cb);
            }

            RoomBuilder?.Run(context);
            this.RunCallbacks(context);
            MazeCarver?.Run(context);
            this.RunCallbacks(context);
            DeadEndFiller?.Run(context);
            this.RunCallbacks(context);
        }
Пример #7
0
        public IMap GenerateMap(IMap?previousMap = null)
        {
            var map = new RogueMap(Width, Height, previousMap);

            map.Level = previousMap == null ? 1 : previousMap.Level + 1;
            PlaceRooms(map, previousMap);

            var maze = new MazeCarver(Rnd, map);

            maze.CarveMaze(new Point(0, 0));

            ConnectRooms(map);
            DecorateRooms(map);
            PlaceMonsters(map);

            return(map);
        }