Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D Tile based checks

Started by Programmer16 Sep 22, 2003 at 9:29 PM 4 replies 750+ views
Original Post
Programmer16
Programmer16
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]
Darkneon
Darkneon
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]
Programmer16
Programmer16
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)
*/
M3d10n
M3d10n
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.