Hi guys,
here I am again. And now I've come with a map - maker!
Again, like my animator program, it's open source. Or for the people that would like a exe, just click the download button.
Features:
- Resizing
- 100 tiles
- Change each character
- Change each color
- Exports ".bmp" (heightmaps)
- Exports ".dat" (data map)
And here is the code:
sync on : sync rate 0
`set variables
xsize = 20 : ysize = 20
mapx = 5 : mapy = 5
startprogram:
cls
if ysize > 43 then ysize = 43
if xsize > 45 then xsize = 45
dim map_data(xsize,ysize)
`draw grid and get an image from it
ink rgb(75,75,75),0
for x = 0 to xsize
line x*10,0,x*10,ysize*10
next x
for y = 0 to ysize
line 0,y*10,xsize*10,y*10
next y
get image 1,0,0,((xsize)*10)+1,((ysize)*10)+1
`variables
tool$ = "freehand"
dim tile$(100) : dim tile(100)
for i = 1 to 100
tile$(i) = chr$(47+i)
tile(i) = i * 25600
next i
tile(1) = rgb(0,0,0)
ctile = 2
`clear map
for y = 1 to ysize
for x = 1 to xsize
map_data(x,y) = 1
next x
next y
do
`clear screen
cls
`paste board
paste image 1,mapx,mapy
`get mouse position on map
mposx = int(((mousex() - mapx)/10)+1)
mposy = int(((mousey() - mapy)/10)+1)
`display mouse position
if mposx => 0 and mposx <= xsize
if mposy => 0 and mposy <= ysize
ink rgb(75,75,75),0
center text screen width() - 40,20,str$(mposx) + " : " + str$(mposy)
if mouseclick() = 2 then ctile = map_data(mposx,mposy)
endif
endif
ink rgb(75,75,75),0
center text screen width() - 40, 40, str$(screen fps())
center text screen width() - 40, 60, "rgb(" + str$(rgbr(tile(ctile))) + "," + str$(rgbg(tile(ctile))) + "," + str$(rgbb(tile(ctile))) + ")"
`buttons
gosub buttons
`freehand tool
if tool$ = "freehand" then gosub freehand
sync
loop
buttons:
`background
ink 0,0
box 0,screen height() - 30,screen width()-1,screen height() - 1
`buttons
if button1(10,screen height() - 25,80,20,"Export") > 0
repeat
cls
ink rgb(75,75,75),0
print "Export bitmap (0) or dat(1) file?"
input q
until q <= 1 and q => 0
if q = 1 then ext$ = ".dat" else ext$ = ".bmp"
repeat
cls
paste image 1,320,0
ink rgb(255,255,255),0
set cursor 5,10
input "Filename: ",filename$
until file exist(filename$ + ext$) = 0
if ext$ = ".dat"
open to write 1,filename$ + ".dat"
for y = 1 to ysize
string$ = ""
for x = 1 to xsize
string$ = string$ + tile$(map_data(x,y))
next x
write string 1,string$
next y
close file 1
else
cls
for y = 1 to ysize
for x = 1 to xsize
ink tile(map_data(x,y)),0
dot x,y
next x
next y
get image 10,0,0,xsize,ysize
text 0,ysize+5,"Press any key to continue"
suspend for key
save image filename$ + ".bmp",10
delete image 10
endif
endif
`switch between tiles
if textbutton(110,screen height() - 15,"<<") > 0 and hold = 0
hold = 1 : dec ctile
endif
ink tile(ctile),0
center text 150,screen height() - 15 - (text height(str$(ctile)))/2,"tile: " + str$(ctile)
if textbutton(190,screen height() - 15,">>") > 0 and hold = 0
hold = 1 : inc ctile
endif
if ctile < 1 then ctile = 1
if ctile > 100 then ctile = 100
`switch between characters
if textbutton(210, screen height() - 15, "<<") > 0 and hold = 0
hold = 1
if asc(tile$(ctile)) > 0
tile$(ctile) = chr$(asc(tile$(ctile))-1)
endif
endif
ink rgb(75,75,75),0
center text 240,screen height() - 15 - (text height(tile$(ctile))/2),tile$(ctile)
if textbutton(270,screen height() - 15, ">>") > 0 and hold = 0
hold = 1
tile$(ctile) = chr$(asc(tile$(ctile))+1)
endif
`color controls
redv = rgbr(tile(ctile))
greenv = rgbg(tile(ctile))
bluev = rgbb(tile(ctile))
ink rgb(75,75,75),0
box 300,screen height() - 24,555,screen height() - 18
box 300,screen height() - 16,555,screen height() - 10
box 300,screen height() - 8,555,screen height() - 2
`red value display
ink rgb(255,0,0),0
box 300,screen height() - 24,300 + redv, screen height() - 18
ink rgb(0,255,0),0
box 300,screen height() - 16,300 + greenv,screen height() - 10
ink rgb(0,0,255),0
box 300,screen height() - 8 ,300 + bluev, screen height() - 2
`control colors
if mousex() > 300 and mousex() < 556 and mouseclick() = 1
if mousey() > screen height() - 24 and mousey() < screen height() - 18
tile(ctile) = rgb(mousex() - 300,greenv,bluev)
endif
if mousey() > screen height() - 16 and mousey() < screen height() - 10
tile(ctile) = rgb(redv,mousex() - 300,bluev)
endif
if mousey() > screen height() - 8 and mousey() < screen height() - 2
tile(ctile) = rgb(redv,greenv,mousex() - 300)
endif
endif
`resize map
if textbutton(screen width() - 40, 100, "Resize Map") > 0
cls
ink rgb(75,75,75),0
input "Tiles X: ",xsize
input "Tiles Y: ",ysize
goto startprogram
endif
`exit
if button1(screen width() - 60,screen height() - 25,50,20,"Quit") > 0 then end
`unlock mouse
if mouseclick() = 0 then hold = 0
return
freehand:
`get position
if mouseclick() = 1 and mousey() < screen height() - 30
if mposx => 0 and mposx <= xsize
if mposy => 0 and mposy <= ysize
map_data(mposx,mposy) = ctile
ink tile(ctile),0
box mapx + ((mposx-1)*10)+1,mapy + ((mposy-1)*10)+1,mapx + (mposx*10)-1,mapy + (mposy*10)-1
get image 1,mapx,mapy,mapx + (xsize*10)+1,mapy + (ysize*10)+1
endif
endif
endif
return
`**********************************
`FUNCTIONS
`**********************************
function button1(x,y,xsize,ysize,content$)
colortheme = rgb(75,75,75)
pressed = 0
if mousex() > x and mousex() < x + xsize
if mousey() > y and mousey() < y + ysize
if mouseclick() > 0 then pressed = mouseclick()
endif
endif
if pressed = 1
ink rgb(rgbr(colortheme)/2,rgbg(colortheme)/2,rgbb(colortheme)/2),0
box x,y,x+xsize-1,y+ysize-1
ink rgb(255,255,255),0
box x+1,y+1,x+xsize,y+ysize
else
ink rgb(rgbr(colortheme)/2,rgbg(colortheme)/2,rgbb(colortheme)/2),0
box x+1,y+1,x+xsize,y+ysize
ink rgb(255,255,255),0
box x,y,x+xsize-1,y+ysize-1
endif
ink colortheme,0
box x+1,y+1,x+xsize-1,y+ysize-1
ink rgb(255,255,255),0
center text x+(xsize/2),y + (ysize/2) - (text height(content$)/2),content$
endfunction pressed
function textbutton(x,y,text$)
tx = text width(text$) / 2
ty = text height(text$)/2
pressed = 0
if mousex() < x + tx and mousex() > x - tx
if mousey() > y - ty and mousey() < y + ty
pressed = 1
endif
endif
if pressed = 1 then ink rgb(255,255,255),0 else ink rgb(75,75,75),0
center text x,y-ty,text$
if mouseclick() = 0 then pressed = 0
endfunction pressed
Controls:
Right mouseclick: changes the current tile to that of the one on the map at the mouse position.
Left mouseclick: draws a tile to the current tile.
Click on the colors to change the colors
Click on the << and >> to inc or dec tiles or character.
Cheers everyone!
Sven B
Immunity and Annihalation makes Immunihalation...