Files
logo_01/source/logo.cpp
Sergio Valor a40c9a899b ja pinta el logo en tamany 1:1
moguda la logica del main a la classe Logo
2025-04-07 11:55:09 +02:00

78 lines
1.1 KiB
C++

#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<Surface>("jailgames.gif");
logo_sprite = std::make_unique<SSprite>(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;
}