Im currently developing a c++ console game.
The gam consist of a board class with a 2D array of tiles.
I also have game pieces classes for players, arrows, and items.
I need to be able to handle every collision between players/arrows/items, and im wondering between two possible solutions.
1) Hold a list on every tile that holds all the game pieces currently on that tile, and have an enterTile(gamePiece piece) on the tiles and put the logic there.
2) Have an outer “CollisionDetector” class that will scan all tiles/pieces for collision and handle them there.
What do you think?
I would create a function which would look like that:
This function will handle the collisions.
In order to find the collisions, whenever an object enters a tile (enterTile), you can search that tile for the objects contained in it, and call their OnCollision functions.
That would of course mean keeping the items on the board as some list in their respective tile.
So I basically suggest your first solution.
Also notice, if your board is too big it might take more time to go through all of it. So in case it is rather large, consider the second solution you came up with.