I'm working on a 2D game where you can move up, down, left and right. I have essentially two game logic objects:
- Player: Has a position relative to the world
- World: Draws the map and the player
So far, World depends on Player (i.e. has a reference to it), needing its position to figure out where to draw the player character, and which portion of the map to draw.
Now I want to add collision detection to make it impossible for the player to move through walls.
The simplest way I can think of is to have the Player ask the World if the intended movement is possible. But that would introduce a circular dependency between Player and World (i.e. each holds a reference to the other), which seems worth avoiding. The only way I came up with is to have the World move the Player, but I find that somewhat unintuitive.
What is my best option? Or is avoiding a circular dependency not worth it?