Files
punchie-engine/src/Game.c
T

79 lines
1.5 KiB
C

#include "Game.h"
#include "SDL.h"
#include "SDL_events.h"
#include "SDL_pixels.h"
#include "Window.h"
#include "constants.h"
#include "engine_build_config.h"
#include <stdbool.h>
#ifdef DEBUG_ENGINE
#include <stdio.h>
#endif /* DEBUG_ENGINE */
INTERNAL struct game {
bool running;
Window window;
SDL_Event event;
} Game;
bool init_game(const char *game_name, int window_width, int window_height,
bool full_screen) {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
#ifdef DEBUG_ENGINE
printf("Failed to initialise game\n");
#endif /* DEBUG_ENGINE */
return false;
}
if (!init_window(&(Game.window), game_name, window_width, window_height,
full_screen)) {
#ifdef DEBUG_ENGINE
printf("Failed to initialise game\n");
#endif /* DEBUG_ENGINE */
return false;
}
Game.running = true;
#ifdef DEBUG_ENGINE
printf("Game initialised successfully\n");
#endif /* DEBUG_ENGINE */
return true;
}
bool game_running() { return Game.running; }
void handle_events() {
while (SDL_PollEvent(&(Game.event))) {
switch (Game.event.type) {
case SDL_QUIT:
Game.running = false;
break;
}
}
}
void update() {}
void render() {
fill_window_with_color(&(Game.window), (SDL_Color){255, 255, 255, 255});
swap_render_buffers(&(Game.window));
}
void close_game() {
destroy_window(&(Game.window));
Game.running = false;
SDL_Quit();
#ifdef DEBUG_ENGINE
printf("Game closed successfully\n");
#endif /* DEBUG_ENGINE */
}