I am making a basic Asteroids game in SFML, and I want the Player ship to always look at the mouse. I have a LookAt(x,y) function which works, but I am not sure how to get the mouse position from the Player's Update() method!
I see several possible solutions to this:
The LookAt(x,y) function is changed to be public, and instead of the Player calling it within its own Update() function, it is called externally (maybe in an Update() function in the GameManager class, which has access to both the Player and the InputManager)
The Player is given a pointer to the mouse position on creation, which is updated every frame in the InputManager on MouseMotion
The Player is given a pointer to the InputManager, which it can then use in the Update() function to access mouse coordinates.
The InputManager class is made 'static', and the Player accesses the mouse position directly via InputManager.GetMousePos()
Ideally I want the Player's behaviour to be contained. I don't feel that it is neat to create new properties, functions or callbacks outside the player class just so that the player has access to two integers. The last solution (making the InputManager static) seems neat to me (especially since it only requires 1 new line of code in the Player class, and doesn't require the Player to hold onto new properties), but I've heard that using singletons is an 'anti-pattern' and should be avoided!