Tiles and collision

Blitz3D Forums/Blitz3D Beginners Area/Tiles and collision

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

There are many ways to achieve what you want.

As mentioned you could use arrays to store extra information about each tile.

You could also use Types or Arrays of Types to store extra information.

Or you could simply use some kind of simple coding scheme in your Data statements. Say for example that all of your tiles are enumerated from 0-37. You know that you will never use more than 64 tiles, so you can set flags for certain tiles by adding the number 64 to any tile (ex. A number 5 tile would equal 69). You can check if the tile is collidable by doing either
If tile > 63
  col_tile = True ;tile is collidable, so note that
  tile = tile - 64
  ;now tile equals what it really is
EndIf
or
col_tile = (tile AND $40) Shr 6
;col_tile now equals a 0 or 1
tile = tile - 64
If you need to add more bits of information to your tiles, you can use other 'multiples of 2' numbers like 128, 256, 512, etc. and compare those with $80, $100, and $200 respectively.
energy_tile = (tile AND $200) Shr 9
;energy_tile now equals a 0 or 1
tile = tile - 512


Alternatively, you could leave tile to equal what it is (don't subtract the 64 or 512 part) and just do a compare like the following when you want to check what type of tile it is. This will only return the value below 64.
tiletype = (tile AND $3F)