#### Archived

This topic is now archived and is closed to further replies.

# 2D Tile based checks

This topic is 5429 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have tilesets, each tile is 32x32, and characters sets, each tile is also 32x32. I want the character to move pixel by pixe, but I can't figure out how to check and see if he is trying to walk on something that he can't (i.e. a wall or tree). With tile-based I would just access my array and with my algorithm, check the tilenumber. But this won't work. I have a theory but it isn't finish:
//In my player class add an index:
int m_iUDMovementIndex; //For up/down
int m_iLRMovementIndex; //For left/right
//And then in my moving function add/subtract 1 for direction
void MoveDown()
{
int UpDown = m_iUDMovementIndex + 1;
if(UpDown <= 0 || UpDown >= 32)
{
m_iRow++;
}
if(g_pMap[(m_iRow * NumberOfColumns) + m_iColumn)] == BLOCKABLE)
{
return;
}
}

Would or wouldn't this work? If anybody knows I would appreciate it. [edited by - Programmer16 on September 22, 2003 10:34:20 PM]

##### Share on other sites
Hi,

Actually, pixel by pixel movement is quite easy. To find the tilenumber all you have to do is to divide your character position in pixels by the tile size.

Thus,

if your character is at position (75, 214)
I assume your map starts at position(0,0)

tilenumberX = 75 / 32 = 2.34.. then round to the lowest integer so it is 2
tilenumberY = 214 / 32 = 6.68.. " " so it is 6

your character is at position (2,6)

hope that helps

[edited by - darkneon on September 22, 2003 10:50:11 PM]

##### Share on other sites
Thanks, I''ll try this.

##### Share on other sites
I tried this, and the only problem is if you are half way onto a tile, this sets it to the the tile you are moving onto. If you stay here you can walk over any tile that is in the column you are moving from. Same thing for the row.

/*
I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/

##### Share on other sites
You''ll need to constrain the character per pixel.

If your character is in a free tile, and the tile to it''s right is blocked, you''ll need to clamp character movement to that tile''s left boundary. Something like the tile width multiplied by the amount of tiles to the left of that tile that are visible in the screen. You then check that against the characters right boundary.

##### Share on other sites
i''ve written a tutorial on tilebased collision detection and response:

http://jnrdev.kbs-design.net/en/jnrdev1

[Edited by - no_skill on February 10, 2005 1:49:23 AM]

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633725
• Total Posts
3013559
×