diff --git a/jailgames.gif b/jailgames.gif index adc09e8..5606819 100644 Binary files a/jailgames.gif and b/jailgames.gif differ diff --git a/source/logo.cpp b/source/logo.cpp new file mode 100644 index 0000000..8ade0f6 --- /dev/null +++ b/source/logo.cpp @@ -0,0 +1,78 @@ +#include "logo.h" + +#include "screen.h" +#include "mouse.h" +#include "surface.h" +#include "s_sprite.h" + +Logo::Logo() +{ + init(); +} + +Logo::~Logo() +{ + close(); +} + +void Logo::init() +{ + Screen::get()->init(); + logo_surface = std::make_shared("jailgames.gif"); + logo_sprite = std::make_unique(logo_surface); + logo_sprite->setPosition( + (options.game.width - logo_sprite->getWidth()) / 2, + (options.game.height- logo_sprite->getHeight()) / 2); + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start"); +} + +void Logo::close() +{ + Screen::get()->destroy(); + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!"); + SDL_Quit(); +} + +void Logo::checkEvents() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_EVENT_QUIT: + running = false; + return; + } + + Mouse::handleEvent(event); + } +} + +void Logo::update() +{ + if (SDL_GetTicks() - ticks > options.game.speed) + { + ticks = SDL_GetTicks(); + } +} + +void Logo::render() +{ + Screen::get()->start(); + logo_sprite->render(); + Screen::get()->render(); +} + +int Logo::run() +{ + while (running) + { + update(); + checkEvents(); + render(); + } + return 0; +} \ No newline at end of file diff --git a/source/logo.h b/source/logo.h new file mode 100644 index 0000000..cb82d09 --- /dev/null +++ b/source/logo.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include "surface.h" +#include "s_sprite.h" + +class Logo +{ + +private: + bool running = true; + Uint64 ticks = 0; + std::shared_ptr logo_surface = nullptr; + std::unique_ptr logo_sprite = nullptr; + + void init(); + void close(); + void checkEvents(); + void update(); + void render(); + +public: + Logo(); + ~Logo(); + int run(); +}; \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 36c33c8..32a1c3d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,75 +1,12 @@ #include #include -#include "screen.h" -#include "mouse.h" -#include "surface.h" -#include "s_sprite.h" - -bool running = true; -Uint64 ticks = 0; -std::shared_ptr logo_surface = nullptr; -std::unique_ptr logo_sprite = nullptr; - -void init() -{ - Screen::get()->init(); - logo_surface = std::make_shared("jailgames.gif"); - logo_sprite = std::make_unique(logo_surface); - - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Logo start"); -} - -void close() -{ - Screen::get()->destroy(); - - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!"); - SDL_Quit(); -} - -void checkEvents() -{ - SDL_Event event; - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_EVENT_QUIT: - running = false; - return; - } - - Mouse::handleEvent(event); - } -} - -void update() -{ - if (SDL_GetTicks() - ticks > options.game.speed) - { - ticks = SDL_GetTicks(); - } -} - -void render() -{ - Screen::get()->start(); - - logo_sprite->render(); - - Screen::get()->render(); -} +#include "logo.h" int main() { - init(); + // Crea el objeto Logo + auto logo = std::make_unique(); - while (running) - { - update(); - checkEvents(); - render(); - } - - close(); + // Bucle principal + return logo->run(); } diff --git a/source/screen.cpp b/source/screen.cpp index cae9e48..9c8f0a7 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -50,6 +50,7 @@ Screen::Screen() std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl; } } + SDL_SetTextureScaleMode(game_texture_, options.video.scale_mode); // Crea la surface donde se dibujan los graficos del juego game_surface_ = std::make_shared(options.game.width, options.game.height); diff --git a/source/surface.cpp b/source/surface.cpp index ce640e1..41cc184 100644 --- a/source/surface.cpp +++ b/source/surface.cpp @@ -494,7 +494,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture) int pitch = 0; // Bloquea la textura para modificar los pĂ­xeles directamente - if (SDL_LockTexture(texture, nullptr, reinterpret_cast(&pixels), &pitch) != 0) + if (!SDL_LockTexture(texture, nullptr, reinterpret_cast(&pixels), &pitch)) { throw std::runtime_error("Failed to lock texture: " + std::string(SDL_GetError())); }