Hello all!
I've been learning C++ for the past few months and lately I started messing around with SFML. I tried making some simple games but I always get to a point where I have 3 or 4 classes which always end up being a mess, and also I get header files compilation errors.
Question # 1 is, when dealing with OOP game programming, is there a general structure I should be aiming at? What I do is make a "game" class which creates and initializes the window, and it has a method with the game loop in it. in that method I create all instances of other classes, such as "eventHandler Event", and I pass a reference of the Window to a method in Event.. Same thing when rendering, I have a Graphics class which receives a reference of the Window(created in Game) and renders from there. Am I doing this right? I mean, it feels "right" to do but it gets messy very fast to the point that I'm struggling to understand my own code. Are there any recommended general guidelines for this?
Question # 2 - I seem to get header files errors quite a lot.. Say I have:
-Game class
-Graphics class
-Event handling class
-Sprite class
-Player class(inherited from sprite)
What I do is include all headers in Game.h, and include Game.h in all headers - does this means that if Graphics class needs to use something from Sprite class, Sprite.h won't be seen by Graphics.h? I get a lot of errors with this. I once was able to solve it with a forward declaration, "Class Sprite;" in Graphics.h but then other times this doesn't work. How do I avoid such errors?
Thanks so much!