Creating your own map editor is not difficult as long as you understand how to use and manipulate the arrays that will hold your level data.
A simple editor could be something like this
// --------------------------------- //
// Project: simple_map_editor
// Start: Monday, March 04, 2013
// IDE Version: 10.283
SETCURRENTDIR("Media") // go to media files
SETSCREEN 640,480,0
GLOBAL map%[]
GLOBAL colour%[]
DIM map[20][15]
DIM colour[10]
colour[0]=RGB(0,0,0)
colour[1]=RGB(255,0,0)
colour[2]=RGB(0,255,0)
colour[3]=RGB(0,0,255)
colour[4]=RGB(255,255,255)
colour[5]=RGB(255,0,255)
colour[6]=RGB(255,255,0)
colour[7]=RGB(0,255,255)
SYSTEMPOINTER TRUE
main()
// Main function
FUNCTION main:
LOCAL mx%, my%, b1%, b2%, cx%, cy%, gfx%
WHILE TRUE
// Tiles
FOR n=0 TO 7
DRAWRECT n*32,0,32,32,colour[n]
NEXT
PRINT "LOAD",320,16
PRINT "SAVE",384,16
PRINT "NEW",448,16
// Mouse position
MOUSESTATE mx,my,b1,b2
// Cursor position
cx=mx/32
cy=my/32
// Select options
IF b1 AND cy=0
IF cx<8 THEN gfx=cx // Pick tile
IF cx=10 THEN load_data() // Load data
IF cx=12 THEN save_data() // Save data
IF cx=14 THEN clear_data() // Clear data
ENDIF
// Draw screen
FOR y=1 TO 14
FOR x=0 TO 19
DRAWLINE x*32,32,x*32,480,RGB(64,64,64)
DRAWLINE 0,y*32,640,y*32,RGB(64,64,64)
IF map[x][y]>0 THEN DRAWRECT x*32,y*32,32,32,colour[map[x][y]]
PRINT map[x][y],x*32,y*32
NEXT
NEXT
// Paint with colour onto map
IF b1 AND cy>0 THEN map[cx][cy]=gfx
SHOWSCREEN
WEND
ENDFUNCTION
// Clear data
FUNCTION clear_data:
FOR y=0 TO 14
FOR x=0 TO 19
map[x][y]=0
NEXT
NEXT
ENDFUNCTION
// Load map data
FUNCTION load_data:
LOCAL file$, ok%
file$="level.dat"
ok=DOESFILEEXIST(file$)
IF ok
OPENFILE (1,file$,1)
FOR y=0 TO 14
FOR x=0 TO 19
READWORD 1,map[x][y]
NEXT
NEXT
CLOSEFILE 1
ENDIF
ENDFUNCTION
// Save map data
FUNCTION save_data:
LOCAL file$
file$="level.dat"
OPENFILE (1,file$,0)
FOR y=0 TO 14
FOR x=0 TO 19
WRITEWORD 1,map[x][y]
NEXT
NEXT
CLOSEFILE 1
ENDFUNCTION
This code shows a number of important features in a map editor, including -
- Storing map data in an array
- Using array data to display a map
- Saving the array
- Loading the array
It's simple, but it works. This code can easily be adapted to use sprites instead of rectangles.