REM Project: map_editor
REM Created: 6/25/2008 5:39:14 PM
REM
REM ***** Main Source File *****
REM
gosub _startup
gosub _editor
_startup:
set display mode 1024,768,32
set image colorkey 255,0,255
get image 1,0,0,1,1
sprite 1,0,0,1
set sprite 1,0,1
delete sprite 1
delete image 1
editordir$=get dir$()
cls 0
type mapinfo
mapname$ as string
xtiles as integer
ytiles as integer
endtype
type button
btx as integer
bty as integer
bbx as integer
bby as integer
endtype
dim button(20) as button
for b=1 to 20
button(b).btx=0
button(b).bty=0
button(b).bbx=0
button(b).bby=0
next b
dim mapinfo(1) as mapinfo
mapinfo(1).mapname$=""
mapinfo(1).xtiles=250
mapinfo(1).ytiles=175
load image "usaot.jpg",1000
load image "grass.bmp",1
load image "water.bmp",2
load image "coast1.bmp",3
load image "coast2.bmp",4
load image "coast3.bmp",5
load image "coast4.bmp",6
load image "coast5.bmp",7
load image "coast6.bmp",8
load image "coast7.bmp",9
load image "coast8.bmp",10
load image "coast9.bmp",11
load image "coast10.bmp",12
load image "coast11.bmp",13
load image "coast12.bmp",14
return
_editor:
type mapdat
tt as integer
endtype
dim mapdat(mapinfo(1).xtiles,mapinfo(1).ytiles) as mapdat
for tx=0 to (mapinfo(1).xtiles)-1
for ty=0 to (mapinfo(1).ytiles)-1
mapdat(tx,ty).tt=0
next ty
next tx
menu=1
currenttile=1
sxl=0
syl=0
do
cls
`start of sequence
up=upkey()
down=downkey()
left=leftkey()
right=rightkey()
key=scancode()
mc=mouseclick()
if up=1
if syl>0
syl=syl-1
endif
endif
if down=1
if syl<mapinfo(1).ytiles-60
syl=syl+1
endif
endif
if left=1
if sxl>0
sxl=sxl-1
endif
endif
if right=1
if sxl<mapinfo(1).xtiles-66
sxl=sxl+1
endif
endif
mx=mousex()
my=mousey()
mxl=mx/12
myl=my/12
mxx=mxl+sxl
myy=myl+syl
txl=((mxx-sxl)*12)
tyl=((myy-syl)*12)
paste image 1000,0-(sxl*12),0-(syl*12)
ink rgb(0,200,0),rgb(0,0,0)
for drawgridx=0 to 792
line drawgridx,0,drawgridx,720
inc drawgridx,11
next drawgridx
for drawgridy=0 to 720
line 0,drawgridy,792,drawgridy
inc drawgridy,11
next drawgridy
for tx=sxl to sxl+66
for ty=syl to syl+60
if mapdat(tx,ty).tt>0
paste image mapdat(tx,ty).tt,((tx-sxl)*12),((ty-syl)*12)
endif
next ty
next tx
ink rgb(100,100,100),rgb(0,0,0)
box 0,721,1024,768
box 793,0,1024,721
if mx<792
if my<720
ink rgb(0,0,0),rgb(0,0,0)
set cursor 10,735
print "x:",mxx
set cursor 50,735
print "y:",myy
if mc=1
paste image currenttile,txl,tyl
mapdat(mxx,myy).tt=currenttile
endif
if mc=2
mapdat(mxx,myy).tt=0
endif
endif
endif
y=20
for img=1 to 14
ink rgb(255,255,255),0
box button(img).btx,button(img).bty,button(img).bbx,button(img).bby
paste image img,800,y
button(img).btx=799
button(img).bty=y-1
button(img).bbx=813
button(img).bby=y+13
if mx>button(img).btx
if mx<button(img).bbx
if my>button(img).bty
if my<button(img).bby
ink rgb(0,0,255),0
box button(img).btx,button(img).bty,button(img).bbx,button(img).bby
paste image img,800,y
if mc=1
currenttile=img
endif
endif
endif
endif
endif
y=y+20
next img
loop
This editor works as is, but I am still making adjustments to it. I would like to add more features like coloring multiple tiles at one time, auto-blending of water and land tiles, multiple layers for city and boundry lines, loading and saving different maps, and other features. Anyway, if you can shape this code to fit your needs feel free to use it.