Пример #1
0
        private static string generateNext(uint seed, DungeonTemplate template)
        {
            var gen = new DungeonGen((int)seed, template);

            gen.GenerateAsync();
            return(gen.ExportToJson());
        }
Пример #2
0
        void Start()
        {
            var mapchip = Resources.Load <MapchipSet>($"Dungeon/{assetName}/MapchipSet");

            GridSize = mapchip.GridSize;

            var postProcessing = Camera.main.GetComponent <PostProcessingBehaviour>();

            if (postProcessing != null)
            {
                postProcessing.profile = mapchip.PostProcessingProfile;
            }

            var additional = new[] { Tile.UpStairs, Tile.DownStairs };
            var map        = DungeonGen.Gen(0, new Vector2Int(30, 30), new Vector2Int(3, 3), new Vector2Int(12, 12), new Vector2Int(20, 20), 2, 2, 1, obstacleRate, additional);

            var width  = map.GetLength(0);
            var height = map.GetLength(1);

            var random = new System.Random();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var info = mapchip.GetChip(map[x, y], random);
                    if (info != null)
                    {
                        var go = Instantiate(info.prefab, this.transform);
                        go.transform.localRotation = info.Quaternion;
                        go.transform.localPosition = new Vector3(x * GridSize.x, go.transform.localPosition.y, -y * GridSize.y);
                    }
                }
            }
        }
Пример #3
0
    private void Awake()
    {
        tileGen    = GetComponent <TileGen>();
        dungeonGen = GetComponent <DungeonGen>();

        savedLevels = new List <string>();

        fileLocation = "MapData/";
    }
Пример #4
0
        /// <summary>
        /// generate the type of map
        /// </summary>
        /// <param name="map">map to be used</param>
        /// <param name="type">type of map to generate</param>
        /// <returns>true upon success, otherwise false</returns>
        public static bool generate(Map map, MapType type)
        {
            //set type
            map.MapDef.MapType = type;
            m_CurrentMapType   = type;

            //call appropriate generator and generate the map
            switch (type)
            {
            case MapType.CAVE:
                return(CaveGen.generate(map, m_Params));

            case MapType.CITY:
                break;

            case MapType.DUNGEON:
                return(DungeonGen.generate(map, m_Params));

            case MapType.FORT:
                break;

            case MapType.OUTPOST:
                break;

            case MapType.NEXUS:
                break;

            case MapType.TOWER:
                break;

            case MapType.TOWN:
                break;

            case MapType.WORLD:
                return(WorldGen.generate(map, m_Params));

            case MapType.WILDERNESS:
                return(ForestGen.generate(map, m_Params));

            default:
                return(false);//no map created
            }

            //no map was created
            return(false);
        }
 private static string generateNext(uint seed, DungeonTemplate template)
 {
     var gen = new DungeonGen((int)seed, template);
     gen.GenerateAsync();
     return gen.ExportToJson();
 }
Пример #6
0
    void Start()
    {
        //
        //		DungeonGen dgen = new DungeonGen ();
        //		dgen.braidMaze (30,70);
        //		UnityEngine.Debug.Log (dgen.printMaze ());
        dgen = new DungeonGen ();
        if (DungeonGen.width == 0){
            DungeonGen.width = 5;
            DungeonGen.height = 10;
        }

        dgen.Start(); // Don't touch any data in the job class after you called Start until IsDone is true.
    }
Пример #7
0
    void Update()
    {
        if (dgen != null)
        {
            if (dgen.Update())
            {
                // Alternative to the OnFinished callback
                map = dgen.newDungeon;
                int borderSize = 2;
                borderedMap = new int[DungeonGen.width + borderSize * 2,DungeonGen.height + borderSize * 2];

                for (int x = 0; x < borderedMap.GetLength(0); x ++) {
                    for (int y = 0; y < borderedMap.GetLength(1); y ++) {
                        if (x >= borderSize && x < DungeonGen.width + borderSize && y >= borderSize && y < DungeonGen.height + borderSize) {
                            borderedMap[x,y] = map[x-borderSize,y-borderSize];
                        }
                        else {
                            borderedMap[x,y] =1;
                        }
                    }
                }

                meshGen = GetComponent<MeshGenerator>();

                Vector3 start = new Vector3(0,-10,0);
                Vector3 end = new Vector3(0,-10,1);
                List<Vector3> spaces = new List<Vector3>();
                List<Vector3> walls = new List<Vector3>();
                for (int x = 0; x < borderedMap.GetLength(0); x++){
                    for (int y = 0; y < borderedMap.GetLength(1); y++){
                        if ( borderedMap[x,y] == DungeonGen.space){
                            spaces.Add(new Vector3((x-borderedMap.GetLength(0)/2)*meshGen.squareWidth-meshGen.squareWidth,-10,(y-borderedMap.GetLength(1)/2)*meshGen.squareWidth-meshGen.squareWidth));
                        } else if (borderedMap[x,y] == DungeonGen.wall){
                            walls.Add(new Vector3((x-borderedMap.GetLength(0)/2)*meshGen.squareWidth-meshGen.squareWidth,-10,(y-borderedMap.GetLength(1)/2)*meshGen.squareWidth-meshGen.squareWidth));
                            Instantiate(WallPrefab, new Vector3((x-borderedMap.GetLength(0)/2)*meshGen.squareWidth-meshGen.squareWidth,-8,(y-borderedMap.GetLength(1)/2)*meshGen.squareWidth-meshGen.squareWidth), transform.rotation);
                        }
                    }
                }
        //				UnityEngine.Random.seed = 2;
                start = spaces[UnityEngine.Random.Range(0,spaces.Count)];
                end = start;
                while (Vector3.Distance(start, end) < 6){  //Place end at least 6 away from start;
                    end = spaces[UnityEngine.Random.Range(0,spaces.Count)];
                }

                for (int i = 0; i < spaces.Count/8; i++){
                    placeObjectOnRandomWall(spaces, walls, wallChainPrefab, Vector3.zero);//For Minotaur
                    Vector3 floorChain = spaces[UnityEngine.Random.Range(0,spaces.Count)];
                    Instantiate(floorChainPrefab, floorChain+Vector3.down, floorChainPrefab.transform.rotation);
                }
                Vector3 minotaurStart = start;
                while (Vector3.Distance(minotaurStart, start) < 12){  //Place minotaur at least 12 away from start;
                    minotaurStart = spaces[UnityEngine.Random.Range(0,spaces.Count)];
                }

                Instantiate(MinotaurPrefab, minotaurStart, MinotaurPrefab.transform.rotation);

                for (int i = 0; i < spaces.Count/16; i++){
                    placeObjectOnRandomWall(spaces, walls, SecurityCameraPrefab, new Vector3(0,2,0)); //For robot
                }
                Vector3 robotStart = start;
                while (Vector3.Distance(robotStart, start) < 12){  //Place minotaur at least 12 away from start;
                    robotStart = spaces[UnityEngine.Random.Range(0,spaces.Count)];
                }
                Instantiate(RobotPrefab, robotStart, RobotPrefab.transform.rotation);
        //				chain.transform.position += (closestWall-wallCh)/2;
                Vector3 ghostStart = start;
                while (Vector3.Distance(ghostStart, start) < 4 || Vector3.Distance(ghostStart, start) >12){  //Place minotaur at least 12 away from start;
                    ghostStart = spaces[UnityEngine.Random.Range(0,spaces.Count)];
                }
                Instantiate(GhostPrefab, ghostStart, GhostPrefab.transform.rotation);

        //				meshGen.GenerateMesh(borderedMap);

                Destroy(Camera.main.gameObject);

                Instantiate(playerController, start, transform.rotation);

                Instantiate(StairsPrefab, end+Vector3.down, StairsPrefab.transform.rotation);
                dgen = null;
            }
        }
    }
Пример #8
0
    void Start()
    {
        var mapchip = Resources.Load <MapchipSet>($"Dungeon/{Dungeon.AssetPath}/MapchipSet");

        GridSize = mapchip.GridSize;
        var postProcessing = Camera.main.GetComponent <PostProcessingBehaviour>();

        if (postProcessing != null)
        {
            postProcessing.profile = mapchip.PostProcessingProfile;
        }

        map = DungeonGen.Gen(stageInfo.seed, Room.AreaSize, Room.RoomNum, Room.RoomMin, Room.RoomMax, Room.DeleteRoadTry, Room.DeleteRoadTry, Room.MergeRoomTry, Room.ObstacleRate, GetAdditionalTile(Dungeon));
        var width  = map.GetLength(0);
        var height = map.GetLength(1);

        Vector2Int?playerGrid = null;
        var        random     = new System.Random(stageInfo.seed);

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                var info = mapchip.GetChip(map[x, y], random);
                if (info != null)
                {
                    var go = Instantiate(info.prefab, Vector3.zero, info.Quaternion, dungeonRoot);
                    go.transform.localRotation = info.Quaternion;
                    go.transform.localPosition = Grid2WorldPosition(new Vector2Int(x, y), GridSize, info.prefab.transform.localPosition);
                    go.name += $"({x},{y})";
                }

                if (map[x, y] == Tile.Start && stageInfo.move == Move.None)
                {
                    playerGrid = new Vector2Int(x, y);
                }
                if ((map[x, y] == Tile.UpStairs && stageInfo.move == Move.Down) ||
                    (map[x, y] == Tile.DownStairs && stageInfo.move == Move.Up))
                {
                    var pos = new Vector2Int(x, y);
                    if (x - 1 >= 0 && map[x - 1, y] == Tile.All)
                    {
                        pos.x -= 1;
                    }
                    else if (x + 1 < width && map[x + 1, y] == Tile.All)
                    {
                        pos.x += 1;
                    }
                    else if (y - 1 >= 0 && map[y - 1, y] == Tile.All)
                    {
                        pos.y -= 1;
                    }
                    else if (y + 1 < height && map[y + 1, y] == Tile.All)
                    {
                        pos.y += 1;
                    }
                    playerGrid = pos;
                }
            }
        }

        if (playerGrid.HasValue)
        {
            var position = Grid2WorldPosition(playerGrid.Value, GridSize, new Vector3(0, playerPrefab.transform.localPosition.y, 0));

            foreach (var uniq in Entity.Instance.StageInfo.pets)
            {
                var go = Instantiate(playerPrefab, dungeonRoot);
                go.transform.localPosition = position;
                var player = go.GetComponent <Player>();
                player.Setup(uniq);
                players.Add(player);
            }
        }

        cinemachineVirtualCamera.Follow = players.First().transform;
        Observer.Instance.Subscribe(MapchipEvent.MoveEvent, OnSubscribe);

        // 経路探索用 A* 生成
        aStar = new AStar(map);
    }