afegit el modo demo al marcador
This commit is contained in:
@@ -21,6 +21,10 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
||||
hiScoreName = "";
|
||||
color = {0, 0, 0};
|
||||
rect = {0, 0, 320, 40};
|
||||
mode[0] = SCOREBOARD_MODE_PLAYING;
|
||||
mode[1] = SCOREBOARD_MODE_PLAYING;
|
||||
ticks = SDL_GetTicks();
|
||||
counter = 0;
|
||||
|
||||
// Recalcula las anclas de los elementos
|
||||
recalculateAnchors();
|
||||
@@ -88,10 +92,26 @@ std::string Scoreboard::updateScoreText(Uint32 num)
|
||||
return (std::to_string(num));
|
||||
}
|
||||
|
||||
// Actualiza el contador
|
||||
void Scoreboard::updateCounter()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks > SCOREBOARD_TICK_SPEED)
|
||||
{
|
||||
ticks = SDL_GetTicks();
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica del marcador
|
||||
void Scoreboard::update()
|
||||
{
|
||||
fillBackgroundTexture();
|
||||
updateCounter();
|
||||
}
|
||||
|
||||
// Pinta el marcador
|
||||
void Scoreboard::render()
|
||||
{
|
||||
fillBackgroundTexture();
|
||||
SDL_RenderCopy(renderer, background, nullptr, &rect);
|
||||
}
|
||||
|
||||
@@ -182,21 +202,47 @@ void Scoreboard::fillBackgroundTexture()
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
SDL_RenderFillRect(renderer, nullptr);
|
||||
|
||||
// PLAYER1 - SCORE
|
||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
||||
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
|
||||
// PARTE IZQUIERDA
|
||||
if (mode[SCOREBOARD_LEFT_SIDE] == SCOREBOARD_MODE_PLAYING)
|
||||
{ // PLAYER1 - SCORE
|
||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
||||
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
|
||||
|
||||
// PLAYER1 - MULT
|
||||
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y, std::to_string(mult1).substr(0, 3));
|
||||
// PLAYER1 - MULT
|
||||
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y, std::to_string(mult1).substr(0, 3));
|
||||
}
|
||||
|
||||
// PLAYER2 - SCORE
|
||||
textScoreBoard->writeCentered(offsetScoreP2Label.x, offsetScoreP2Label.y, lang->getText(54));
|
||||
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, updateScoreText(score2));
|
||||
else if (mode[SCOREBOARD_LEFT_SIDE] == SCOREBOARD_MODE_DEMO)
|
||||
{
|
||||
if (counter % 2 == 0)
|
||||
{
|
||||
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, "Mode");
|
||||
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, "Demo");
|
||||
}
|
||||
}
|
||||
|
||||
// PLAYER2 - MULT
|
||||
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetMultP2.x, offsetMultP2.y, std::to_string(mult2).substr(0, 3));
|
||||
// PARTE DERECHA
|
||||
if (mode[SCOREBOARD_RIGHT_SIDE] == SCOREBOARD_MODE_PLAYING)
|
||||
{ // PLAYER2 - SCORE
|
||||
textScoreBoard->writeCentered(offsetScoreP2Label.x, offsetScoreP2Label.y, lang->getText(54));
|
||||
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, updateScoreText(score2));
|
||||
|
||||
// PLAYER2 - MULT
|
||||
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetMultP2.x, offsetMultP2.y, std::to_string(mult2).substr(0, 3));
|
||||
}
|
||||
|
||||
else if (mode[SCOREBOARD_RIGHT_SIDE] == SCOREBOARD_MODE_DEMO)
|
||||
{
|
||||
if (counter % 2 == 0)
|
||||
{
|
||||
textScoreBoard->writeCentered(offsetScoreP2.x, offsetScoreP2.y, "Mode");
|
||||
textScoreBoard->writeCentered(offsetMultP2Label.x, offsetMultP2Label.y, "Demo");
|
||||
}
|
||||
}
|
||||
|
||||
// PARTE CENTRAL
|
||||
|
||||
// STAGE
|
||||
textScoreBoard->writeCentered(offsetStage.x, offsetStage.y, lang->getText(57) + std::to_string(stage));
|
||||
@@ -250,4 +296,10 @@ void Scoreboard::recalculateAnchors()
|
||||
offsetMultP1 = {col1, row4};
|
||||
offsetHiScore = {col2, row4};
|
||||
offsetMultP2 = {col3, row4};
|
||||
}
|
||||
|
||||
// Establece el modo del marcador
|
||||
void Scoreboard::setMode(int index, scoreboard_modes_e mode)
|
||||
{
|
||||
this->mode[index] = mode;
|
||||
}
|
||||
Reference in New Issue
Block a user