Añadida mas información al marcador

This commit is contained in:
2022-09-11 19:59:09 +02:00
parent 3eab857267
commit ccb58c169c
8 changed files with 156 additions and 53 deletions

View File

@@ -3,18 +3,17 @@
#include <sstream>
// Constructor
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *items, Uint32 *clock)
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, board_t *board)
{
// Obten punteros a objetos
this->asset = asset;
this->renderer = renderer;
this->lives = lives;
this->items = items;
this->clock = clock;
this->board = board;
// Reserva memoria para los objetos
texture = new LTexture(renderer, asset->get("player.png"));
sprite = new AnimatedSprite(texture, renderer, asset->get("player.ani"));
playerTexture = new LTexture(renderer, asset->get("player.png"));
itemTexture = new LTexture(renderer, asset->get("items.png"));
sprite = new AnimatedSprite(playerTexture, renderer, asset->get("player.ani"));
sprite->setCurrentAnimation("walk_menu");
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
@@ -26,8 +25,8 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it
color_t c = stringToColor("blue");
color.push_back(c);
c = stringToColor("red");
color.push_back(c);
//c = stringToColor("red");
//color.push_back(c);
c = stringToColor("magenta");
color.push_back(c);
@@ -47,8 +46,8 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it
c = stringToColor("bright_blue");
color.push_back(c);
c = stringToColor("bright_red");
color.push_back(c);
//c = stringToColor("bright_red");
//color.push_back(c);
c = stringToColor("bright_magenta");
color.push_back(c);
@@ -69,7 +68,8 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it
// Destructor
ScoreBoard::~ScoreBoard()
{
delete texture;
delete playerTexture;
delete itemTexture;
delete sprite;
delete text;
}
@@ -89,7 +89,7 @@ void ScoreBoard::render()
const int frame = desp % 4;
sprite->setCurrentFrame(frame);
for (int i = 0; i < *lives; i++)
for (int i = 0; i < board->lives; i++)
{
sprite->setPosX(8 + (16 * i) + desp);
index = i % color.size();
@@ -97,18 +97,25 @@ void ScoreBoard::render()
sprite->render();
}
// Escribe los textos
const clock_t clock = getTime();
std::string itemsTxt = std::to_string(*items / 100) + std::to_string((*items % 100) / 10) + std::to_string(*items % 10);
std::string separator = " ";
if (clock.separator)
// Muestra si suena la música
if (board->music)
{
separator = ":";
const color_t c = stringToColor("bright_blue");
SDL_Rect clip = {0, 8, 8, 8};
itemTexture->setColor(c.r, c.g, c.b);
itemTexture->render(renderer, 20 * BLOCK, 20 * BLOCK, &clip);
}
std::string timeTxt = std::to_string((clock.minutes % 60) / 10) + std::to_string(clock.minutes % 10) + separator + std::to_string((clock.seconds % 60) / 10) + std::to_string(clock.seconds % 10);
std::string text = "Items collected " + itemsTxt + " Time " + timeTxt;
const color_t color = stringToColor("white");
this->text->writeColored(BLOCK, 22 * BLOCK, text, color);
// Escribe los textos
const std::string timeTxt = std::to_string((clock.minutes % 60) / 10) + std::to_string(clock.minutes % 10) + clock.separator + std::to_string((clock.seconds % 60) / 10) + std::to_string(clock.seconds % 10);
const std::string itemsTxt = std::to_string(board->items / 100) + std::to_string((board->items % 100) / 10) + std::to_string(board->items % 10);
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
this->text->writeColored(22 * BLOCK, 20 * BLOCK, "Rooms", stringToColor("yellow"));
this->text->writeColored(28 * BLOCK, 20 * BLOCK, roomsTxt, stringToColor("bright_blue"));
this->text->writeColored(BLOCK, 22 * BLOCK, "Items collected ", stringToColor("yellow"));
this->text->writeColored(17 * BLOCK, 22 * BLOCK, itemsTxt, stringToColor("bright_blue"));
this->text->writeColored(20 * BLOCK, 22 * BLOCK, " Time ", stringToColor("yellow"));
this->text->writeColored(26 * BLOCK, 22 * BLOCK, timeTxt, stringToColor("bright_blue"));
}
// Actualiza las variables del objeto
@@ -116,23 +123,27 @@ void ScoreBoard::update()
{
counter++;
sprite->update();
clock = getTime();
}
// Obtiene el tiempo transcurrido de partida
ScoreBoard::clock_t ScoreBoard::getTime()
{
const Uint32 timeElapsed = SDL_GetTicks() - *clock;
const Uint32 timeElapsed = SDL_GetTicks() - board->iniClock;
clock_t time;
time.hours = timeElapsed / 3600000;
time.minutes = timeElapsed / 60000;
time.seconds = timeElapsed / 1000;
time.separator = (timeElapsed % 1000 <= 500);
time.separator = (timeElapsed % 1000 <= 500) ? ":" : " ";
return time;
}
// Recarga la textura
void ScoreBoard::reLoadTexture()
{
texture->reLoad();
playerTexture->reLoad();
itemTexture->reLoad();
text->reLoadTexture();
}