static void MakeDungeon(int seed) { stage = new Stage(23, 23); RoomDecorator rd = new RoomDecorator(stage); rd.ReadAll("rooms.txt"); Generator g = new Generator(seed); g.DecorateRoom += rd.DecorateRoom; g.numRoomTries = 500; g.generate(stage); DijkstraMap dm = new DijkstraMap(stage, 0); //dm.Compute(1,1,true); dm.Compute(stage.GetAll(Tiles.Brazier), false); dm.Display(); dm.CalculatePath(21, 21); var path = dm.GetReversePath().ToList(); PrintDungeon(seed); }
void Start() { Debug.Log("GM Start called."); Cursor.lockState = CursorLockMode.Confined; bool setPlayer = true; container = new GameObject("level"); player = GameObject.Find("Player"); stage = new Stage(23, 23); RoomDecorator rd = new RoomDecorator(stage); var roomLines = Resources.Load("rooms") as TextAsset; rd.ReadAll(roomLines.text.Split('\n')); Generator g = new Generator(seed); g.DecorateRoom += rd.DecorateRoom; g.numRoomTries = 500; g.generate(stage); rng = new MersenneTwister(seed); var wallset = Tileset.GetRandomSet(Tileset.ws_everything); var floorset = Tileset.GetRandomSet(Tileset.fs_everything); var ceilingset = Tileset.GetRandomSet(Tileset.fs_everything); for (int y = 0; y < stage.height; y++) { for (int x = 0; x < stage.width; x++) { var tile = stage[x, y]; //if (tile != Tiles.Wall) { var cell = CreateFloor(x, y, Tileset.GetRandom(floorset)); cell.transform.parent = container.transform; cell = CreateCeiling(x, y, Tileset.GetRandom(ceilingset)); cell.transform.parent = container.transform; if (setPlayer && tile == Tiles.Floor) { setPlayer = false; var vv = cell.transform.position; GameObject.Find("Player").transform.position = new Vector3(vv.x, 0.15f, vv.z); GameObject.Find("Player").SendMessage("RegisterWithStage", SendMessageOptions.DontRequireReceiver); GameObject.Find("Inventory").SendMessage("RegisterWithStage", SendMessageOptions.RequireReceiver); } } if (tile == Tiles.Wall) { var tileId = Tileset.GetRandom(wallset); var cell = CreateWall(x, y, tileId); cell.transform.parent = container.transform; } if (tile == Tiles.ClosedDoor_EW) { var pre = Resources.Load("Prefabs/Decoration/Door") as GameObject; var cell = Instantiate(pre); cell.transform.position = new Vector3(x, 0, y); cell.transform.parent = container.transform; var dc = cell.GetComponent <DoorController>(); dc.Position = new Vec(x, y); dc.Tile = tile; } if (tile == Tiles.ClosedDoor_NS) { var pre = Resources.Load("Prefabs/Decoration/Door") as GameObject; var cell = Instantiate(pre); cell.transform.position = new Vector3(x, 0, y); cell.transform.rotation = Quaternion.AngleAxis(90, Vector3.up); cell.transform.parent = container.transform; var dc = cell.GetComponent <DoorController>(); dc.Position = new Vec(x, y); dc.Tile = tile; } if (tile == Tiles.Pillar) { var pre = Resources.Load("Prefabs/Decoration/Pillar") as GameObject; var cell = Instantiate(pre); cell.name = "Pillar_" + x + "_" + y; cell.transform.position = new Vector3(x, 0, y); //cell.transform.rotation = Quaternion.AngleAxis(45, Vector3.up); cell.transform.parent = container.transform; } if (tile == Tiles.Brazier) { var pre = Resources.Load("Prefabs/Decoration/Brazier") as GameObject; var cell = Instantiate(pre); cell.name = "Brazier_" + x + "_" + y; cell.transform.position = new Vector3(x, 0, y); cell.transform.rotation = Quaternion.AngleAxis(45, Vector3.up); cell.transform.parent = container.transform; } if (tile == Tiles.Altar) { if (!stage.HasDoorAtCardinalDirection(new Vec(x, y))) { var pre = Resources.Load("Prefabs/Decoration/Altar") as GameObject; var cell = Instantiate(pre); cell.name = "Altar_" + x + "_" + y; cell.transform.position = new Vector3(x, 0, y); cell.transform.rotation = Quaternion.AngleAxis(0, Vector3.up); cell.transform.parent = container.transform; } } if (tile == Tiles.Fountain) { if (!stage.HasDoorAtCardinalDirection(new Vec(x, y))) { var pre = Resources.Load("Prefabs/Decoration/BloodFountain") as GameObject; var cell = Instantiate(pre); cell.name = "BloodFountain_" + x + "_" + y; cell.transform.position = new Vector3(x, 0, y); cell.transform.rotation = Quaternion.AngleAxis(0, Vector3.up); cell.transform.parent = container.transform; } } if (tile == Tiles.Floor) { if (rng.OneIn(20)) { var item = ItemFactory.GetRandom(); CreateItem(x, y, item); } if (rng.OneIn(20)) { var pre = Resources.Load("Prefabs/Decoration/EnemySmall") as GameObject; var cell = Instantiate(pre); cell.name = "Rat_" + x + "_" + y; cell.transform.position = new Vector3(x, 0.2f, y); cell.transform.parent = container.transform; } } } } }