I've made a few adjustments to the code to improve speed:
I got rid of capturing/pasting the screen image every loop.
I also added the choice of a few tiles (0-9) at the top of the keyboard.
Main Program
rem board creator for rpgs and other tilebased games
rem by Code Ninja
cls 0
sync on
#include "TileSetFunc.dba"
`these variables are essential to the workings of the functions
dim R(15,32,32)
dim G(15,32,32)
dim B(15,32,32)
Size=ReadTileset("newtileset.tst",5) : `last number must be less than/equal to the first number in the R/G/B arrays
GetTile(15,1) : `Makes a tile an Image to be used with sprites
cls 0
`get image 3,0,0,screen width(),screen height()
img#=1
do
`cls 0
`paste image 3,0,0,1
tilex=mousex()/32
tiley=mousey()/32
key=scancode()
if key=11
key=1
get image 13,0,0,screen width(),screen height()
cls 0
GetTile(key-1,key)
cls 0
paste image 13,0,0,1
img#=key
endif
if key>=2 and key<=6
get image 13,0,0,screen width(),screen height()
cls 0
GetTile(key-1,key)
cls 0
paste image 13,0,0,1
img#=key
endif
if keystate(48)=1
img#=12
endif
if mouseclick()=1
if img#=12
ink 0,0
box tilex*32,tiley*32,(tilex*32)+32,(tiley*32)+32
ink rgb(255,255,255),0
else
paste image img#,tilex*32,tiley*32,trans
endif
endif
` get image 3,0,0,screen width(),screen height()
sync
loop
Tileset Functions
`RPGToolkit Tileset Functions v1.0 by DragnBreth aka Code Ninja
`Needed variables
`R(#ofTiles2BRead,32,32)
`G(same as above)
`B(same as above)
`SYNTAX
`SizeOfTile=ReadTileset(filename$,#ofTiles2BRead)
`DrawTiles(xposition,yposition,First2Draw,Last2Draw,SizeOfTile)
`Reads tiles from a tileset to R/G/B arrays
function ReadTileset(filename$,TileAmount)
open to read 1,filename$
`read first byte; the tile version
read byte 1,TileVersion
`read bytes 2-4
for useless = 2 to 3
read byte 1,uselessness
next useless
`read fifth byte; tile detail
read byte 1,TileDetail
if TileDetail=1
TileSize=32
read byte 1,uselessness
endif
for times=0 to TileAmount
If TileDetail=1
for x=0 to (TileSize-1)
for y=0 to (TileSize-1)
`get blue
read byte 1,B(times,x,y)
`get red
read byte 1,R(times,x,y)
`get green
read byte 1,G(times,x,y)
if R(times,x,y)=0 and G(times,x,y)=0 and B(times,x,y)=0
R(times,x,y)=5
B(times,x,y)=5
G(times,x,y)=5
endif
if R(times,x,y)=0 and G(times,x,y)=1 and B(times,x,y)=2
R(times,x,y)=0
B(times,x,y)=0
G(times,x,y)=0
endif
next y
next x
endif
next times
close file 1
endfunction TileSize
`Draws the read tiles to the screen starting at the specified
`coordinates
function DrawTiles(xpos,ypos,FirstShow,SecondShow,TileSize)
Zoom=1
for tile=FirstShow to SecondShow
`if xpos+(32*timesy)>=160 then ypos=ypos+32 : timesy=0
for x=xpos+(32*timesx) to (TileSize+(32*timesx)-1)
for y=ypos to (TileSize+ypos-1)
ink rgb(R(tile,x-(32*timesx),y-ypos),G(tile,x-(32*timesx),y-ypos),B(tile,x-(32*timesx),y-ypos)),0
if Zoom<1 then Zoom=1
if Zoom>1
box (x * Zoom),(y * Zoom),(x * Zoom) + Zoom,(y * Zoom) + Zoom
endif
if Zoom=1
dot x,y
endif
next y
next x
if x=32+32*timesx then timesx=timesx+1
next tile
timesx=0
ink rgb(255,255,255),0
endfunction
`Captures a tile as an image
function GetTile(TileNumber,ImageNumber)
DrawTiles(0,0,TileNumber,TileNumber,32)
Get Image ImageNumber,0,0,32,32
endfunction
`copy a certain number of tiles from one tileset to a new tileset
function CopyTileset(filename$,newfile$,First2Copy,Last2Copy)
if file exist(newfile$)=1 then delete file newfile$
open to read 1,filename$
`read first byte; the tile version
read byte 1,TileVersion
TileVersion=10
`read bytes 2-4
read byte 1,byte2
read byte 1,byte3
read byte 1,byte4
`read fifth byte; tile detail
read byte 1,TileDetail
read byte 1,byte6
close file 1
Size=ReadTileset(filename$,Last2Copy+1)
open to write 1,newfile$
write byte 1,TileVersion
write byte 1,byte2
write byte 1,byte3
write byte 1,byte4
write byte 1,TileDetail
`write byte 1,byte6
for times=0 to Last2Copy-First2Copy
for x=0 to (Size-1)
for y=0 to (Size-1)
`write blue
write byte 1,B(times,x,y)
`write red
write byte 1,R(times,x,y)
`write green
write byte 1,G(times,x,y)
next y
next x
next times
close file 1
endfunction
`more functions to come
I will be adding a GUI later, but at the moment I want to be able to get the tile placement and solidity stuff down pat... maybe even have a layering option... maybe.
Dragael Software
Current Project: Nothing worth mentioning