Treballant en scoreboard::fillPanelTextures

This commit is contained in:
2025-02-06 20:58:15 +01:00
parent 44e4ca490d
commit 559210652f
11 changed files with 194 additions and 134 deletions

View File

@@ -10,7 +10,7 @@
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text
#include "enter_name.h"
#include "enter_name.h" // Para NAME_LENGHT
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Scoreboard *Scoreboard::scoreboard_ = nullptr;
@@ -68,6 +68,9 @@ Scoreboard::Scoreboard()
// Rellena la textura de fondo
fillBackgroundTexture();
// Inicializa el vector de colores para el nombre
iniNameColors();
}
Scoreboard::~Scoreboard()
@@ -95,14 +98,14 @@ std::string Scoreboard::updateScoreText(int num)
}
// Actualiza el contador
void Scoreboard::updateCounter()
void Scoreboard::updateTimeCounter()
{
constexpr int TICKS_SPEED = 100;
if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
{
ticks_ = SDL_GetTicks();
counter_++;
++time_counter_;
}
}
@@ -110,7 +113,8 @@ void Scoreboard::updateCounter()
void Scoreboard::update()
{
fillBackgroundTexture();
updateCounter();
updateTimeCounter();
++loop_counter_;
}
// Pinta el marcador
@@ -180,7 +184,7 @@ void Scoreboard::fillPanelTextures()
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(101));
// PRESS START TO PLAY
if (counter_ % 10 < 8)
if (time_counter_ % 10 < 8)
{
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(103));
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText(104));
@@ -194,7 +198,7 @@ void Scoreboard::fillPanelTextures()
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(102));
// PRESS START TO PLAY
if (counter_ % 10 < 8)
if (time_counter_ % 10 < 8)
{
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(103));
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText(104));
@@ -208,7 +212,7 @@ void Scoreboard::fillPanelTextures()
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(102));
// PLEASE WAIT
if (counter_ % 10 < 8)
if (time_counter_ % 10 < 8)
{
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(114));
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, lang::getText(115));
@@ -257,13 +261,13 @@ void Scoreboard::fillPanelTextures()
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106));
SDL_Rect rect = {enter_name_pos_.x, enter_name_pos_.y, 5, 7};
// Recorre el nombre
for (size_t j = 0; j < record_name_[i].size(); ++j)
// Recorre todos los slots de letras del nombre
for (size_t j = 0; j < NAME_LENGHT; ++j)
{
// Selecciona el color
const Color color = j < selector_pos_[i] ? orange_soft_color.lighten() : Color(0xFF, 0xFF, 0xEB);
if (j != selector_pos_[i] || counter_ % 3 == 0)
if (j != selector_pos_[i] || time_counter_ % 3 == 0)
{
// Dibuja la linea
if (j >= selector_pos_[i])
@@ -273,20 +277,34 @@ void Scoreboard::fillPanelTextures()
}
// Dibuja la letra
text_scoreboard_->writeColored(rect.x, rect.y, record_name_[i].substr(j, 1), color);
if (j < record_name_->size())
{
text_scoreboard_->writeColored(rect.x, rect.y, record_name_[i].substr(j, 1), color);
}
}
rect.x += 7;
}
}
break;
}
case ScoreboardMode::SHOW_NAME:
{
// SCORE
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y, name_[i]);
text_scoreboard_->writeCentered(slot4_2_.x, slot4_2_.y, updateScoreText(score_[i]));
// NAME
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106));
text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[i], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
break;
}
case ScoreboardMode::GAME_COMPLETED:
{
// GAME OVER
text_scoreboard_->writeCentered(slot4_1_.x, slot4_1_.y + 4, lang::getText(102));
// SCORE
if (counter_ % 10 < 8)
if (time_counter_ % 10 < 8)
{
text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y - 2, lang::getText(120));
text_scoreboard_->writeCentered(slot4_4_.x, slot4_4_.y - 2, updateScoreText(score_[i]));
@@ -295,6 +313,9 @@ void Scoreboard::fillPanelTextures()
default:
break;
}
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255);
SDL_RenderDrawLine(renderer_, (float)rect_.w / (float)SCOREBOARD_MAX_PANELS / 2, 0, (float)rect_.w / (float)SCOREBOARD_MAX_PANELS / 2, rect_.h);
}
// Deja el renderizador apuntando donde estaba
@@ -332,27 +353,27 @@ void Scoreboard::fillBackgroundTexture()
void Scoreboard::recalculateAnchors()
{
// Recalcula la posición y el tamaño de los paneles
const float panelWidth = (float)rect_.w / (float)SCOREBOARD_MAX_PANELS;
const float panel_width = (float)rect_.w / (float)SCOREBOARD_MAX_PANELS;
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
{
panel_[i].pos.x = roundf(panelWidth * i);
panel_[i].pos.x = roundf(panel_width * i);
panel_[i].pos.y = 0;
panel_[i].pos.w = roundf(panelWidth * (i + 1)) - panel_[i].pos.x;
panel_[i].pos.w = roundf(panel_width * (i + 1)) - panel_[i].pos.x;
panel_[i].pos.h = rect_.h;
}
// Constantes para definir las zonas del panel_: 4 filas y 1 columna
const int rowSize = rect_.h / 4;
const int textHeight = 7;
const int row_size = rect_.h / 4;
const int text_height = 7;
// Filas
const int row1 = (rowSize * 0) + (textHeight / 2);
const int row2 = (rowSize * 1) + (textHeight / 2) - 1;
const int row3 = (rowSize * 2) + (textHeight / 2) - 2;
const int row4 = (rowSize * 3) + (textHeight / 2) - 3;
const int row1 = (row_size * 0) + (text_height / 2);
const int row2 = (row_size * 1) + (text_height / 2) - 1;
const int row3 = (row_size * 2) + (text_height / 2) - 2;
const int row4 = (row_size * 3) + (text_height / 2) - 3;
// Columna
const int col = panelWidth / 2;
const int col = panel_width / 2;
// Slots de 4
slot4_1_ = {col, row1};
@@ -361,8 +382,9 @@ void Scoreboard::recalculateAnchors()
slot4_4_ = {col, row4};
// Primer cuadrado para poner el nombre de record
const int enterNameLenght = NAME_LENGHT * 7;
enter_name_pos_.x = (panelWidth - enterNameLenght) / 2;
// const int enter_name_lenght = NAME_LENGHT * 7;
const int enter_name_lenght = text_scoreboard_->lenght(std::string(NAME_LENGHT, ' '));
enter_name_pos_.x = (panel_width - enter_name_lenght) / 2;
enter_name_pos_.y = row4;
// Recoloca los sprites
@@ -415,4 +437,14 @@ void Scoreboard::renderSeparator()
// Dibuja la linea que separa el marcador de la zona de juego
SDL_SetRenderDrawColor(renderer_, separator_color.r, separator_color.g, separator_color.b, 255);
SDL_RenderDrawLine(renderer_, 0, 0, rect_.w, 0);
}
// Inicializa el vector de colores para el nombre
void Scoreboard::iniNameColors()
{
name_colors_.clear();
name_colors_.emplace_back(green_color.lighten(50));
name_colors_.emplace_back(green_color.lighten(25));
name_colors_.emplace_back(green_color);
name_colors_.emplace_back(green_color.darken(25));
}