Page 1 of 1

### How woul i go about creating a random tilebased map

Posted: Wed Oct 28, 2015 8:11 pm
So what's the basic idea to do it.

### Re: How woul i go about creating a random tilebased map

Posted: Fri Oct 30, 2015 7:59 pm
You need some formula according to which you to edit the map. For example you can generate rooms and then connect them via pathways.

You can use the EditMap command to set tile values of a tilemap.

Code: Select all

``EDITMAP map, layer, x, y, tile``
• map The tilemap object.
• layer: 0 = background, 1 = over, 2 = collision, 3 = data
• x: Horizontal tile coordinate.
• y: Vertical tile coordinate.
• tile: Tile index
Here's an example taken from the documentation that creates a map with random tiles:

Code: Select all

``````FrameLimit 40

'Create a map from Blank
map=MakeMap(32,32,32,32)

'Apply some graphics on it
PaintObject map,tileset

'Randomly fill the map
For y=1 To MapHeight()
For x=1 To MapWidth()
If Rand(1,5)=5 Then
EditMap map,0,x,y,2 'drawing
EditMap map,2,x,y,1 'collision
Else
EditMap map,0,x,y,145
EndIf
Next x
Next y

'The game loop-itself
Repeat

If UpKey() Then MoveObject u,2
If DownKey() Then MoveObject u, -2
If LeftKey() Then TurnObject u,5
If RightKey() Then TurnObject u, -5

'Glue camera to object position
CloneCameraPosition u

DrawScreen

Forever``````

### Re: How woul i go about creating a random tilebased map

Posted: Sun Nov 01, 2015 4:35 pm
Thanks!