static public void Main() { //UI d = new VT100UI(); VT100UI d = new VT100UI(); // This is just a placeholder for (int x = 0; x < 80; x++) { d.DrawAt(x, 3, " ", 0, 0, 0, 0, 0, 64); } for (int x = 0; x < 80; x++) { d.DrawAt(x, 22, " ", 0, 0, 0, 0, 0, 64); } UIMapElement map_element = d.MapElement( x: 0, y: 4, h: 17 ); ClearMapGenerator gen = new ClearMapGenerator(new int[] { 0, 0 }, MapCoordinate.GenerateRandom()); map_element.map = new MapData(80, 40); ClearMapGenerator gen2 = new ClearMapGenerator(new int[] { 2, 1 }, MapCoordinate.GenerateRandom()); gen2.Run(map_element.map.grid, new MapRectangle(10, 10, 10, 10), null); List <MapRoom> blockedList = new List <MapRoom>(); MapRectangle fullArea = new MapRectangle(0, 0, 80, 40); blockedList.Add(new MapRoom(new MapRectangle(10, 10, 10, 10))); gen.Run(map_element.map.grid, fullArea, blockedList); DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] { 5, 6, 7 }, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List <MapRoom> allRooms = drmg.Run(map_element.map.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] { 5, 6, 7 }, MapCoordinate.GenerateRandom(), 2, new int[] { 0, 100000, 100000, 0, 0, 100000, 0, 0 }); dcmg.Run(map_element.map.grid, fullArea, allRooms); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '*'); map_element.map.AddSpaceType(glyph: '~', r: 0, g: 32, b: 255); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '.', r: 64, g: 64, b: 64); map_element.map.AddSpaceType(glyph: '+', r: 128, g: 64, b: 0); d.DrawAt(54, 3, " 5 targets in range ", 255, 255, 192, 0, 0, 0); d.DrawAt(74, 3, "[T] ", 192, 192, 255, 0, 0, 0); d.DrawAt(58, 22, " Press for help ", 255, 255, 192, 0, 0, 0); d.DrawAt(65, 22, "[?]", 192, 192, 255, 0, 0, 0); map_element.Draw(); d.DrawScreen(); }
public static int Main(String[] args) { ClearMapGenerator gen = new ClearMapGenerator(new int[] {0, 0}, MapCoordinate.GenerateRandom()); MapData mapdata = new MapData(40, 40); ClearMapGenerator gen2 = new ClearMapGenerator(new int[] {2, 1}, MapCoordinate.GenerateRandom()); gen2.Run(mapdata.grid, new MapRectangle(10, 10, 10, 10), null); List<MapRoom> blockedList = new List<MapRoom>(); MapRectangle fullArea = new MapRectangle(0, 0, 40, 40); blockedList.Add(new MapRoom(new MapRectangle(10, 10, 10, 10))); gen.Run(mapdata.grid, fullArea, blockedList); if (args.Length == 0) { Console.WriteLine("Specify -cave, -dungeon, or -office"); return 0; } else if (args[0] == "-office") { gen.Run(mapdata.grid, fullArea, null); BSPBuildingMapGenerator bsp = new BSPBuildingMapGenerator( new int[] {0, 1, 7}, MapCoordinate.GenerateRandom(), 4, 3, 2); MapRectangle borderedArea = new MapRectangle(1, 1, 38, 38); bsp.Run(mapdata.grid, borderedArea, null); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '.'); mapdata.AddSpaceType(glyph: 'O'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: 'X'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); } else if (args[0] == "-dungeon") { DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List<MapRoom> allRooms = drmg.Run(mapdata.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 2, new int[] {0, 100000, 100000, 0, 0, 100000, 0, 0}); dcmg.Run(mapdata.grid, fullArea, allRooms); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); } else if (args[0] == "-cave") { CADecayMapGenerator cad = new CADecayMapGenerator(new int[] {0, 1}, MapCoordinate.GenerateRandom(), 10, 20, 5, 10); // add this to not get random caves // cad.UseCoordinateBasedRandom(); cad.Run(mapdata.grid, fullArea, blockedList); CAGrowthMapGenerator cag1 = new CAGrowthMapGenerator(new int[] {3, 1}, MapCoordinate.GenerateRandom(), 50, 2, 20); cag1.Run(mapdata.grid, fullArea, blockedList); CAGrowthMapGenerator cag2 = new CAGrowthMapGenerator(new int[] {4, 1, 2}, MapCoordinate.GenerateRandom(), 200, 8, 20); cag2.Run(mapdata.grid, fullArea, blockedList); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '.'); mapdata.AddSpaceType(glyph: 'O'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: 'X'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); } else if (args[0] == "-line") { Path path = PathUtils.GetBresenhamPath(0, 1, 6, 4, null); Console.WriteLine("Path from 0, 1 to 6, 4"); PathUtils.PrintPath(path, 0, 1); PathUtils.GetBresenhamPath(-3, 1, -4, 9, path); Console.WriteLine("Path from -3, 1 to -4, 9"); PathUtils.PrintPath(path, -3, 1); gen = new ClearMapGenerator(new int[] {1, 1}, MapCoordinate.GenerateRandom()); fullArea = new MapRectangle(0, 0, 40, 40); mapdata = new MapData(40, 40); gen.Run(mapdata.grid, fullArea, null); int length = PathUtils.CalculateBresenhamProductSquareToSquare( 0, 1, 6, 4, mapdata.grid, (x, y) => x + y, 0); Console.WriteLine("Length (0, 1) -> (6, 4) in steps = " + length); MapData distance = new MapData(40, 40); PathUtils.CalculateBresenhamProductsToRectangle(5, 5, mapdata.grid, fullArea, (x, y) => x + y, 0, distance.grid); for (int i = 0; i < 20; i++) { Console.WriteLine("3 " + i + " dist = " + distance.grid[3][i]); } return 0; } else if (args[0] == "-bfs") { DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List<MapRoom> allRooms = drmg.Run(mapdata.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 2, new int[] {0, 100000, 100000, 0, 0, 100000, 0, 0}); dcmg.Run(mapdata.grid, fullArea, allRooms); int xStart = allRooms[0].bounds.xCenter; int yStart = allRooms[0].bounds.yCenter; int xEnd = allRooms[1].bounds.xCenter; int yEnd = allRooms[1].bounds.yCenter; Path path = PathUtils.BFSPath(xStart, yStart, xEnd, yEnd, null, (x, y) => (mapdata.grid[x][y] >= 6), null, (x, y, d) => ((((int)d) % 2) == 1 ? 140 : 100), fullArea); if (path != null) { int[][] pathSquares = PathUtils.UnrollPath(path, xStart, yStart); for (int i = 0; i < pathSquares.Length; i++) { mapdata.grid[pathSquares[i][0]][pathSquares[i][1]] = 8; } } mapdata.grid[xStart][yStart] = 9; mapdata.grid[xEnd][yEnd] = 10; mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); mapdata.AddSpaceType(glyph: 'v'); mapdata.AddSpaceType(glyph: 'S'); mapdata.AddSpaceType(glyph: 'E'); } else { Console.WriteLine("Specify -cave, -dungeon, or -office"); return 0; } DisplayMap(mapdata); return 0; }
public static int Main(String[] args) { ClearMapGenerator gen = new ClearMapGenerator(new int[] { 0, 0 }, MapCoordinate.GenerateRandom()); MapData mapdata = new MapData(40, 40); ClearMapGenerator gen2 = new ClearMapGenerator(new int[] { 2, 1 }, MapCoordinate.GenerateRandom()); gen2.Run(mapdata.grid, new MapRectangle(10, 10, 10, 10), null); List <MapRoom> blockedList = new List <MapRoom>(); MapRectangle fullArea = new MapRectangle(0, 0, 40, 40); blockedList.Add(new MapRoom(new MapRectangle(10, 10, 10, 10))); gen.Run(mapdata.grid, fullArea, blockedList); if (args.Length == 0) { Console.WriteLine("Specify -cave, -dungeon, or -office"); return(0); } else if (args[0] == "-office") { gen.Run(mapdata.grid, fullArea, null); BSPBuildingMapGenerator bsp = new BSPBuildingMapGenerator( new int[] { 0, 1, 7 }, MapCoordinate.GenerateRandom(), 4, 3, 2); MapRectangle borderedArea = new MapRectangle(1, 1, 38, 38); bsp.Run(mapdata.grid, borderedArea, null); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '.'); mapdata.AddSpaceType(glyph: 'O'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: 'X'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); } else if (args[0] == "-dungeon") { DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] { 5, 6, 7 }, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List <MapRoom> allRooms = drmg.Run(mapdata.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] { 5, 6, 7 }, MapCoordinate.GenerateRandom(), 2, new int[] { 0, 100000, 100000, 0, 0, 100000, 0, 0 }); dcmg.Run(mapdata.grid, fullArea, allRooms); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); } else if (args[0] == "-cave") { CADecayMapGenerator cad = new CADecayMapGenerator(new int[] { 0, 1 }, MapCoordinate.GenerateRandom(), 10, 20, 5, 10); // add this to not get random caves // cad.UseCoordinateBasedRandom(); cad.Run(mapdata.grid, fullArea, blockedList); CAGrowthMapGenerator cag1 = new CAGrowthMapGenerator(new int[] { 3, 1 }, MapCoordinate.GenerateRandom(), 50, 2, 20); cag1.Run(mapdata.grid, fullArea, blockedList); CAGrowthMapGenerator cag2 = new CAGrowthMapGenerator(new int[] { 4, 1, 2 }, MapCoordinate.GenerateRandom(), 200, 8, 20); cag2.Run(mapdata.grid, fullArea, blockedList); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '.'); mapdata.AddSpaceType(glyph: 'O'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: 'X'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); } else if (args[0] == "-line") { Path path = PathUtils.GetBresenhamPath(0, 1, 6, 4, null); Console.WriteLine("Path from 0, 1 to 6, 4"); PathUtils.PrintPath(path, 0, 1); PathUtils.GetBresenhamPath(-3, 1, -4, 9, path); Console.WriteLine("Path from -3, 1 to -4, 9"); PathUtils.PrintPath(path, -3, 1); gen = new ClearMapGenerator(new int[] { 1, 1 }, MapCoordinate.GenerateRandom()); fullArea = new MapRectangle(0, 0, 40, 40); mapdata = new MapData(40, 40); gen.Run(mapdata.grid, fullArea, null); int length = PathUtils.CalculateBresenhamProductSquareToSquare( 0, 1, 6, 4, mapdata.grid, (x, y) => x + y, 0); Console.WriteLine("Length (0, 1) -> (6, 4) in steps = " + length); MapData distance = new MapData(40, 40); PathUtils.CalculateBresenhamProductsToRectangle(5, 5, mapdata.grid, fullArea, (x, y) => x + y, 0, distance.grid); for (int i = 0; i < 20; i++) { Console.WriteLine("3 " + i + " dist = " + distance.grid[3][i]); } return(0); } else if (args[0] == "-bfs") { DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] { 5, 6, 7 }, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List <MapRoom> allRooms = drmg.Run(mapdata.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] { 5, 6, 7 }, MapCoordinate.GenerateRandom(), 2, new int[] { 0, 100000, 100000, 0, 0, 100000, 0, 0 }); dcmg.Run(mapdata.grid, fullArea, allRooms); int xStart = allRooms[0].bounds.xCenter; int yStart = allRooms[0].bounds.yCenter; int xEnd = allRooms[1].bounds.xCenter; int yEnd = allRooms[1].bounds.yCenter; Path path = PathUtils.BFSPath(xStart, yStart, xEnd, yEnd, null, (x, y) => (mapdata.grid[x][y] >= 6), null, (x, y, d) => ((((int)d) % 2) == 1 ? 140 : 100), fullArea); if (path != null) { int[][] pathSquares = PathUtils.UnrollPath(path, xStart, yStart); for (int i = 0; i < pathSquares.Length; i++) { mapdata.grid[pathSquares[i][0]][pathSquares[i][1]] = 8; } } mapdata.grid[xStart][yStart] = 9; mapdata.grid[xEnd][yEnd] = 10; mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: '*'); mapdata.AddSpaceType(glyph: '~'); mapdata.AddSpaceType(glyph: '#'); mapdata.AddSpaceType(glyph: ' '); mapdata.AddSpaceType(glyph: '+'); mapdata.AddSpaceType(glyph: 'v'); mapdata.AddSpaceType(glyph: 'S'); mapdata.AddSpaceType(glyph: 'E'); } else { Console.WriteLine("Specify -cave, -dungeon, or -office"); return(0); } DisplayMap(mapdata); return(0); }
// Use this for initialization void Start () { int player_x = 0; int player_y = 0; mapdata = new MapData(levelWidth,levelHeight); fullMapBounds = new MapRectangle(0, 0, levelWidth, levelHeight); ClearMapGenerator gen = new ClearMapGenerator(new int[] {0, 0}, MapCoordinate.GenerateRandom()); ClearMapGenerator gen2 = new ClearMapGenerator(new int[] {2, 1}, MapCoordinate.GenerateRandom()); gen2.Run(mapdata.grid, new MapRectangle(10, 10, 10, 10), null); List<MapRoom> blockedList = new List<MapRoom>(); MapRectangle fullArea = new MapRectangle(0, 0, 40, 40); blockedList.Add(new MapRoom(new MapRectangle(10, 10, 10, 10))); gen.Run(mapdata.grid, fullArea, blockedList); DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List<MapRoom> allRooms = drmg.Run(mapdata.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 2, new int[] {0, 100000, 100000, 0, 0, 100000, 0, 0}); dcmg.Run(mapdata.grid, fullArea, allRooms); mapdata.AddSpaceType(glyph: '#', passable: false, transparent: false); mapdata.AddSpaceType(glyph: '#', passable: false, transparent: false); mapdata.AddSpaceType(glyph: '#', passable: false, transparent: false); mapdata.AddSpaceType(glyph: '*', passable: true, transparent: true); mapdata.AddSpaceType(glyph: '~', passable: true, transparent: true); mapdata.AddSpaceType(glyph: '#', passable: false, transparent: false); mapdata.AddSpaceType(glyph: ' ', passable: true, transparent: true); mapdata.AddSpaceType(glyph: '+', passable: true, transparent: false); bool[][] visibility_map = new bool[levelHeight][]; for (int i = 0; i < levelWidth; i++) { visibility_map[i] = new bool[levelWidth]; for (int j = 0; j < levelHeight; j++) { visibility_map[i][j] = false; bool keepLooping = true; for (int x = i-1; (keepLooping == true) && (x <= i+1); x++) { for (int y = j-1; (keepLooping == true) && (y <= j+1); y++) { if ( (x >= 0) && (x < levelWidth) && (y >= 0) && (y < levelHeight) && (mapdata.palette[mapdata.grid[x][y]].passable) ) { keepLooping = false; visibility_map[i][j] = true; } } } } } for (int i = 0; i < levelHeight; i++) { tileGrid.Add(new List<GameObject>()); subTileGrid.Add(new List<GameObject>()); for (int j = 0; j < levelWidth; j++) { // XXX this is profoundly dumb -- we're just assigning the player coords to the last passable square. But it's temporary. if (mapdata.palette[mapdata.grid[j][i]].passable) { player_x = j; player_y = i; } // special case for doors :( -- they need a floor. if (mapdata.grid[j][i] == 7) { var flr = Instantiate(this.tilePrefabs[6]) as GameObject; flr.transform.position = new Vector3(j, i, 1); subTileGrid[i].Add(flr); } else { subTileGrid[i].Add(null); } var o = Instantiate(this.tilePrefabs[mapdata.grid[j][i]]) as GameObject; o.transform.position = new Vector3(j, i, 0); var sts = o.GetComponent<ShapeTerrainScript>(); if (sts) { int surroundNum = 0; // 1: north if ( (i < 39) && (visibility_map[j][i+1]) && (! mapdata.palette[mapdata.grid[j][i+1]].passable) ) { surroundNum += 1; } // 2: east if ( (j < 39) && (visibility_map[j+1][i]) && (! mapdata.palette[mapdata.grid[j+1][i]].passable) ) { surroundNum += 2; } // 4: south if ( (i > 0) && (visibility_map[j][i-1]) && (! mapdata.palette[mapdata.grid[j][i-1]].passable) ) { surroundNum += 4; } // 8: west if ( (j > 0) && (visibility_map[j-1][i]) && (! mapdata.palette[mapdata.grid[j-1][i]].passable) ) { surroundNum += 8; } sts.SetSprite(surroundNum); if (! visibility_map[j][i]) o.GetComponent<SpriteRenderer>().enabled = false; } tileGrid[i].Add(o); } } this.player = Instantiate(this.playerPrefab) as GameObject; Vector3 pos = new Vector3(player_x, player_y, 0); this.player.transform.position = pos; this.player.transform.SetParent(transform); GameObject camera = Instantiate( cameraPrefab ); pos.z=-10; camera.transform.position = pos; camera.GetComponent<CameraScript>().target = this.player.transform; }
static public void Main () { //UI d = new VT100UI(); VT100UI d = new VT100UI(); // This is just a placeholder for (int x = 0; x < 80; x++) { d.DrawAt(x,3," ",0,0,0,0,0,64); } for (int x = 0; x < 80; x++) { d.DrawAt(x,22," ",0,0,0,0,0,64); } UIMapElement map_element = d.MapElement( x: 0, y: 4, h: 17 ); ClearMapGenerator gen = new ClearMapGenerator(new int[] {0, 0}, MapCoordinate.GenerateRandom()); map_element.map = new MapData(80,40); ClearMapGenerator gen2 = new ClearMapGenerator(new int[]{2, 1}, MapCoordinate.GenerateRandom()); gen2.Run(map_element.map.grid, new MapRectangle(10, 10, 10, 10), null); List<MapRoom> blockedList = new List<MapRoom>(); MapRectangle fullArea = new MapRectangle(0, 0, 80, 40); blockedList.Add(new MapRoom(new MapRectangle(10, 10, 10, 10))); gen.Run(map_element.map.grid, fullArea, blockedList); DungeonRoomMapGenerator drmg = new DungeonRoomMapGenerator(new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 5, 12, 10, 3); List<MapRoom> allRooms = drmg.Run(map_element.map.grid, fullArea, blockedList); DungeonCorridorMapGenerator dcmg = new DungeonCorridorMapGenerator( new int[] {5, 6, 7}, MapCoordinate.GenerateRandom(), 2, new int[] {0, 100000, 100000, 0, 0, 100000, 0, 0}); dcmg.Run(map_element.map.grid, fullArea, allRooms); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '*'); map_element.map.AddSpaceType(glyph: '~', r: 0, g: 32, b: 255); map_element.map.AddSpaceType(glyph: '#', r: 128, g: 128, b: 128); map_element.map.AddSpaceType(glyph: '.', r: 64, g: 64, b: 64); map_element.map.AddSpaceType(glyph: '+', r: 128, g: 64, b: 0); d.DrawAt(54,3," 5 targets in range ",255,255,192,0,0,0); d.DrawAt(74,3,"[T] ",192,192,255,0,0,0); d.DrawAt(58,22," Press for help ",255,255,192,0,0,0); d.DrawAt(65,22,"[?]",192,192,255,0,0,0); map_element.Draw(); d.DrawScreen(); }