Valid Move

Started by
1 comment, last by delbogun 22 years, 5 months ago
I have problem to check if a move is valid for the player. If each tile is 32x32 and the player stands on (x,y) where x and y is the exact pixel positions on the screen. How do I check the properties (example: tile.movable == true) the tile next to the player have?
Advertisement
From the screen coordinates, you can get the coordinates of the tile into the tile map. If your screen is also scrolled by ScrollX and ScrollY pixels from the top-left of the tilemap, then you can get the tile coordinates like this:

  TileX = (ScreenX + ScrollX) / 32;TileY = (ScreenY + ScrollY) / 32;  

That will tell you the tile that the pixel at (ScreenX, ScreenY) is in. From there, you can simply add/subtract 1 to TileX or TileY to get a neighbouring tile.
Kippesoep
yeah, thats how I do it, but the problem is that this works if he walks 32 pixels each time, but I want him to walk 4 pixels, and then it doesn''t seems work...

This topic is closed to new replies.

Advertisement