Jump to content
  • Advertisement

Archived

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

Programmer16

2D Tile based checks

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!