Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2014-07-26 04:30:32

Raildex
New member
Registered: 2014-06-07
Posts: 3

Tile Collision

Hey there!
I'm currently working on an idea for a sidescroller and I'm stuck at the Collision for Tiles.
Many suggest to make a Collision-Map for every map but I think this is too time consuming.

I had the following Idea:
I create the Tileset using Gameboy Tile Designer. This Tileset is saved in a declaration in Tileset.c
in Tileset.c, there is also a "Collision Table" like this:

Code:

typedef struct tileColl
{
    UBYTE tileID;
    UBYTE collisionType;
}TileCollision;

TileCollision collisionTable;

and a method like this

Code:

UBYTE getCollision(UBYTE tile)
{
    for(UWORD i = 0;i < sizeof(collisionTable)/sizeof(TileCollision);i++)
    {
        if(tile == tileID)
        {
            return collisionTable.collisionType;
        }
    }
}

But since A tileset is stored as an array of unsigned bytes, I have no idea how to get a "whole tile" out of it.
Here's an example of how these tiles are saved:

Code:

const unsigned char MainTiles[] =
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0xFF,0xFF,0xC0,0x80,0xBF,0x80,0xBF,0x80,
  0xBF,0x80,0xBF,0x80,0xA0,0xDF,0xFF,0xFF,
  0xFF,0xFF,0xF1,0x03,0x0D,0x01,0xFD,0x01,
  0xF5,0x09,0xFD,0x01,0x8D,0x73,0xFF,0xFF,
[...]

Do you have an idea how to get a single tile (16x16/8x8) out of this array?

Offline

 

#2 2014-07-30 05:51:11

LuckyLights
Member
Registered: 2014-07-06
Posts: 20

Re: Tile Collision

Hi Raildex,

I have not worked with Gameboy Tile Designer so I'm going to make some assumptions.
Your MainTiles[] contains your tile image data as 16 bytes, where each 2 bytes represent a line per tile. Aka one row or MainTiles[i*8] == your tile at (i).

I suggests comparing on you map data instead of your tile data. Senes your map data will only be one byte per pixel and aligned with your map layout, grabbing one of them is just a mater of MapData[w*y + x] where w = MapData width.

And if you want 16x16 you pick the 3 surrounding tiles x+1, y+1 and x+1 y+1.

Offline

 

#3 2014-09-23 10:56:38

Crona
Member
From: Wisconsin
Registered: 2014-09-23
Posts: 58
Website

Re: Tile Collision

I just started learning about gbdk this week so my methods are a little limited, but here is what I use for collision detection:

if(xpos - 4 < obstaclex){   /* if your tiles are 16x16 change the 4s to 8s */
    if(xpos > obstaclex - 4){
        if(ypos - 4 < obstacley){
            if(ypos > obstacley - 4){
                /* replace this comment with whatever you want to happen when the tiles are overlapping */
            }
        }
    }
}


Havent tested this one yet, but if your trying to make something that you cant walk past it would be something like this:

if(xpos == obstaclex - 5) {
cantgoright = 1;
}
else{
cantgoright = 0;
}
if(xpos == obstaclex + 5) {
cantgoleft = 1;
}
else{
cantgoleft = 0;
}
if(ypos == obstacley + 5) {
cantgoup = 1;
}
else{
cantgoup = 0;
}
if(ypos == obstacley - 5) {
cantgodown = 1;
}
else{
cantgodown = 0;
}

again I've only been learning for like a week, and these are probably crazy inefficient but it will give you an idea.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson