I am building the engine for a terraria-like 2D sandbox game using SDL2. Currently, I am working on a scene management system. I was wondering if just having a single local variable in main called scene_num
and some if statements in main to control the scene the player is currently on would suffice, especially as the game gets more complex?
This is what I meant in terms of basic structure:
int scene_num = 0;
// scene_num guide:
// 0 = title screen
// 1 = actual game
// 2 = inventory screen
// 3 = pause screen
// game loop
bool running = true;
while (running == true) {
while (SDL_PollEvent(&ev)) {
// handle user inputs here (ie: keyboard, mouse, etc.)
}
// handle game updates here
if (scene_num == 0) {
// handle title screen here
} else if (scene_num == 1) {
// handle gameplay updates here
} else if (scene_num == 2) {
// handle inventory screen here
} else {
// hanlde pause screen here
}
// handle rendering here
if (scene_num == 0) {
// handle title screen rendering here
} else if (scene_num == 1) {
// handle gameplay rendering here
} else if (scene_num == 2) {
// handle inventory screen rendering here
} else {
// handle pause screen rendering here
}
}