Search code examples
c++2d-gamesgod-object

2D Game Development "God class"


I am developing a 2D game in C++ using SFML API, but I am having an issue with class design. I think that I am disobeying the SRP (Single Responsibility Principle) because I have one main class called "Game" that should handle the window. It contains a method containing main game loop. Now the problem; it contains object (composition) of more than 5 classes, such as Player, Menu, SplashScreen. Do you think that it is a good idea to create such "God" class? Do you know any open source C++ 2D games from which I could learn? Thank you in advance.


Solution

  • See this thread on the Gamedev site about God classes (yes, they are a bad idea because tight coupling makes code less robust in the face of change).

    Don't know about 2D, but there is a whole GitHub repo with id-Software 3D game engines. Apart from the graphics, this should provide a treasure trove for you. See also the Doom source code review for ideas on good coding style for writing games.