TGC Codebase Backup



Tileset Reading Functions by Code Ninja

6th Jan 2005 13:36
Summary

Reads and draws tiles from the RPGToolkit's tileset file format.



Description

SizeofTile=ReadTileset(filename$,#ofTiles2Read)
-reads tiles 0 to #ofTiles2Read from the specified tileset.
-returns the tile size (generally 32)

DrawTiles(xpos,ypos,First2Draw,Last2Draw,SizeofTile)
-draws tiles First2Draw to Last2Draw to the screen at xpos,ypos

GetTile(Tile#,Image#)
-captures tile Tile# to image Image#



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Tileset Function 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)
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

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

function GetTile(TileNumber,ImageNumber)
 DrawTiles(0,0,TileNumber,TileNumber,32)
 Get Image ImageNumber,0,0,32,32
endfunction