public static List<GPoint> Generate (Grid g, GPoint.PType walkType, int steps) { //make the last direction random, to randomise the opposite of the first direction //start at 1 //pick a new direction //if the direction is okay //move the test vector //if the new position is in bounds //add the point //iterate the loop //set the last direction to the new direction List<GPoint> points = new List<GPoint> (); //set the scanpoint in the middle of the grid ScanPoint scan = new ScanPoint (g.GetSize () / 2); //set the last direction as a new direction Direction lastDir = PickNewDirection (); //set the stepcount at 1 int stepcount = 1; //if the stepcount is less than or equal to the max number of steps while (stepcount<=steps) { //pick a new direction and set it as the new direction Direction newDir = PickNewDirection (); //if the new direction is not the opposite of the last direction if (IsValidDirection (newDir, lastDir)) { //move the testposition in the new direction Vector2 testPos = scan.VirtualMove (newDir); //check if the new position is within the constraints if (g.PositionInBounds (testPos)) { //if it is, move the scanpoint in the direction scan.Move (newDir); //iterate the stepcount stepcount++; //add a new gpoint to the list of the designated type points.Add (new GPoint (scan.Position (), walkType)); //Debug.Log ("point added to grid at " + scan.Position ()); } //set the last dir to the new dir to ensure accurate direction checking //when the loop repeats lastDir = newDir; } //otherwise, do absolutely nothing } Debug.Log ("generated a " + points.Count + " point line of " + walkType); Grid tg = new Grid (g); tg.Clear (); tg.UpdatePoints (points); List<GPoint> processed = new List<GPoint> (); processed = PostProcess (tg, walkType, walkType); return processed; }