VB Code:
Sub FloodFill( StartX, Start )
CreateTodoList() 'Empty list that holds the items we have to check
CreateDoneMap( Width, Height ) 'Bool map storing already processed positions
TodoList.Add( StartX, StartY ) 'Adds first item to list
While( TodoList.Count > 0 ) 'While there is something to do...
Position = TodoList.RemoveFirst() 'Remove one item (get x and y)
DoneMap( Pos ) = True 'Mark current position as done
If FreeTile( x, y ) Then 'If current position is free
FillTile( x, y ) 'Process that tile, eg. fill it
'Add neighbours if they were not already checked
If Not DoneMap( x, y-1 ) Then: TodoList.Add( x, y-1 )
If Not DoneMap( x+1, y ) Then: TodoList.Add( x+1, y )
If Not DoneMap( x, y+1 ) Then: TodoList.Add( x, y+1 )
If Not DoneMap( x-1, y ) Then: TodoList.Add( x-1, y )
Endif
Wend
End Sub