82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
/*
|
|
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
|
|
|
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 <SDL3/SDL_init.h>
|
|
#include <SDL3/SDL_rect.h>
|
|
#include <SDL3/SDL_render.h>
|
|
#include <string>
|
|
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_main.h>
|
|
|
|
#include <memory>
|
|
|
|
#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<PlayerGraphics>(),
|
|
std::make_unique<PlayerInput>()
|
|
);
|
|
|
|
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<state*>(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)
|
|
{
|
|
}
|
|
|