Rectangles of a value in a 2d array.

BlitzMax Forums/BlitzMax Beginners Area/Rectangles of a value in a 2d array.

This is a very difficult problem that I just can't wrap my mind around. I would be really very grateful if anyone could solve it for me. Basically I have an array in 2 dimensions.

I would like to populate the array with "blocks" of a value. These blocks will serve as rooms for a dungeon. I suppose they would have a max width and a max height.

So in our 2d array, the value 0 is a non-room square and the value 1 is part of a room block of squares. I don't need anything fancy just rectangles of the value 1 fitted inside an array.

I have a few dungeon generation algorithms I want to try but they all start with the rooms in place first. So fellows, how do I seed a 2d array with room squares?

how is this?

Local dx:Int = 640
Local dy:Int = 480
Local dungeonplan:Int[dx,dy]


Function fillroom(layout:Int[,], x:Int, y:Int, w:Int, h:Int)
	For Local i:Int = 0 Until w
		For Local j:Int = 0 Until h
			layout[x+i, y+j] = True
		Next
	Next	
End Function

fillroom(dungeonplan, 0, 0, 50, 50)       'make some "rooms" in array
fillroom(dungeonplan, 100, 0, 50, 50)
fillroom(dungeonplan, 0, 100, 40, 60)
fillroom(dungeonplan, 300, 400, 90, 20)

Graphics(dx, dy)                'display the contents of the array
SetColor(255, 255, 255)

For Local x:Int = 0 Until dx
	For Local y:Int = 0 Until dy
		If dungeonplan[x, y] = True Plot(x, y)
	Next
Next

Flip

WaitMouse()


ugly... no error checking to make sure values are not written beyond array boundaries... but there you go.

The problem is more packing random sized rooms into an array without overlapping. Making rectangles is not really the challange.