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

Post your coding questions such as 'how to' here.
Vaarna
Newcomer
Posts: 1
Joined: Wed Oct 28, 2015 7:55 pm

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

So what's the basic idea to do it.
CCE
Artist
Posts: 650
Joined: Mon Aug 27, 2007 9:53 pm

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

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)
u=LoadObject("Media\guy.bmp",72)

'Apply some graphics on it
tileset=LoadImage("Media\tileset.bmp")
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``````
433434

Thanks!