1

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.

  1. key for a direction is pressed
  2. check the next pixel ahead and check the tile at this postion
  3. 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 :)

Dawesign
  • 643
  • 1
  • 7
  • 25
  • Pixell, hopefully some of these can help you out: http://stackoverflow.com/questions/16020578/slick2d-entity-collision-detection and https://www.youtube.com/watch?v=V5n3duxD--s and http://www.gamedev.net/topic/608825-preferred-slick2d-collision-detection/ http://stackoverflow.com/questions/24755050/slick2d-rectangle-collision-detection – Devarsh Desai Oct 22 '14 at 17:37
  • Okey, so drawing a shape as a hitbox would be a good idea! And if I draw it around the feet of the player I automatically solve this "logical collision" problem. :) But since the fridge is not an object but a tile on the map I can't use methods like "intersects". – Dawesign Oct 22 '14 at 17:49
  • hey Pixell, I'm happy you figured it out! to be honest, I've NEVER done anything in slick 2d or isometric games before; I just tried to find some links that might help you out! haha; I hope everything works out with your game and best of luck!! :) – Devarsh Desai Oct 22 '14 at 17:52
  • Thanks for kind words and help! I actually saw some of these links before but didn't really had the idea to make a hitbox :D But there are still problems... I will try to figure it all out. When I have a solution I will definitely post it here! – Dawesign Oct 22 '14 at 17:58

0 Answers0