Acabat de renamar, encara que he descobert cosetes i tindré que fer altra pasaeta
Actualitzat stb_image.h a la última versió
This commit is contained in:
104
source/logo.cpp
104
source/logo.cpp
@@ -20,54 +20,48 @@ Logo::Logo()
|
||||
SDL_Renderer *renderer = Screen::get()->getRenderer();
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
jailTexture = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
|
||||
sinceTexture = std::make_shared<Texture>(renderer, Asset::get()->get("logo_since_1998.png"));
|
||||
sinceSprite = std::make_unique<Sprite>((param.game.width - sinceTexture->getWidth()) / 2, 83 + jailTexture->getHeight() + 5, sinceTexture->getWidth(), sinceTexture->getHeight(), sinceTexture);
|
||||
jail_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames.png"));
|
||||
since_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_since_1998.png"));
|
||||
since_sprite_ = std::make_unique<Sprite>((param.game.width - since_texture_->getWidth()) / 2, 83 + jail_texture_->getHeight() + 5, since_texture_->getWidth(), since_texture_->getHeight(), since_texture_);
|
||||
|
||||
// Inicializa variables
|
||||
counter = 0;
|
||||
counter_ = 0;
|
||||
section::name = section::Name::LOGO;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
showSinceSprite_cm = 70;
|
||||
initFade_cm = 300;
|
||||
endLogo_cm = 400;
|
||||
postLogoDuration = 20;
|
||||
speed = 8;
|
||||
dest.x = param.game.game_area.center_x - jailTexture->getWidth() / 2;
|
||||
dest.y = param.game.game_area.center_y - jailTexture->getHeight() / 2;
|
||||
sinceSprite->setPosY(dest.y + jailTexture->getHeight() + 5);
|
||||
sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight());
|
||||
sinceSprite->setEnabled(false);
|
||||
sinceTexture->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
||||
ticks_ = 0;
|
||||
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
|
||||
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
|
||||
since_sprite_->setPosY(dest_.y + jail_texture_->getHeight() + 5);
|
||||
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
|
||||
since_sprite_->setEnabled(false);
|
||||
since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ??
|
||||
|
||||
// Crea los sprites de cada linea
|
||||
for (int i = 0; i < jailTexture->getHeight(); ++i)
|
||||
for (int i = 0; i < jail_texture_->getHeight(); ++i)
|
||||
{
|
||||
auto temp = std::make_unique<Sprite>(0, i, jailTexture->getWidth(), 1, jailTexture);
|
||||
temp->setSpriteClip(0, i, jailTexture->getWidth(), 1);
|
||||
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jailTexture->getWidth() - (i * 3);
|
||||
auto temp = std::make_unique<Sprite>(0, i, jail_texture_->getWidth(), 1, jail_texture_);
|
||||
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
|
||||
const int posX = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
|
||||
temp->setPosX(posX);
|
||||
temp->setPosY(dest.y + i);
|
||||
jailSprite.push_back(std::move(temp));
|
||||
temp->setPosY(dest_.y + i);
|
||||
jail_sprite_.push_back(std::move(temp));
|
||||
}
|
||||
|
||||
// Inicializa el vector de colores
|
||||
color.push_back({0x00, 0x00, 0x00}); // Black
|
||||
color.push_back({0x00, 0x00, 0xd8}); // Blue
|
||||
color.push_back({0xd8, 0x00, 0x00}); // Red
|
||||
color.push_back({0xd8, 0x00, 0xd8}); // Magenta
|
||||
color.push_back({0x00, 0xd8, 0x00}); // Green
|
||||
color.push_back({0x00, 0xd8, 0xd8}); // Cyan
|
||||
color.push_back({0xd8, 0xd8, 0x00}); // Yellow
|
||||
color.push_back({0xFF, 0xFF, 0xFF}); // Bright white
|
||||
color_.push_back({0x00, 0x00, 0x00}); // Black
|
||||
color_.push_back({0x00, 0x00, 0xd8}); // Blue
|
||||
color_.push_back({0xd8, 0x00, 0x00}); // Red
|
||||
color_.push_back({0xd8, 0x00, 0xd8}); // Magenta
|
||||
color_.push_back({0x00, 0xd8, 0x00}); // Green
|
||||
color_.push_back({0x00, 0xd8, 0xd8}); // Cyan
|
||||
color_.push_back({0xd8, 0xd8, 0x00}); // Yellow
|
||||
color_.push_back({0xFF, 0xFF, 0xFF}); // Bright white
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
void Logo::reloadTextures()
|
||||
{
|
||||
jailTexture->reLoad();
|
||||
sinceTexture->reLoad();
|
||||
jail_texture_->reLoad();
|
||||
since_texture_->reLoad();
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
@@ -117,26 +111,26 @@ void Logo::checkInput()
|
||||
// Gestiona el logo de JAILGAME
|
||||
void Logo::updateJAILGAMES()
|
||||
{
|
||||
if (counter > 30)
|
||||
if (counter_ > 30)
|
||||
{
|
||||
for (int i = 0; i < (int)jailSprite.size(); ++i)
|
||||
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
|
||||
{
|
||||
if (jailSprite[i]->getPosX() != dest.x)
|
||||
if (jail_sprite_[i]->getPosX() != dest_.x)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
jailSprite[i]->incPosX(-speed);
|
||||
if (jailSprite[i]->getPosX() < dest.x)
|
||||
jail_sprite_[i]->incPosX(-SPEED);
|
||||
if (jail_sprite_[i]->getPosX() < dest_.x)
|
||||
{
|
||||
jailSprite[i]->setPosX(dest.x);
|
||||
jail_sprite_[i]->setPosX(dest_.x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jailSprite[i]->incPosX(speed);
|
||||
if (jailSprite[i]->getPosX() > dest.x)
|
||||
jail_sprite_[i]->incPosX(SPEED);
|
||||
if (jail_sprite_[i]->getPosX() > dest_.x)
|
||||
{
|
||||
jailSprite[i]->setPosX(dest.x);
|
||||
jail_sprite_[i]->setPosX(dest_.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,19 +146,19 @@ void Logo::updateTextureColors()
|
||||
// Manejo de 'sinceTexture'
|
||||
for (int i = 0; i <= 7; ++i)
|
||||
{
|
||||
if (counter == showSinceSprite_cm + inc * i)
|
||||
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + inc * i)
|
||||
{
|
||||
sinceTexture->setColor(color[i].r, color[i].g, color[i].b);
|
||||
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
|
||||
}
|
||||
}
|
||||
|
||||
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
|
||||
for (int i = 0; i <= 6; ++i)
|
||||
{
|
||||
if (counter == initFade_cm + inc * i)
|
||||
if (counter_ == INIT_FADE_COUNTER_MARK + inc * i)
|
||||
{
|
||||
jailTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b);
|
||||
sinceTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b);
|
||||
jail_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
|
||||
since_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,10 +167,10 @@ void Logo::updateTextureColors()
|
||||
void Logo::update()
|
||||
{
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
@@ -191,18 +185,18 @@ void Logo::update()
|
||||
updateTextureColors();
|
||||
|
||||
// Gestiona el contador y sus eventos
|
||||
counter++;
|
||||
counter_++;
|
||||
|
||||
// Comprueba si ha terminado el logo
|
||||
if (counter == endLogo_cm + postLogoDuration)
|
||||
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
|
||||
{
|
||||
section::name = section::Name::INTRO;
|
||||
}
|
||||
|
||||
// Comprueba si se ha de mostrar el sprite
|
||||
else if (counter == showSinceSprite_cm)
|
||||
else if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK)
|
||||
{
|
||||
sinceSprite->setEnabled(true);
|
||||
since_sprite_->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,11 +211,11 @@ void Logo::render()
|
||||
Screen::get()->clean();
|
||||
|
||||
// Dibuja los sprites
|
||||
for (auto &sprite : jailSprite)
|
||||
for (auto &sprite : jail_sprite_)
|
||||
{
|
||||
sprite->render();
|
||||
}
|
||||
sinceSprite->render();
|
||||
since_sprite_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->blit();
|
||||
|
||||
Reference in New Issue
Block a user