Jump to content
  • Advertisement
Sign in to follow this  
BytePtr

Tile Maps and Snapping player coordinates

This topic is 2606 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

Hi.

For example i create simple tile map and add player to it.
When i press left, right, up or down key i will increase or decrease X and Y pos, like this for example (C++):

xpos += 1;
ypos += 1;

Map is define by simple numbers 0 and 1 etc.
0 is grass
1 is rock etc...

Depending on number i draw specific tile. Now let's say my tiles are all 64x64 pixels.
I would like to get "full" coordinates of player.
I mean, let's say map width is 256 and height also 256.
So if player is at X: 2 Y: 2 (at which the map tile ID is 1 for ex) then i must get his coordinates also like they are: X 2 and Y 2.
If he moves away from tile ID 1 then coordinate must also increase by one. Not by 1.42343 or something...

I don't know how to explain it better. It just must increase coordinate value only if he moves away from one tile to another.
If player is in one tile and moving within that tile, then coordinate values should stay same.

But i don't know the math behind it. Should i use % operator to do what i need or something else?


Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!