public static List<GPoint> FixRoads (Grid g, List<GPoint> rVHplusO, Vector2 blockSize) { //we will need to create a temporary grid that contains all of the new points //then iterate through it by the blocksize as done earlier //for each intersection check if there is a road to the left or down //if there is one left, then create a vertical road as done earlier //if there is one down, then create a horizontal road as done earlier //also create an intersection at the point List<GPoint> fixedRoads = new List<GPoint> (); Grid tG = new Grid (g); tG.Fill (GPoint.PType.TILE_GRASS); tG.UpdatePoints (rVHplusO); for (float ix=1.0f; ix<tG.GetXYMax().x; ix+=blockSize.x) { //iterate up by blocksize for (float iy=1.0f; iy<tG.GetXYMax().y; iy+=blockSize.y) { //iterate right by blocksize //set the scan point to the current position on the grid ScanPoint sp1 = new ScanPoint (new Vector2 (ix, iy)); //move the scanpoint to the left and check if is anything but background if (!tG.GetPoint (sp1.VirtualMove (Direction.w)).IsBackgroundTile ()) { //create a vertical road blocksize.y units long //probably going to do this with a for loop fixedRoads.Add (new GPoint (sp1.Position (), GPoint.PType.TILE_ROADI)); fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x, sp1.Position ().y + blockSize.y), GPoint.PType.TILE_ROADI)); for (float iy2 = 1.0f; iy2<blockSize.y; iy2+=1.0f) { fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x, sp1.Position ().y + iy2), GPoint.PType.TILE_ROADV)); } } if (!tG.GetPoint (sp1.VirtualMove (Direction.s)).IsBackgroundTile ()) { //create a horizontal road blocksize.x units long //probably going to do this with a for loop fixedRoads.Add (new GPoint (sp1.Position (), GPoint.PType.TILE_ROADI)); fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x + blockSize.x, sp1.Position ().y), GPoint.PType.TILE_ROADI)); for (float ix2 = 1.0f; ix2<blockSize.x; ix2+=1.0f) { fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x + ix2, sp1.Position ().y), GPoint.PType.TILE_ROADH)); } } } } return fixedRoads; }
public static List<GPoint> Generate (Grid g, int numOfTrees) { List<GPoint> trees = new List<GPoint> (); int i = 0; while (i < numOfTrees) { int rX = (int)Random.Range (g.GetXYMin ().x, g.GetXYMax ().x); int rY = (int)Random.Range (g.GetXYMin ().y, g.GetXYMax ().y); if (g.GetPoint (rX, rY).GetPType () == GPoint.PType.TILE_GRASS) { trees.Add (new GPoint (new Vector2 ((float)rX, (float)rY), GPoint.PType.TILE_TREE)); i++; } } return trees; }
public static List<GPoint> FindRoadOrigins (Grid g, Vector2 blockSize) { List<GPoint> roadOrigins = new List<GPoint> (); //iterate right by blocksize for (float ix=1.0f; ix<g.GetXYMax().x; ix+=blockSize.x) { //iterate up by blocksize for (float iy=1.0f; iy<g.GetXYMax().y; iy+=blockSize.y) { //start at the next block right and up //so the previous iteration set is the 1 //and where this iteration set starts is the 2 //this is because we start at ix2 = 1.0f and iy2 = 1.0f //10000100001 //00000000000 //02000020000 //10000100001 //iterate right for (float ix2=1.0f; ix2<blockSize.x; ix2+=1.0f) { //iterate up for (float iy2=1.0f; iy2<blockSize.y; iy2+=1.0f) { //check if the tile at the given point is anything other //than a background tile if (!g.GetPoint (new Vector2 (ix + ix2, iy + iy2)).IsBackgroundTile ()) { //if it is, then add a road intersection at start point roadOrigins.Add (new GPoint (new Vector2 (ix, iy), GPoint.PType.TILE_ROADI)); } } } } } return roadOrigins; }