Variables renombrades en input.cpp
This commit is contained in:
@@ -19,40 +19,39 @@
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||
: music(music)
|
||||
: music_(music)
|
||||
{
|
||||
// Copia punteros
|
||||
renderer = Screen::get()->getRenderer();
|
||||
renderer_ = Screen::get()->getRenderer();
|
||||
|
||||
// Objetos
|
||||
eventHandler = std::make_unique<SDL_Event>();
|
||||
fade = std::make_unique<Fade>(renderer);
|
||||
background = std::make_unique<Background>(renderer);
|
||||
text = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
|
||||
fade_ = std::make_unique<Fade>(renderer_);
|
||||
background_ = std::make_unique<Background>(renderer_);
|
||||
text_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer_);
|
||||
|
||||
// Crea un backbuffer para el renderizador
|
||||
backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND);
|
||||
backbuffer_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height);
|
||||
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
counter = 0;
|
||||
counterEnd = 800;
|
||||
viewArea = {0, 0, param.game.width, param.game.height};
|
||||
fadeMode = FadeMode::IN;
|
||||
ticks_ = 0;
|
||||
ticks_speed_ = 15;
|
||||
counter_ = 0;
|
||||
counter_end_ = 800;
|
||||
view_area_ = {0, 0, param.game.width, param.game.height};
|
||||
fade_mode_ = FadeMode::IN;
|
||||
|
||||
// Inicializa objetos
|
||||
background->setPos(param.game.game_area.rect);
|
||||
background->setCloudsSpeed(-0.1f);
|
||||
background->setGradientNumber(1);
|
||||
background->setTransition(0.8f);
|
||||
fade->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade->setType(FadeType::RANDOM_SQUARE);
|
||||
fade->setPost(param.fade.post_duration);
|
||||
fade->setMode(fadeMode);
|
||||
fade->activate();
|
||||
background_->setPos(param.game.game_area.rect);
|
||||
background_->setCloudsSpeed(-0.1f);
|
||||
background_->setGradientNumber(1);
|
||||
background_->setTransition(0.8f);
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->setPost(param.fade.post_duration);
|
||||
fade_->setMode(fade_mode_);
|
||||
fade_->activate();
|
||||
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
fillTexture();
|
||||
@@ -61,45 +60,45 @@ HiScoreTable::HiScoreTable(JA_Music_t *music)
|
||||
// Destructor
|
||||
HiScoreTable::~HiScoreTable()
|
||||
{
|
||||
SDL_DestroyTexture(backbuffer);
|
||||
SDL_DestroyTexture(backbuffer_);
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void HiScoreTable::update()
|
||||
{
|
||||
// Actualiza las variables
|
||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
||||
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks = SDL_GetTicks();
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Mantiene la música sonando
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(music);
|
||||
JA_PlayMusic(music_);
|
||||
}
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background->update();
|
||||
background_->update();
|
||||
|
||||
// Gestiona el fade
|
||||
updateFade();
|
||||
|
||||
// Gestiona el contador y sus eventos
|
||||
counter++;
|
||||
counter_++;
|
||||
|
||||
if (counter == 150)
|
||||
if (counter_ == 150)
|
||||
{
|
||||
background->setColor({0, 0, 0});
|
||||
background->setAlpha(96);
|
||||
background_->setColor({0, 0, 0});
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
|
||||
if (counter == counterEnd)
|
||||
if (counter_ == counter_end_)
|
||||
{
|
||||
fade->activate();
|
||||
fade_->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,40 +106,40 @@ void HiScoreTable::update()
|
||||
// Crea el contenido de la textura con la lista de puntuaciones
|
||||
void HiScoreTable::fillTexture()
|
||||
{
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
||||
constexpr auto maxNames = 10;
|
||||
constexpr auto spaceBetweenHeader = 32;
|
||||
const auto spaceBetweenLines = text->getCharacterSize() * 2.0f;
|
||||
const auto size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize();
|
||||
const auto firstLine = (param.game.height - size) / 2;
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - name_lenght 0 num_dots
|
||||
constexpr auto max_names = 10;
|
||||
constexpr auto space_between_header = 32;
|
||||
const auto space_between_lines = text_->getCharacterSize() * 2.0f;
|
||||
const auto size = space_between_header + space_between_lines * (max_names - 1) + text_->getCharacterSize();
|
||||
const auto first_line = (param.game.height - size) / 2;
|
||||
|
||||
// Pinta en el backbuffer el texto y los sprites
|
||||
auto temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
// Escribe el texto: Mejores puntuaciones
|
||||
text->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, firstLine, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, lang::getText(42), 1, orange_color, 1, shdw_txt_color);
|
||||
|
||||
// Escribe los nombres de la tabla de puntuaciones
|
||||
for (int i = 0; i < maxNames; ++i)
|
||||
for (int i = 0; i < max_names; ++i)
|
||||
{
|
||||
const auto nameLenght = options.game.hi_score_table[i].name.length();
|
||||
const auto name_lenght = options.game.hi_score_table[i].name.length();
|
||||
const auto score = format(options.game.hi_score_table[i].score);
|
||||
const auto scoreLenght = score.size();
|
||||
const auto numDots = 25 - nameLenght - scoreLenght;
|
||||
const auto score_lenght = score.size();
|
||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < (int)numDots; ++j)
|
||||
for (int j = 0; j < (int)num_dots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const auto line = options.game.hi_score_table[i].name + dots + score;
|
||||
text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orange_color, 1, shdw_txt_color);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, (i * space_between_lines) + first_line + space_between_header, line, 1, orange_color, 1, shdw_txt_color);
|
||||
}
|
||||
|
||||
// Cambia el destino de renderizado
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Pinta en pantalla
|
||||
@@ -153,16 +152,16 @@ void HiScoreTable::render()
|
||||
Screen::get()->clean(bg_color);
|
||||
|
||||
// Pinta el fondo
|
||||
background->render();
|
||||
background_->render();
|
||||
|
||||
// Establece la ventana del backbuffer
|
||||
viewArea.y = std::max(0, param.game.height - counter + 100);
|
||||
view_area_.y = std::max(0, param.game.height - counter_ + 100);
|
||||
|
||||
// Copia el backbuffer al renderizador
|
||||
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
|
||||
SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_area_);
|
||||
|
||||
// Renderiza el fade
|
||||
fade->render();
|
||||
fade_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->blit();
|
||||
@@ -171,7 +170,7 @@ void HiScoreTable::render()
|
||||
// Recarga todas las texturas
|
||||
void HiScoreTable::reloadTextures()
|
||||
{
|
||||
text->reLoadTexture();
|
||||
text_->reLoadTexture();
|
||||
fillTexture();
|
||||
}
|
||||
|
||||
@@ -179,19 +178,20 @@ void HiScoreTable::reloadTextures()
|
||||
void HiScoreTable::checkEvents()
|
||||
{
|
||||
// Comprueba los eventos que hay en la cola
|
||||
while (SDL_PollEvent(eventHandler.get()) != 0)
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
// Evento de salida de la aplicación
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
section::name = section::Name::QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba si se ha cambiado el tamaño de la ventana
|
||||
else if (eventHandler->type == SDL_WINDOWEVENT)
|
||||
else if (event.type == SDL_WINDOWEVENT)
|
||||
{
|
||||
if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||
{
|
||||
reloadTextures();
|
||||
}
|
||||
@@ -233,16 +233,16 @@ void HiScoreTable::run()
|
||||
// Gestiona el fade
|
||||
void HiScoreTable::updateFade()
|
||||
{
|
||||
fade->update();
|
||||
fade_->update();
|
||||
|
||||
if (fade->hasEnded() && fadeMode == FadeMode::IN)
|
||||
if (fade_->hasEnded() && fade_mode_ == FadeMode::IN)
|
||||
{
|
||||
fade->reset();
|
||||
fadeMode = FadeMode::OUT;
|
||||
fade->setMode(fadeMode);
|
||||
fade_->reset();
|
||||
fade_mode_ = FadeMode::OUT;
|
||||
fade_->setMode(fade_mode_);
|
||||
}
|
||||
|
||||
if (fade->hasEnded() && fadeMode == FadeMode::OUT)
|
||||
if (fade_->hasEnded() && fade_mode_ == FadeMode::OUT)
|
||||
{
|
||||
section::name = section::Name::INSTRUCTIONS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user