#include "engine.h" #include // for SDL_GetError #include // for SDL_Event, SDL_PollEvent #include // for SDL_Init, SDL_Quit, SDL_INIT_VIDEO #include // for SDL_Keycode #include // for SDL_SetRenderDrawColor, SDL_RenderPresent #include // for SDL_GetTicks #include // for SDL_CreateWindow, SDL_DestroyWindow #include // for rand, srand #include // for time #include // for cout #include // for string #include "ball.h" // for Ball #include "external/dbgtxt.h" // for dbg_init, dbg_print #include "external/texture.h" // for Texture // Implementación de métodos públicos bool Engine::initialize() { bool success = true; if (!SDL_Init(SDL_INIT_VIDEO)) { std::cout << "¡SDL no se pudo inicializar! Error de SDL: " << SDL_GetError() << std::endl; success = false; } else { // Crear ventana principal window_ = SDL_CreateWindow(WINDOW_CAPTION, SCREEN_WIDTH * WINDOW_SIZE, SCREEN_HEIGHT * WINDOW_SIZE, SDL_WINDOW_OPENGL); if (window_ == nullptr) { std::cout << "¡No se pudo crear la ventana! Error de SDL: " << SDL_GetError() << std::endl; success = false; } else { // Crear renderizador renderer_ = SDL_CreateRenderer(window_, nullptr); if (renderer_ == nullptr) { std::cout << "¡No se pudo crear el renderizador! Error de SDL: " << SDL_GetError() << std::endl; success = false; } else { // Establecer color inicial del renderizador SDL_SetRenderDrawColor(renderer_, 0xFF, 0xFF, 0xFF, 0xFF); // Establecer tamaño lógico para el renderizado SDL_SetRenderLogicalPresentation(renderer_, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE); // Configurar V-Sync inicial SDL_SetRenderVSync(renderer_, vsync_enabled_ ? 1 : 0); } } } // Inicializar otros componentes si SDL se inicializó correctamente if (success) { texture_ = std::make_shared(renderer_, "data/ball.png"); srand(static_cast(time(nullptr))); dbg_init(renderer_); initBalls(scenario_); } return success; } void Engine::run() { while (!should_exit_) { calculateDeltaTime(); update(); handleEvents(); render(); } } void Engine::shutdown() { // Limpiar recursos SDL if (renderer_) { SDL_DestroyRenderer(renderer_); renderer_ = nullptr; } if (window_) { SDL_DestroyWindow(window_); window_ = nullptr; } SDL_Quit(); } // Métodos privados - esqueleto básico por ahora void Engine::calculateDeltaTime() { // TODO: Implementar cálculo de delta time } void Engine::update() { // TODO: Implementar lógica de actualización } void Engine::handleEvents() { // TODO: Implementar manejo de eventos } void Engine::render() { // TODO: Implementar renderizado } void Engine::initBalls(int value) { // TODO: Implementar inicialización de pelotas } void Engine::setText() { // TODO: Implementar texto } void Engine::pushUpBalls() { // TODO: Implementar impulso de pelotas } void Engine::switchBallsGravity() { // TODO: Implementar cambio de gravedad } void Engine::changeGravityDirection(GravityDirection direction) { // TODO: Implementar cambio de dirección } void Engine::toggleVSync() { // TODO: Implementar toggle V-Sync } std::string Engine::gravityDirectionToString(GravityDirection direction) const { // TODO: Implementar conversión a string return "DOWN"; } void Engine::renderGradientBackground() { // TODO: Implementar fondo degradado } void Engine::addSpriteToBatch(float x, float y, float w, float h, int r, int g, int b) { // TODO: Implementar batch rendering }