-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.c
52 lines (44 loc) · 875 Bytes
/
Game.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Game.h"
#include "DeltaTime.h"
#include "DrawableScreen.h"
#include "Input.h"
void InitializeGameState()
{
game_state = malloc(sizeof(GameState));
if(game_state)
{
game_state->isRunning = true;
}
screen_stack = malloc(sizeof(Stack));
}
void SetScreen(const DrawableScreen* _screen)
{
StackPush(screen_stack, _screen);
}
void Update()
{
TickDeltaTime();
PollInput();
UpdateCurrentScreen();
DrawCurrentScreen();
if(window_events.closeButtonClicked)
{
game_state->isRunning = false;
}
}
void DestroyGame()
{
free(game_state);
StackDestroy(screen_stack);
free(screen_stack);
}
void DrawCurrentScreen()
{
const DrawableScreen* screen = StackFront(screen_stack);
screen->draw();
}
void UpdateCurrentScreen()
{
const DrawableScreen* screen = StackFront(screen_stack);
screen->update();
}