This guide assumes you have basic programming knowledge. You have been warned.
So, everyone loves the DATA instruction, right? Some may find it useless, but probably not a hinderance. Well, here's yet another use for it: making map data.
DIM MAP$[height]'Visible map data
DIM MAD$[height]'Map collision data
DIM BGTABLE$[amount]'BG tile table
DIM I,J'FOR loop
DIM CH$,SCDT'Data display
Ok, first we need a BG table that holds all of the different tiles you want in your map. This way, you can have only a small amount of characters you can use to make your data. In other words, you won't need to use CHR$(17) or anything weird like that. So you can set these manually like this:
Or you could set them with DATA where your map data will be:
So these are your map tiles you work with. To read them from data, just put after RESTORE a FOR loop:
This way it reads your BG table automatically.
Now we need to cover the map data. We are using the array MAP$. This has the visible map stored in it. You set this with the DATA instruction:
Reading this can be done with another FOR loop:
FOR I=0 TO LEN(MAP$)-1
Now we've read that.
The next thing we need to read is the collision data, which we will specify the same way as we did with MAP$ data. We will use the array MAD$. We literally do this the exact same as MAP$ except that there's no COLTABLE or anything. At least, I prefer not to do that. You could do that if you had a ton of collision types, but I usually don't so I just use the same characters for the same things anyway. Like 0 is no collision, 1 is collision on all sides, etc. Not too many combos.
Now for the harder part: using this data. Displaying the map is hard to figure out, but is easily done with only a few lines. You need a nested FOR loop and the string function MID$. You also need to play with character codes. So you put your nested FOR loops, something like this:
FOR I=0 TO LEN(MAP$)-1
FOR J=0 TO LEN(MAP$[I])-1
So the outer loop goes through the array, and the inner loop goes through the array's current element. Now you need some magic to single out a character and use it. So, we use the definetly-for sure magic function MID$. Just set a string to a section of the MAP$ line, and turn it into a map tile.
This gets the map tile. Now we need to convert this into something that BGPUT can read:
We basically just reduced the subscript so that it is now in range of the BGTABLE and turned that tile into our screen data. Now we just need to BGPUT that on screen:
As for collision, just do the same thing in the same nested loops, just on a different layer. The only purpose of doing this extra collision layer is so that you can test for a specific function, like if a block is solid or if it's a door; not have the visible map stuff get in the way or anything.
Hope this helps anyone wondering about DATA maps!