Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int x = _, y = _; // replace _ with the start x and y. I used the player's coordinate in my own code.
- int replaceId = _, id = _; // replaceId is the only block Id it will replace, and it will be replaced with `id`.
- List<Point> points = new List<Point>(); // Point is from System.Drawing & lets you remember x's/y's.
- Block[, ,] tempMap; // replace with whatever method you use to read the map.
- // It needs to contain all the blocks in the room. Or, at least the ones you are using.
- // I use a three-dimensional array of Block objects. Blocks are found by typing Map[x,y,layer].
- do // using a do-while instead of a while because the list starts at 0 and it wouldn't execute.
- {
- // if you're on the replace id, replace it and remove it from the list.
- if (tempMap[x, y, 0].Id == replaceId)
- {
- Build(id, x, y);
- tempMap[x, y, 0] = new Block(id, x, y);;
- for (int ind = 0; ind < points.Count; ind++)
- {
- if (points[ind].X == x && points[ind].Y == y)
- {
- points.RemoveAt(ind);
- }
- }
- }
- else // If you're not on the replace id, you're on the border. Select a random point and remove it from the list.
- {
- var RanPoint = points[MyRandom.Next(points.Count)]; // Do not use `new Random` here. Do it outside the loop.
- x = RanPoint.X;
- y = RanPoint.Y;
- for (int ind = 0; ind < points.Count; ind++)
- {
- if (points[ind].X == x && points[ind].Y == y)
- {
- points.RemoveAt(ind);
- }
- }
- }
- // Move to the right.
- x++;
- if (tempMap[x, y, 0].Id == replaceId) // If it's on the replace id, replace it and add it to the list.
- {
- b.Push.Build(id, x, y);
- tempMap[x, y, 0] = new Block(id, x, y);;
- points.Add(new Point(x, y));
- }
- // Moooove to the left.
- x -= 2;
- if (tempMap[x, y, 0].Id == replaceId)
- {
- b.Push.Build(id, x, y);
- tempMap[x, y, 0] = new Block(id, x, y);;
- points.Add(new Point(x, y));
- }
- // 2 hops this time (go one space above the original)
- x++;
- y++;
- if (tempMap[x, y, 0].Id == replaceId)
- {
- b.Push.Build(id, x, y);
- tempMap[x, y, 0] = new Block(id, x, y);;
- points.Add(new Point(x, y));
- }
- // go one space below the original
- y -= 2;
- if (tempMap[x, y, 0].Id == replaceId)
- {
- b.Push.Build(id, x, y);
- tempMap[x, y, 0] = new Block(id, x, y);;
- points.Add(new Point(x, y));
- }
- y++;
- // You just added a few points to the list. Return, select a random one, delete it, and repeat until there are none left.
- // Often times it will select a point that is already surrounded with dots, making the process much quicker.
- } while (points.Count > 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement