What datastructure would you use for a collision-detection in a tilemap?

Posted by Solom on Game Development See other posts from Game Development or by Solom
Published on 2014-08-18T12:23:41Z Indexed on 2014/08/18 16:47 UTC
Read the original article Hit count: 334

Currently I save those blocks in my map that could be colliding with the player in a HashMap (Vector2, Block). So the Vector2 represents the coordinates of the blog.

Whenever the player moves I then iterate over all these Blocks (that are in a specific range around the player) and check if a collision happened.

This was my first rough idea on how to implement the collision-detection. Currently if the player moves I put more and more blocks in the HashMap until a specific "upper bound", then I clear it and start over.

I was fully aware that it was not the brightest solution for the problem, but as said, it was a rough first implementation (I'm still learning a lot about game-design and the data-structure).

What data-structure would you use to save the Blocks? I thought about a Queue or even a Stack, but I'm not sure, hence I ask.

© Game Development or respective owner

Related posts about java

Related posts about collision-detection