I can't figure out how I can implement my collision detection with the provided methods from Slick 2D. I created a map with the program "Tiled" because Slick 2D supports the files you get from there. So this is how my game looks right now:
It pretty much consists of the basic (isometric) background, the functional player and a fridge somewhere on the map (The object to collide with). In Tiled you can create several layers for the objects you place. The Grass is on layer 0 and the fridge on layer 1 etc.
So here comes the well known basic collision detection.
- key for a direction is pressed
- check the next pixel ahead and check the tile at this postion
- If this tile at this postion has the layer ID 1 (wich is the layer for all solid objects), don't move
Slick 2D provides the method getTileID(xPos, yPos, layerIndex) wich returns the int of the layer of this tile. So 1 in this case.
But there is my problem: I can't just use the x and y coordinates of my player for getTileID(...) because this methods expects x and y to be coordinates in this map pattern.
https://i.stack.imgur.com/X2Fvb.png
But the x and y coordinates of the player are in pixels. So checking getTileID(...) with the x and y of the player would cause and outOfBoundsException because the map is only 20 by 20 tiles. But the player is at position 200, 200 for example.
So I have to somehow combine the coordinates of the player with the ones of the map. And I have now Idea how to that. Also the player should collide logical with the tile. Like this:
https://i.stack.imgur.com/AKpGD.png
The best result I could get was, that I said x is x/32 and y is y/64 (because the tiles are 32 px in height and 64 in width). So the palyer actually somehow collided but just somewhere else on the map. And the shape he collided with was more like a reactangle and not an isometric thing :/
Where do I start? Any sources for help? I don't know how to make this happen. Thanks for reading and any help :)