I just want to know if there is a way in java to detect when the character is on an item on the floor without without verifying if every items on the map contains the character or vice versa in every iteration.
Tell me more
×
Game Development Stack Exchange is a question and answer site for
professional and independent game developers. It's 100% free, no registration required.
A common way to do this is to divide the game world into tiles (which is something you may want to do for other reasons too) and have each tile store a list of the items in it. That way, you only have to check the items that are in the same tile as the character (or possibly in an adjacent tile, if the items and/or the character can overlap several tiles). If you have a large world with items scattered sparsely in it, you may also try fancier spatial subdivision techniques like quadtrees. In any case, the principle is the same: divide the world into chunks, assign each item or character into a chunk based on their location, and only check for collisions between things in the same or in adjacent chunks. |
|||
|