PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Tiles collison detection

jeemigdepeemig · 25 Oct 2005, 13:09 UTC
Hey all,

I’m new in game design so i want to start with a simple turn based rpg-like game. The grid itself is 2d, the graphics will make it have a isometric effect.

Now i must choose a tile format. Originally i was thinking of a simple square grid: |_|, but for the 3d feel diamand shape tiles look better: \/. The problem with that is that way i cant use the rect function for collision detection. If the stylus touches a specific tile f.e.

What’s the best method to do collision detection on the tiles when they are not sqaure?

I use now:

Code:

void HekkusSample::DrawTile(Surface *image, int x, int y)
{
int h = x*80;
int v = y*80;
Display* display = GetDisplay();
display->Blit( h, v, image);
m_position[x][y].Set(h,v,h+80,v+80);
}



Where m_position is the rectangle that i use for collision detection.

Gr,
jeemig
What you probably want to do is to map the screen back onto your game tile coordinates when you click. There's probably several ways to do it, and it really depends on your tiles. Whatever you do to calculate where to put a tile, you 'undo' it to go from screen coordinates into tile coordinates.

Just keep in mind that even though the game is drawn at an angle, the movement/collision is still a straight 2d matrix.


BTW, your pocketfrog code should not call GetDisplay more than once per frame. The correct way would be to pass the pointer to the display to the DrawTile function. The same goes for the display->Update()... there should only be 1 call to that per frame as well.