Trabajando en el marcador
This commit is contained in:
56
source/scoreboard.cpp
Normal file
56
source/scoreboard.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "scoreboard.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, board_t *board)
|
||||
{
|
||||
// Obten punteros a objetos
|
||||
this->asset = asset;
|
||||
this->renderer = renderer;
|
||||
this->board = board;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
texture = new LTexture(renderer, asset->get("player.png"));
|
||||
sprite = new Sprite({0, 0, 0, 0}, texture, renderer);
|
||||
text = new Text(asset->get("dogica.png"), asset->get("dogica.txt"), renderer);
|
||||
|
||||
// Inicializa las variables
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
ScoreBoard::~ScoreBoard()
|
||||
{
|
||||
delete texture;
|
||||
delete sprite;
|
||||
delete text;
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void ScoreBoard::render()
|
||||
{
|
||||
// Ponenegro el fondo del marcador
|
||||
const SDL_Rect rect = {0, 0, PLAY_AREA_WIDTH, 2 * 8};
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
// Escribe los textos
|
||||
text->writeCentered(PLAY_AREA_CENTER_FIRST_QUARTER_X, 1, "-LIVES-");
|
||||
text->writeCentered(PLAY_AREA_CENTER_FIRST_QUARTER_X, 1 + text->getCharacterSize(), std::to_string(board->lives));
|
||||
text->writeCentered(PLAY_AREA_CENTER_THIRD_QUARTER_X, 1, "-DIAMONDS-");
|
||||
text->writeCentered(PLAY_AREA_CENTER_THIRD_QUARTER_X, 1 + text->getCharacterSize(), std::to_string(board->diamonds));
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void ScoreBoard::update()
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
void ScoreBoard::reLoadTexture()
|
||||
{
|
||||
texture->reLoad();
|
||||
text->reLoadTexture();
|
||||
}
|
||||
Reference in New Issue
Block a user