当前位置: 首页>>代码示例>>C#>>正文


C# Dungeon.Generate方法代码示例

本文整理汇总了C#中Dungeon.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# Dungeon.Generate方法的具体用法?C# Dungeon.Generate怎么用?C# Dungeon.Generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dungeon的用法示例。


在下文中一共展示了Dungeon.Generate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

    public void Generate()
    {
        Dungeon dungeon = new Dungeon ();

        dungeon.min_size = minRoomSize;
        dungeon.max_size = maxRoomSize;
        dungeon.minimumRoomCount = minimumRoomCount;
        dungeon.maximumRoomCount = maximumRoomCount;
        dungeon.roomMargin = roomMargin;
        dungeon.prune = pruneCollidingRooms;

        dungeon.Generate ();

        for (var y = 0; y < Dungeon.map_size; y++) {
            for (var x = 0; x < Dungeon.map_size; x++) {
                int tile = Dungeon.map [x, y].type;
                GameObject created_tile;
                Vector3 tile_location;
                tile_location = new Vector3 (x * tileScaling, y * tileScaling, 0);

                created_tile = null;
                if (tile == 1) {
                    created_tile = GameObject.Instantiate (floorPrefab, tile_location, Quaternion.identity) as GameObject;
                }

                if (tile == 2) {
                    created_tile = GameObject.Instantiate (wallPrefab, tile_location, Quaternion.identity) as GameObject;
                }

                if (tile == 3) {
                    created_tile = GameObject.Instantiate (floorPrefab, tile_location, Quaternion.identity) as GameObject;
                }

                if (Dungeon.corners.Contains(tile)) {
                    if(cornerPrefab){
                        created_tile = GameObject.Instantiate (cornerPrefab, tile_location, Quaternion.identity) as GameObject;
                        if(cornerRotation) {
                            created_tile.transform.Rotate(Vector3.forward  * (-90 * (tile -4)));
                        }
                    }
                    else {
                        created_tile = GameObject.Instantiate (wallPrefab, tile_location, Quaternion.identity) as GameObject;
                    }
                }

                if (created_tile) {
                    created_tile.transform.parent = transform;
                }
            }
        }

        GameObject end_point   = GameObject.Instantiate (exitPrefab,  new Vector3 (Dungeon.goalRoom.x  * tileScaling,  Dungeon.goalRoom.y * tileScaling, 0), Quaternion.identity) as GameObject;
        GameObject start_point = GameObject.Instantiate (startPrefab, new Vector3 (Dungeon.startRoom.x * tileScaling, Dungeon.startRoom.y * tileScaling, 0), Quaternion.identity) as GameObject;

        end_point.transform.parent = transform;
        start_point.transform.parent = transform;

        //Spawn Objects;
        List<SpawnList> spawnedObjectLocations = new List<SpawnList> ();

        //OTHERS
        for (int x = 0; x < Dungeon.map_size; x++) {
            for (int y = 0; y < Dungeon.map_size; y++) {
                if (Dungeon.map [x, y].type == 1 && ((Dungeon.startRoom != Dungeon.map [x, y].room && Dungeon.goalRoom != Dungeon.map [x, y].room) || maximumRoomCount <= 3)) {
                    var location = new SpawnList ();
                    location.x = x;
                    location.y = y;
                    if (Dungeon.map [x + 1, y].type == 2 || Dungeon.map [x - 1, y].type == 2 || Dungeon.map [x, y + 1].type == 2 || Dungeon.map [x, y - 1].type == 2) {
                        location.byWall = true;
                    }
                    if (Dungeon.map [x + 1, y].type == 3 || Dungeon.map [x - 1, y].type == 3 || Dungeon.map [x, y + 1].type == 3 || Dungeon.map [x, y - 1].type == 3) {
                        location.byCorridor = true;
                    }
                    if (Dungeon.map [x + 1, y + 1].type == 3 || Dungeon.map [x - 1, y - 1].type == 3 || Dungeon.map [x - 1, y + 1].type == 3 || Dungeon.map [x + 1, y - 1].type == 3) {
                        location.byCorridor = true;
                    }
                    spawnedObjectLocations.Add (location);
                }
                else if (Dungeon.map[x, y].type == 3) {
                    var location = new SpawnList ();
                    location.x = x;
                    location.y = y;
                    if ( (Dungeon.map [x + 1, y].type == 1 || Dungeon.map [x - 1, y].type == 1  ||  Dungeon.map [x, y + 1].type == 1 || Dungeon.map [x, y - 1].type == 1)
                    && ( (Dungeon.map [x + 1, y].type == 2 && Dungeon.map [x - 1, y].type == 2) || (Dungeon.map [x, y + 1].type == 2 && Dungeon.map [x, y - 1].type == 2) ) ) {
                            location.byCorridor = true;
                            location.asDoor = true;
                            spawnedObjectLocations.Add (location);
                    }
                }
            }
        }

        for (int i = 0; i < spawnedObjectLocations.Count; i++) {
            SpawnList temp = spawnedObjectLocations [i];
            int randomIndex = Random.Range (i, spawnedObjectLocations.Count);
            spawnedObjectLocations [i] = spawnedObjectLocations [randomIndex];
            spawnedObjectLocations [randomIndex] = temp;
        }

        int objectCountToSpawn = 0;
//.........这里部分代码省略.........
开发者ID:mwdewey,项目名称:GameDev2,代码行数:101,代码来源:generateDungeon.cs


注:本文中的Dungeon.Generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。