Engine Framework - the bloddy basics
All code below is in C# for reference. Should be no problem to port this to another language.
The code is not ment to be a complete engine but rather the import excerpts.
Main class - engine.cs
Here we've got our main game loop. What it basicaly does is to tell the ScreenManager to render the current game screen, the AI-Subsystem to update NPC movements (and what else is going on) and the InputManager to reread attached devices (gamepad, keyboard, etc).
This is done in a loop as long as the game is running.
Code: Alles auswählen
while(!isShutingDown)
{
ScreenManager.Render();
AI.Update();
Input.Update();
}
This subsystem is responsible for rendering the screen to... urmmm... the screen.
A screen is what we actualy see on the screen. Could be also named 'a scene'. Typical examples are MainMenu, OptionsMenu, WorldView, CityView, Inventory, etc...
The ScreenManager has a stack of screens.
So if we're in the city and looking at our character (CityView) we push the CityView on top of the stack. If the player then opens the options menu or the inventory we push another screen on the stack (InventoryView).
Normaly only the top most screen of the stack is rendered by the ScreenManager. In this case we would only see the inventory, not the CityView underneath it. But we can set a screen as popup or inactive.
So when we push the inventory on the stack, we mark it as popup. This tells the ScreenManager to also render the previous screen (CityView) from the stack. And it marks the CityView as inactive thus not receiving any inputs from the InputManager.
Once the player closes the inventory, we pop the InventoryView from the stack, which sets the CityView back to active.
The Render() method which is called by the game loop just calls the Render() method from the topmost screen (maybe the previous screen if marked as popup). The screen's Render() method then does the actual rendering (placing sprites and stuff on the screen)
Code: Alles auswählen
void PushStack(GameScreen screen);
void PopStack();
void Render();