For about a year I was working on a game, on a learning by doing basis. This worked well for me, and the result, so far, isn't that bad. I shelved that project for now though, and I started working on a new one, with a somewhat smaller scale.
A question that has been bothering me for a very long time, is surfacing again. Let me explain...
When I make a game, I make several "Screen" classes, that each contain a screen, like the menu screen or the playscreen, etc. When the game is playing the playscreen is of course shown. The playscreen then has an instance of a level class, that contains the level array, lists with mobs and items, and the starting location for the player. Each type of mob has it's own class, that derives from a base class (to make it possible to keep them all in the same list). Now this is all well and good, but my problem arises, when I start doing the movement logic for either the player or the mobs. Since each mob has its own movement logic, it will need to check its surroundings for obstacles and such.
And here is the problem - What would be the best way to do this, while maintaining a solid code structure?
In my first project, each mob that was created received a reference to the world array, which fixed the problem. This time I was thinking about making the level array static, and then use a public static property to access it from wherever I would need it, but both of those solutions seems.. wrong somehow to me? I mean making my mobs dependent on a static variable in another class, doesn't that somehow break the whole idea of object oriented programming?
Passing down a reference somehow seems more preferable, but again, it seems wrong. I would then make the mobs dependent on the level class to be initialized, before it would even be possible to initialize it properly...
Am I seeing ghosts here? Or did I miss a much smoother option?
Thanks for reading.