I'm actually developing a very simple 3D game, Arkanoid/Breakout style, with very simple mechanics, and it's progressing while I learn the game dev domain own concepts and techniques (My background is C/C++ middleware/low-level systems programmer).
I've advanced to a functional game loop, input, movement, collision checks, all it's working, but I reached to a day where the code was a mess, e.g: my Level class was doing too much. So I partitioned, OOP style, the code in several classes.
My intention is to get ideas from more experienced programmers regarding how Game state and substates relate with entities. My general picture is:
- A game object which contains the main loop
- A level object which contains a World instance with a list of all entities.
- A renderer class which does Direct2D and Direct3D rendering.
Prior to the major refactoring, I was doing something like
Level::Update(float clockMs) {
switch (m_state)
case (LevelState::Preloading) { ... }
case (LevelState::Load) { ...}
case (LevelState::Playing) {
UpdateBallPosition ( ... )
CheckCollisions( ...)
}
}
Level contained references to ball, game bricks, etc. Now I create the entities in the Level startup and add them to the World instance. (World is a member of Level).
Now I want to move all state-related code to the entities themselves. Suppose "Ball", it shouldn't do anything until Level is in LevelState::Playing. Where do you store typically state for the current Level (suppose a closed-level game)? It's correct to store entities with a pointer to the World and the World to mantain a pointer to the Level containing it? It's a tightly coupled architecture but I want to discuss how to relate world/level states with entities, and how the entities acknowledge in which higher-level states they are.
Keep in mind that I accept good procedural or data-driven approaches. I'm not an OOP fanatic, I think good designs can be built upon several paradigms. Thanks.