public void LoadRiver(Tilemap mainTilemap) { var grid = new List <List <Node> >(); for (int i = bottomLeftCorner.x - 5; i < upperRightCorner.x + 5; i++) { var row = new List <Node>(); for (int j = bottomLeftCorner.y - 5; j < upperRightCorner.y + 5; j++) { row.Add(MakeMapNode(new Vector2Int(i, j))); } grid.Add(row); } var astar = new Astar(grid); var start = -castleTemplate.boundingBox.size / 2 - bottomLeftCorner + new Vector2Int(5, 5); var end = new Vector2Int(1, 1); var pathStack = astar.FindPath(start, end); if (pathStack != null) { foreach (var item in pathStack) { var pos = item.Position + bottomLeftCorner - new Vector2Int(5, 5); mainTilemap.SetTile(pos.To3D(), riverTile); } } start = castleTemplate.boundingBox.size / 2 - bottomLeftCorner + new Vector2Int(4, 4); end = usableMapDimensions + new Vector2Int(8, 8); pathStack = astar.FindPath(start, end); if (pathStack != null) { foreach (var item in pathStack) { var pos = item.Position + bottomLeftCorner - new Vector2Int(5, 5); mainTilemap.SetTile(pos.To3D(), riverTile); } } }
// Called when the node enters the scene tree for the first time. public override void _Ready() { int floorLevel = Global.floorLevel; Global.state = "game"; for (int i = 0; i < 200; i++) { tileArray.Add(new List <AStarSharp.Node>()); for (int j = 0; j < 200; j++) { tileArray[i].Add(new AStarSharp.Node(new Vector2(i, j), false)); } } for (int i = -70; i < 200; i++) { for (int j = -70; j < 200; j++) { SetCell(i, j, 0); } } //ROOM LAYOUT int[,] dungeonRoomGrid = new int[mapSize * 2 + 1, mapSize * 2 + 1]; int noOfWalkers = (int)Math.Floor(floorLevel / 3f) + 3; //GD.Print(noOfWalkers); //GD.Print((int)((1f / (floorLevel + 3)) * 100)); Walker[] walkerArray = new Walker[noOfWalkers]; for (int i = 0; i < walkerArray.Length; i++) { walkerArray[i] = new Walker(); } //for(int i=0;i<30;i++) //{ GD.Print(i+" chance=" + // ((50f / 900f) * i * i - (3000f / 900f) * i + 50)); } float chance = ((50f / 900f) * floorLevel * floorLevel - (3000f / 900f) * floorLevel + 50); while (true) { bool flag = true; for (int i = 0; i < noOfWalkers; i++) { if (walkerArray[i].alive) { flag = false; //attempt to kill the walker. chance decreases per floor level bool result = walkerArray[i].stillAlive(chance, floorLevel); //if it was killed make the current room a treasure room if (result) { walkerArray[i].killX = walkerArray[i].x; walkerArray[i].killY = walkerArray[i].y; } else { dungeonRoomGrid[walkerArray[i].x + (mapSize - 1), walkerArray[i].y + (mapSize - 1)] = 1; walkerArray[i].move(mapSize); } } } if (flag) { break; } } for (int i = 0; i < noOfWalkers; i++) { dungeonRoomGrid[walkerArray[i].killX + (mapSize - 1), walkerArray[i].killY + (mapSize - 1)] = 2; } //make the starter room a default room dungeonRoomGrid[(mapSize - 1), (mapSize - 1)] = 3; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { //GD.PrintRaw(dungeonRoomGrid[i, j]); } //GD.Print(""); } //POPULATE MAP WITH ROOMS RoomGen roomGen = new RoomGen(); int[][] roomHolder = new int[11][]; //structure to hold data for room, room size 11 for (int i = 0; i < roomHolder.Length; i++) { roomHolder[i] = new int[11]; } for (int i = 0; i < (mapSize * 2) + 1; i++) { for (int j = 0; j < (mapSize * 2) + 1; j++) { switch (dungeonRoomGrid[i, j]) { case 0: break; //main case 1: roomHolder = roomGen.randomRoom(1); updateTileMapWRoom(ref roomHolder, i, j); break; //treasure case 2: roomHolder = roomGen.randomRoom(2); updateTileMapWRoom(ref roomHolder, i, j); break; case 3: roomHolder = roomGen.randomRoom(3); updateTileMapWRoom(ref roomHolder, i, j); break; } } } //CREATE DOORS //For each room check if there is room below it and to the right of it for (int i = 0; i < (mapSize * 2) + 1; i++) { for (int j = 0; j < (mapSize * 2) + 1; j++) { if (!(dungeonRoomGrid[i, j] == 0)) { //carve out door if (!(dungeonRoomGrid[i + 1, j] == 0)) { //create a door width int rand = (int)Math.Round(GD.RandRange(0.5, 5.49)); for (int k = rand; k < 11 - rand; k++) { tileArray[10 + 11 * i][k + 11 * j] = new AStarSharp.Node(new Vector2(10 + 11 * i, k + 11 * j), true); tileArray[11 + 11 * i][k + 11 * j] = new AStarSharp.Node(new Vector2(11 + 11 * i, k + 11 * j), true); SetCell(10 + 11 * i, k + 11 * j, 1); SetCell(11 + 11 * i, k + 11 * j, 1); } } if (!(dungeonRoomGrid[i, j + 1] == 0)) { //create a door width int rand = (int)Math.Round(GD.RandRange(0.5, 5.49)); for (int k = rand; k < 11 - rand; k++) { tileArray[k + 11 * i][10 + 11 * j] = new AStarSharp.Node(new Vector2(k + 11 * i, 10 + 11 * j), true); tileArray[k + 11 * i][11 + 11 * j] = new AStarSharp.Node(new Vector2(k + 11 * i, 11 + 11 * j), true); SetCell(k + 11 * i, 10 + 11 * j, 1); SetCell(k + 11 * i, 11 + 11 * j, 1); } } } } } pathfindAstar = new AStarSharp.Astar(tileArray); UpdateBitmaskRegion(); for (int i = 0; i < 200; i++) { for (int j = 0; j < 200; j++) { if (tileArray[i][j].Walkable) { // GD.PrintRaw(0); } else //GD.PrintRaw(1); { } } //GD.Print(""); } var scene = GD.Load <PackedScene>("res://CardAndSpawnManager.tscn"); var node = scene.Instance(); AddChild(node); }