Terminada la tabla de records
This commit is contained in:
@@ -85,20 +85,52 @@ void HiScoreTable::render()
|
||||
SDL_Rect srcRect = {0, 0, 16, 16};
|
||||
|
||||
const color_t orangeColor = {0xFF, 0x7A, 0x00};
|
||||
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
|
||||
const int spaceBetweenHeader = 32;
|
||||
const int spaceBetweenLines = text->getCharacterSize() * 1.8f;
|
||||
const int scorePosition = 180;
|
||||
|
||||
// Pinta en el backbuffer el texto y los sprites
|
||||
SDL_SetRenderTarget(renderer, backbuffer);
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Escribe el texto
|
||||
// Escribe el texto: Mejores puntuaciones
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, SCREEN_CENTER_X, 8, lang->getText(42), 1, orangeColor, 1, shdwTxtColor);
|
||||
|
||||
// Escribe la lista de jugadores
|
||||
int numUsers = jscore::getNumUsers();
|
||||
for (int i = 0; i < numUsers; ++i)
|
||||
{
|
||||
text->writeShadowed(0, (i * text->getCharacterSize())+20, jscore::getUserName(i),shdwTxtColor);
|
||||
text->writeShadowed(100, (i * text->getCharacterSize())+20, std::to_string(jscore::getPoints(i)),shdwTxtColor);
|
||||
const int nameLenght = jscore::getUserName(i).length();
|
||||
const int numDots = 20 - nameLenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < numDots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const std::string line = jscore::getUserName(i) + dots + scoreToString(jscore::getPoints(i));
|
||||
text->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
// Rellena la lista con otros nombres
|
||||
if (numUsers < 10)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
names.insert(names.end(), {"BRY", "USUFONDO", "G.LUCAS", "P.DELGAT", "P.ARRABALERA", "PELECHANO", "SAHUQUILLO"});
|
||||
|
||||
for (int i = numUsers; i < 10; ++i)
|
||||
{
|
||||
const int nameLenght = names.at(i - numUsers).length();
|
||||
const int numDots = 20 - nameLenght;
|
||||
std::string dots = "";
|
||||
for (int j = 0; j < numDots; ++j)
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const std::string line = names.at(i - numUsers) + dots + "0000000";
|
||||
text->writeDX(TXT_CENTER | TXT_SHADOW, SCREEN_CENTER_X, (i * spaceBetweenLines) + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mode == mhst_manual) && (counter % 50 > 14))
|
||||
@@ -177,3 +209,44 @@ section_t HiScoreTable::run(mode_hiScoreTable_e mode)
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
std::string HiScoreTable::scoreToString(Uint32 num)
|
||||
{
|
||||
if ((num >= 0) && (num <= 9))
|
||||
{
|
||||
return ("000000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 10) && (num <= 99))
|
||||
{
|
||||
return ("00000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 100) && (num <= 999))
|
||||
{
|
||||
return ("0000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 1000) && (num <= 9999))
|
||||
{
|
||||
return ("000" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 010000) && (num <= 99999))
|
||||
{
|
||||
return ("00" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 100000) && (num <= 999999))
|
||||
{
|
||||
return ("0" + std::to_string(num));
|
||||
}
|
||||
|
||||
if ((num >= 1000000) && (num <= 9999999))
|
||||
{
|
||||
return (std::to_string(num));
|
||||
}
|
||||
|
||||
return (std::to_string(num));
|
||||
}
|
||||
Reference in New Issue
Block a user