esqueleto nivel 1
This commit is contained in:
100
source/main.cpp
Normal file
100
source/main.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#define SDL_MAIN_USE_CALLBACKS
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/options.hpp"
|
||||
#include "core/rendering/screen.hpp"
|
||||
#include "utils/delta_timer.hpp"
|
||||
|
||||
class App {
|
||||
public:
|
||||
App() = default;
|
||||
~App() { cleanup(); }
|
||||
|
||||
SDL_AppResult init(int /*argc*/, char* /*argv*/[]) {
|
||||
// --- Configuración ---
|
||||
Options::game.width = 320.0F;
|
||||
Options::game.height = 180.0F;
|
||||
Options::window.caption = "Esqueleto";
|
||||
Options::window.zoom = 3;
|
||||
Options::window.max_zoom = 4;
|
||||
Options::video.palettes_path = "data/palettes";
|
||||
Options::text_config.surface_path = ""; // Ruta al .gif de la fuente
|
||||
Options::text_config.fnt_path = ""; // Ruta al .fnt
|
||||
|
||||
// --- Inicialización de sistemas ---
|
||||
Screen::init();
|
||||
Audio::init();
|
||||
Input::init("data/gamecontrollerdb.txt");
|
||||
|
||||
// Vincular teclas del juego (añadir acciones específicas aquí):
|
||||
// Input::get()->bindKey(InputAction::LEFT, SDL_SCANCODE_LEFT);
|
||||
// Input::get()->bindKey(InputAction::RIGHT, SDL_SCANCODE_RIGHT);
|
||||
|
||||
initialized_ = true;
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
SDL_AppResult handleEvent(const SDL_Event& event) {
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
return SDL_APP_SUCCESS;
|
||||
}
|
||||
Input::get()->handleEvent(event);
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
SDL_AppResult iterate() {
|
||||
float delta_time = delta_timer_.tick();
|
||||
|
||||
Input::get()->update();
|
||||
Audio::update();
|
||||
Screen::get()->update(delta_time);
|
||||
|
||||
// --- Lógica del juego ---
|
||||
// ...
|
||||
|
||||
// --- Renderizado ---
|
||||
Screen::get()->start();
|
||||
Screen::get()->clearSurface(0);
|
||||
|
||||
// Dibuja aquí...
|
||||
|
||||
Screen::get()->render();
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
private:
|
||||
void cleanup() {
|
||||
if (!initialized_) return;
|
||||
Input::destroy();
|
||||
Audio::destroy();
|
||||
Screen::destroy();
|
||||
SDL_Quit();
|
||||
initialized_ = false;
|
||||
}
|
||||
|
||||
DeltaTimer delta_timer_;
|
||||
bool initialized_{false};
|
||||
};
|
||||
|
||||
static App app;
|
||||
|
||||
SDL_AppResult SDL_AppInit(void** /*appstate*/, int argc, char* argv[]) {
|
||||
return app.init(argc, argv);
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppEvent(void* /*appstate*/, SDL_Event* event) {
|
||||
return app.handleEvent(*event);
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppIterate(void* /*appstate*/) {
|
||||
return app.iterate();
|
||||
}
|
||||
|
||||
void SDL_AppQuit(void* /*appstate*/, SDL_AppResult /*result*/) {
|
||||
// ~App() se encarga de la limpieza
|
||||
}
|
||||
Reference in New Issue
Block a user