How woul i go about creating a random tilebased map

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

How woul i go about creating a random tilebased map

Post by Vaarna » Wed Oct 28, 2015 9:11 pm

So what's the basic idea to do it.

User avatar
CCE
Artist
Artist
Posts: 650
Joined: Mon Aug 27, 2007 9:53 pm

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

Post by CCE » Fri Oct 30, 2015 8: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)
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

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

Post by 433434 » Sun Nov 01, 2015 5:35 pm

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests