When I started looking at getting a level made I ran into the same problems with finding help on the net, so I just worked it out myself using methods which made sense to me, therefore there maybe problems all over the place, but, incase you are interested, here's a few idea's.
-Use a Map Editor, there's no need to make your own, there are many out there already, I decided to use 'Tile Studio' (which has a Map Studio built into it). I didn't do too much research before choosing this program, it just seemed to do what I needed it to.
-Tile studio has a scripting language built into it, so you can specify how it saves the maps you create, I made a little export script that outputs 3 files which can then be read into darkbasic, if you use TileStudio then try out using this export code:
#tileset
TileSetName=<TileSetIdentifier>.bmp
#tilebitmap <TileSetIdentifier>.bmp 320
#end tilebitmap
#end tileset
;
#file <TileSetIdentifier>.ini
;
#tileset
#map
NumOfTiles=<TileCount>
Tile_Width=<TileWidth>
Tile_Height=<TileHeight>
Map_Width=<MapWidth>
Map_Height=<MapHeight>
#end map
#end tileset
;
#end file
;
#file <TileSetIdentifier>.col
;
#tileset
#map
#mapdata
<mapcode>\n
#end mapdata
#end map
#end tileset
;
#end file
;
#file <TileSetIdentifier>.txt
;
#tileset
#map
#mapdata
<TileNumber:"%3d">\n
#end mapdata
#end map
This will give you 4 files, 1 will be the bitmap of the tiles you have used, one will be an ini file that holds the map parameters, 1 will be a txt file which contains map data of which sprites go where and finally a .col file that holds information about the collisions. You can pretty much ignore the .col file for now, I needed to use it to allow collisions to work specially (for example in sonic you can jump UP through many ledges, but then don't fall back through them).
So once you have created your map in tile studio, used that script, you should have the 4 files mentioned, put them into your darkbasic working directory, you then need to import the data into a sensible place, for me i put the map parameters into variables, and the mapdata and collision map into two dimensional arrays, and the bmp of the tileset needs to be seperated into seperate tiles.
I found darkbasic couldn't read int's from an external text file so I borrowed and modified someone else's routine to get around this, here are my basic scripts to read in the data:
MAP PARAMETERS
function number_of_tiles(name$)
name2$=name$+".ini"
open to read 1, name2$
read string 1,temp$
for i=1 to len(temp$)
if mid$(temp$, i)="=" then equals_position=i
next i
answer$=right$(temp$, (len(temp$)-equals_position))
close file 1
endfunction val(answer$)
function tile_width(name$)
name2$=name$+".ini"
open to read 1, name2$
read string 1,temp$
read string 1,temp$
for i=1 to len(temp$)
if mid$(temp$, i)="=" then equals_position=i
next i
answer$=right$(temp$, (len(temp$)-equals_position))
close file 1
endfunction val(answer$)
function tile_height(name$)
name2$=name$+".ini"
open to read 1, name2$
read string 1,temp$
read string 1,temp$
read string 1,temp$
for i=1 to len(temp$)
if mid$(temp$, i)="=" then equals_position=i
next i
answer$=right$(temp$, (len(temp$)-equals_position))
close file 1
endfunction val(answer$)
function map_width(name$)
name2$=name$+".ini"
open to read 1, name2$
read string 1,temp$
read string 1,temp$
read string 1,temp$
read string 1,temp$
for i=1 to len(temp$)
if mid$(temp$, i)="=" then equals_position=i
next i
answer$=right$(temp$, (len(temp$)-equals_position))
close file 1
endfunction val(answer$)
function map_height(name$)
name2$=name$+".ini"
open to read 1, name2$
read string 1,temp$
read string 1,temp$
read string 1,temp$
read string 1,temp$
read string 1, temp$
for i=1 to len(temp$)
if mid$(temp$, i)="=" then equals_position=i
next i
answer$=right$(temp$, (len(temp$)-equals_position))
close file 1
endfunction val(answer$)
LOAD SPRITES
function load_sprites(Name$,NumOfTiles,TileWidth,TileHeight,MapWidth,MapHeight)
bitmap_name$=Name$+".bmp"
load bitmap bitmap_name$,1
SpritesPerRow=(bitmap width(1))/TileWidth
SpritesPerColoumn=(bitmap height(1))/TileHeight
for j=1 to SpritesPerColoumn
for i=1 to SpritesPerRow
get image 1000+((j-1)*SpritesPerRow)+i,((i-1)*TileWidth),((j-1)*TileHeight),((TileWidth*i)),((TileHeight*j))
sprite (((j-1)*SpritesPerRow)+i)+1000,1025,769,(((j-1)*SpritesPerRow)+i)+1000
`hide sprite (((j-1)*SpritesPerRow)+i)+1000
`show sprite 1001
next i
next j
delete bitmap 1
endfunction
COLLISION MAP
function collision_map(name$,MapWidth,MapHeight)
filename$=name$+".col"
filelen = file size(filename$)
open to read 1,filename$
` Define some Byte Codes as variables, Make Code More readable
negsign_chr=45
coma_chr=44
return_chr=10
zero_chr=48
nine_chr=57
` Init starting Value for our data... (NOT FOR USER)
value=0
value_negflag=1
Value_Chrsread=0
for lp=1 to filelen
read byte 1,newbyte
` decode this byte into something more useful..
if newbyte=negsign_chr
value_negflag=-1
endif
if newbyte=>zero_chr and newbyte<=nine_chr
newbyte2=newbyte-zero_chr
value=(value*10)+newbyte2
inc Value_Chrsread
endif
if newbyte=coma_chr or newbyte=return_chr
` dump VALUE to Screen
value=value*value_negflag
CollisionMap(x,y)=value;
if value>0
`set cursor 17*x,17*y
`print value
endif
if x<MapWidth+1 then x=x+1
if x=MapWidth+1
x=1
y=y+1
endif
`print value;", ";
` reset Values so we can contine processing file
value=0
value_negflag=1
Value_Chrsread=0
inc Numb_of_values_read
endif
next lp
if Value_ChrsRead<>0
value=value*value_negflag
print value
inc Numb_of_values_read
endif
close file 1
endfunction
MAP DATA
function map_data(name$,MapWidth,MapHeight)
filename$=name$+".txt"
filelen = file size(filename$)
open to read 1,filename$
` Define some Byte Codes as variables, Make Code More readable
negsign_chr=45
coma_chr=44
return_chr=10
zero_chr=48
nine_chr=57
` Init starting Value for our data... (NOT FOR USER)
value=0
value_negflag=1
Value_Chrsread=0
x=0
y=0
for lp=1 to filelen
read byte 1,newbyte
` decode this byte into something more useful..
if newbyte=negsign_chr
value_negflag=-1
endif
if newbyte=>zero_chr and newbyte<=nine_chr
newbyte2=newbyte-zero_chr
value=(value*10)+newbyte2
inc Value_Chrsread
endif
if newbyte=coma_chr or newbyte=return_chr
` dump VALUE to Screen
value=value*value_negflag
MapData(x,y)=value;
if x=MapWidth-1
x=0
y=y+1
else
x=x+1
endif
`print value;", ";
` reset Values so we can contine processing file
value=0
value_negflag=1
Value_Chrsread=0
inc Numb_of_values_read
endif
next lp
if Value_ChrsRead<>0
value=value*value_negflag
print value
inc Numb_of_values_read
endif
close file 1
endfunction
They are functions, the parameters them each take are all reasonably self explantory, basically the parameter function needs to be run first, that just takes the map name, the name of the files you exported, for example "map1" if you have "map1.bmp", "map1.txt", "map1.ini" and "map1.col" in your working directory. This function then sets the values of the sprite dimensions and map dimensions. You can then call the other functions with this information to load up the sprites, load in the mapdata into an array.
From there you can do what you want with it, basically if you read the sprites in from 0 to [number of sprites used], then the sprites numbers will DIRECTY relate the numbers in the MapData array, for example MapData[10][10] might have '6' stored in it, that means at position 10,10 on the screen, sprite 6 should be displayed.
It looks like other people have given other links for tutorials and examples simliar to what I have mentioned so I wont go into any more detail, however, if you would like any more information just ask and I'll try and explain in more detail and give some examples of how to integrate this functions into a game, (at the moment i have a game that can take any map made from tile studio, then i have a character that can run around the level, colliding with what he should collide with, acceleration as he runs, jumping, animations for the character, camera scrolling, and am more then happy to share any knowledge I have so far.
Steve