/* Copyright (C) 1997-2025 Sam Lantinga This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely. */ #include "GameState.h" #include #include #include #include #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ #include #include #include #include "components/PlayerGraphics.h" #include "components/PlayerInput.h" #include "Graphics.h" #include "GameObject.h" static SDL_Window *window = nullptr; static SDL_Renderer *renderer = nullptr; GameObject player( std::make_unique(), std::make_unique() ); struct state { Graphics graphics; /* Physics physics */ }; /* This function runs once at startup. */ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { static struct state state { Graphics("My Game") }; *appstate = &state; /* Create the window */ return SDL_APP_CONTINUE; } /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { auto state = player.processInput(event); if (GameState::STOPPING == state) { return SDL_APP_SUCCESS; } return SDL_APP_CONTINUE; } /* This function runs once per frame, and is the heart of the program. */ SDL_AppResult SDL_AppIterate(void *appstate) { auto game = static_cast(appstate); player.update(game->graphics); game->graphics.show(); return SDL_APP_CONTINUE; } /* This function runs once at shutdown. */ void SDL_AppQuit(void *appstate, SDL_AppResult result) { }