forked from jaildesigner-jailgames/jaildoctors_dilemma
Implementado el temporizador del marcador
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *items)
|
||||
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *items, Uint32 *clock)
|
||||
{
|
||||
// Obten punteros a objetos
|
||||
this->asset = asset;
|
||||
this->renderer = renderer;
|
||||
this->lives = lives;
|
||||
this->items = items;
|
||||
this->clock = clock;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
texture = new LTexture();
|
||||
@@ -107,8 +108,10 @@ void ScoreBoard::render()
|
||||
}
|
||||
|
||||
// Escribe los textos
|
||||
// const std::string text = "Items collected 008 Time 88875";
|
||||
std::string text = "Items collected " + std::to_string(*items / 100) + std::to_string((*items % 100) / 10) + std::to_string(*items % 10) + " Time 88875";
|
||||
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 timeTxt = std::to_string((clock.minutes % 60) / 10) + std::to_string(clock.minutes % 10) + ":" + 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, 21 * BLOCK, text, color);
|
||||
}
|
||||
@@ -118,4 +121,15 @@ void ScoreBoard::update()
|
||||
{
|
||||
counter++;
|
||||
sprite->update();
|
||||
}
|
||||
|
||||
// Obtiene el tiempo transcurrido de partida
|
||||
ScoreBoard::clock_t ScoreBoard::getTime()
|
||||
{
|
||||
const Uint32 timeElapsed = SDL_GetTicks() - *clock;
|
||||
clock_t time;
|
||||
time.hours = timeElapsed / 3600000;
|
||||
time.minutes = timeElapsed / 60000;
|
||||
time.seconds = timeElapsed / 1000;
|
||||
return time;
|
||||
}
|
||||
Reference in New Issue
Block a user