Reading Tile Map Layers Directly

Started by kevin, June 10, 2003, 12:27:40 PM

Previous topic - Next topic

kevin

This code will let you read a loaded tile mpa layer.  It returns the BLock structure index pointer.




` *=---------------------------------------------------------------------=*
`                        >> Mappy Read Tile Layer <<
` *=---------------------------------------------------------------------=*
`
`    This simple function lets you read a Tile from any layer your wish.
`
`  Inputs:
`
`       LAYER = The Map Layer you wish to access
`    TileMapX =  The X coord of the tile
`    TileMapY = The Y coord of the tile
`
`  returns
`
`        Tile = returns the tile structure index number.
`
` *=---------------------------------------------------------------------=*



Function Mappy_Read_Tile_Layer(Layer,TileMapx,TileMapy)
 Tile=-1
     TileMapBank=Mappy_TileMapLayers_BankNumb(Layer)
     ` Check to see if this layer exists
     If TileMapBank>-1
      MapWidth=Mappy_MapWidth(1)
  if TileMapX>-1 and TileMapX<MapWidth
       MapHeight=Mappy_MapHeight(1)
   if TileMapY>-1 and TileMapY<MapHeight

        TileAddress=(TileMapY*MapWidth)+TileMapX+VB_Get_Bank_BaseAddress(TileMapBank)
              Tile=VB_DataCache(TileAddress)

   endif
  endif
 endif
EndFunction Tile



3ddd

I have a few questions about this:

Could you please give an example of how this new function can be used?

Should this function be cut and pasted right into VirtualBanksLibrary_FULL_DBpro_V010a.dba?

What does the Block structure look like? I cannot find its typedef anywhere in the code!

How would I use this function to, for example, check the values of tl, tr, bl, br, and user1 of tile 10, 10, layer? I would really appreciate a code snippet on this.

Thank you very much,
Derek

kevin

#2
QuoteCould you please give an example of how this new function can be used?

That's going to be hard as I don't have Dark BASIC installed anymore, but this is about all you need to pull the tile structure index.  

Tile= Mappy_Read_Tile_Layer(Layer,PLayerX/TileWidth,PLayerY/TileHeight)





QuoteShould this function be cut and pasted right into VirtualBanksLibrary_FULL_DBpro_V010a.dba?

It's meant to be part of the mappy function set of no, Vbanks is just way get around Dark BASIC classic missing memory management commands.


QuoteWhat does the Block structure look like? I cannot find its typedef anywhere in the code!

Of course you won't, DB classic (for which the code was written for) doesn't have Types.  So the structures are peeked/poke through the Vbanks layer.  Which is what makes it a big mess basically ..


QuoteHow would I use this function to, for example, check the values of tl, tr, bl, br, and user1 of tile 10, 10, layer? I would really appreciate a code snippet on this.


Well, you can't..  The first function returns the Tile from a layer. So using this tile you'd peek the structure with something like these.   (completely un tested)


Function Mappy_PeekDataBlock_Byte(ThisTile,Offset)
Bank= Mappy_BlockStructuresBankNumb(1)
Address=(ThisTIle*32)+Offset
result=VB_Byte(Bank,Address)
EndFunction result

Function Mappy_PeekDataBlock_Word(ThisTile,Offset)
Bank= Mappy_BlockStructuresBankNumb(1)
Address=(ThisTIle*32)+Offset
result=VB_Word(Bank,Address)
EndFunction result


Function Mappy_PeekDataBlock_INT(ThisTile,Offset)
Bank= Mappy_BlockStructuresBankNumb(1)
Address=(ThisTIle*32)+Offset
result=VB_Leek(Bank,Address)
EndFunction result


From the quick look i had at this before, the tiles appear to be are stored in offsets 0,4,8,12  

MyTileStructure= Mappy_Read_Tile_Layer(Layer,PLayerX/TileWidth,PLayerY/TileHeight)

; read the tiles
TileA=Mappy_PeekDataBlock_INT(MyTileStructure,0)
TileB=Mappy_PeekDataBlock_INT(MyTileStructure,4)
TileC=Mappy_PeekDataBlock_INT(MyTileStructure,8)
TileD=Mappy_PeekDataBlock_INT(MyTileStructure,12)


If you look in the source i've pre-calced the Structures indexes already.. in this bit



0 long int bgoff, fgoff;   /* offsets from start of graphic blocks */
8 long int fgoff2, fgoff3; /* more overlay blocks */
16 unsigned long int user1, user2;   /* user long data */
20 unsigned short int user3, user4;   /* user short data */
23 unsigned char user5, user6, user7;   /* user byte data */
24 unsigned char tl : 1;   /* bits for collision detection */
25 unsigned char tr : 1;
26 unsigned char bl : 1;
27 unsigned char br : 1;
28 unsigned char trigger : 1;   /* bit to trigger an event */
29 unsigned char unused1 : 1;
30 unsigned char unused2 : 1;
31 unsigned char unused3 : 1;




So to the read the collision bits.

; tl
TL=Mappy_PeekDataBlock_BYTE(MyTileStructure,25)
TR=Mappy_PeekDataBlock_BYTE(MyTileStructure,26)
BL=Mappy_PeekDataBlock_BYTE(MyTileStructure,27)
BR=Mappy_PeekDataBlock_BYTE(MyTileStructure,28)

Your on your own from here ..

3ddd

Thanks for the explaination! I had no idea it would be so complicated using Dark Basic! The Mappy-based source codes that I looked at for other languages (Blitz Basic, Delphi, etc) all seem so straight forward when it comes to getting the block structure information.

I'll try to get something working tonight. Also, I'll be sure to post my results if I have any success.

Thanks again!
Derek