Sunday, 15 May 2011

java - TileMap Collision -



java - TileMap Collision -

how do proper collision tilemap?

this current solution:

int toptilex = ((tilemap.xoffs - x) - 32 - 1) / tile.tile_size; int toptiley = ((tilemap.yoffs - y) - 32 - 1) / tile.tile_size; int bottomtilex = ((tilemap.xoffs - x) - 1) / tile.tile_size; int bottomtiley = ((tilemap.yoffs - y) - 1) / tile.tile_size; int lefttilex = ((tilemap.xoffs - x) - 32-1) / tile.tile_size; int lefttiley = ((tilemap.yoffs - y) - 32-1) / tile.tile_size; int righttilex = ((tilemap.xoffs - x)-1) / tile.tile_size; int righttiley = ((tilemap.yoffs - y)-1) / tile.tile_size; if (keyboard.iskeydown(keyboard.key_w)) { if (!tilemap.getlayer(0)[math.abs(toptiley+1)][math.abs(toptilex)].isblocked()) { tilemap.yoffs++; } } if (keyboard.iskeydown(keyboard.key_s)) { if (!tilemap.getlayer(0)[math.abs(bottomtiley-1)][math.abs(bottomtilex)].isblocked()) { tilemap.yoffs--; } } if (keyboard.iskeydown(keyboard.key_d)) { if (!tilemap.getlayer(0)[math.abs(righttiley)][math.abs(righttilex-1)].isblocked()) { tilemap.xoffs--; } } if (keyboard.iskeydown(keyboard.key_a)) { if (!tilemap.getlayer(0)[math.abs(lefttiley)][math.abs(lefttilex+1)].isblocked()) { tilemap.xoffs++; } }

but player stuck in corners , tiles wouldn't work. tell me proper way check collision , handle collision without playing getting stuck , such.

java opengl 2d lwjgl

No comments:

Post a Comment