Map editor: Fill Command help

Started by
9 comments, last by Thekill473 11 years, 10 months ago
Well I was being stupid and missed one of my checks.

if (val.TileIndex == seed.TileIndex && val.Tileset == val.Tileset)


Is meant to be

if (val.TileIndex == seed.TileIndex && val.Tileset == seed.Tileset)


And here is the original i found online.

private static void Floodfill(byte[,] vals, Point q, byte SEED_COLOR, byte COLOR)
{
int h = vals.GetLength(0);
int w = vals.GetLength(1);

if (q.Y < 0 || q.Y > h - 1 || q.X < 0 || q.X > w - 1)
return;

Stack<Point> stack = new Stack<Point>();
stack.Push(q);
while (stack.Count > 0)
{
Point p = stack.Pop();
int x = p.X;
int y = p.Y;
if (y < 0 || y > h - 1 || x < 0 || x > w - 1)
continue;
byte val = vals[y, x];
if (val == SEED_COLOR)
{
vals[y, x] = COLOR;
stack.Push(new Point(x + 1, y));
stack.Push(new Point(x - 1, y));
stack.Push(new Point(x, y + 1));
stack.Push(new Point(x, y - 1));
}
}
}



At
http://stackoverflow.com/questions/1257117/does-anyone-have-a-working-non-recursive-floodfill-algorithm-written-in-c

Hope this post helps anybody else in the future looking for a flood fill algorithm.

This topic is closed to new replies.

Advertisement