El marcador ya se puede pintar en cualquier coordenada
This commit is contained in:
@@ -247,7 +247,7 @@ void Game::init()
|
||||
}
|
||||
|
||||
// Marcador
|
||||
scoreboard->setPos({0, 20, 256, 32});
|
||||
scoreboard->setPos({10, 20, 256, 32});
|
||||
if (difficulty == DIFFICULTY_NORMAL)
|
||||
{
|
||||
scoreboard->setColor({46, 63, 71});
|
||||
|
||||
@@ -10,11 +10,6 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
||||
this->lang = lang;
|
||||
this->options = options;
|
||||
|
||||
// Crea objetos
|
||||
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
|
||||
powerMeterSprite = new Sprite(PLAY_AREA_CENTER_X - 20, 170, 40, 7, gamePowerMeterTexture, renderer);
|
||||
textScoreBoard = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||
|
||||
// Inicializa variables
|
||||
stage = 1;
|
||||
score1 = 0;
|
||||
@@ -25,14 +20,44 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
||||
power = 0;
|
||||
hiScoreName = "";
|
||||
color = {0, 0, 0};
|
||||
rect = {0, 0, 0, 0};
|
||||
offset1 = 0;
|
||||
offset2 = 0;
|
||||
offset3 = 0;
|
||||
offset4 = 0;
|
||||
offsetLeft = 0;
|
||||
offsetRight = 0;
|
||||
offsetCenterX = 0;
|
||||
rect = {0, 0, 256, 32};
|
||||
|
||||
const int left = 45;
|
||||
const int right = rect.w - left;
|
||||
const int center = rect.w / 2;
|
||||
const int desp = 7;
|
||||
const int line1 = 2;
|
||||
const int line2 = line1 + desp;
|
||||
const int line3 = line2 + desp;
|
||||
const int line4 = line3 + desp;
|
||||
|
||||
offsetScoreP1Label = {left, line1};
|
||||
offsetScoreP1 = {left, line2};
|
||||
offsetScoreP2Label = {right, line1};
|
||||
offsetScoreP2 = {right, line2};
|
||||
|
||||
offsetHiScoreLabel = {center, line3};
|
||||
offsetHiScore = {center, line4};
|
||||
|
||||
offsetMultP1Label = {left, line3};
|
||||
offsetMultP1 = {left, line4};
|
||||
offsetMultP2Label = {right, line3};
|
||||
offsetMultP2 = {right, line4};
|
||||
|
||||
offsetStage = {center, line1};
|
||||
offsetPowerMeter = {center, line2};
|
||||
|
||||
// Crea objetos
|
||||
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
|
||||
powerMeterSprite = new Sprite(offsetPowerMeter.x - 20, offsetPowerMeter.y, 40, 7, gamePowerMeterTexture, renderer);
|
||||
textScoreBoard = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||
|
||||
// Crea la textura dibujar el marcador
|
||||
background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||
SDL_SetTextureBlendMode(background, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Rellena la textura de fondo
|
||||
fillBackgroundTexture();
|
||||
}
|
||||
|
||||
Scoreboard::~Scoreboard()
|
||||
@@ -41,6 +66,7 @@ Scoreboard::~Scoreboard()
|
||||
delete gamePowerMeterTexture;
|
||||
delete powerMeterSprite;
|
||||
delete textScoreBoard;
|
||||
SDL_DestroyTexture(background);
|
||||
}
|
||||
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
@@ -87,43 +113,8 @@ std::string Scoreboard::updateScoreText(Uint32 num)
|
||||
// Pinta el marcador
|
||||
void Scoreboard::render()
|
||||
{
|
||||
// Dibuja el fondo del marcador
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
// Dibuja la linea que separa el marcador de la zona de juego
|
||||
SDL_SetRenderDrawColor(renderer, 13, 26, 43, 255);
|
||||
SDL_RenderDrawLine(renderer, 0, 160, 255, 160);
|
||||
|
||||
// PLAYER1 - SCORE
|
||||
textScoreBoard->writeCentered(offsetLeft, offset1, lang->getText(53));
|
||||
textScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(score1));
|
||||
|
||||
// PLAYER1 - MULT
|
||||
textScoreBoard->writeCentered(offsetLeft, offset3, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(mult1).substr(0, 3));
|
||||
|
||||
// PLAYER2 - SCORE
|
||||
textScoreBoard->writeCentered(offsetRight, offset1, lang->getText(54));
|
||||
textScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(score2));
|
||||
|
||||
// PLAYER2 - MULT
|
||||
textScoreBoard->writeCentered(offsetRight, offset3, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetRight, offset4, std::to_string(mult2).substr(0, 3));
|
||||
|
||||
// STAGE
|
||||
textScoreBoard->writeCentered(offsetCenterX, offset1, lang->getText(57) + std::to_string(stage));
|
||||
|
||||
// POWERMETER
|
||||
powerMeterSprite->setPosY(offset2);
|
||||
powerMeterSprite->setSpriteClip(0, 0, 40, 7);
|
||||
powerMeterSprite->render();
|
||||
powerMeterSprite->setSpriteClip(40, 0, int(power * 40.0f), 7);
|
||||
powerMeterSprite->render();
|
||||
|
||||
// HI-SCORE
|
||||
textScoreBoard->writeCentered(offsetCenterX, offset3, lang->getText(56));
|
||||
textScoreBoard->writeCentered(offsetCenterX, offset4, hiScoreName + updateScoreText(hiScore));
|
||||
fillBackgroundTexture();
|
||||
SDL_RenderCopy(renderer, background, nullptr, &rect);
|
||||
}
|
||||
|
||||
void Scoreboard::setScore1(int score)
|
||||
@@ -169,19 +160,68 @@ void Scoreboard::setHiScoreName(std::string name)
|
||||
void Scoreboard::setColor(color_t color)
|
||||
{
|
||||
this->color = color;
|
||||
fillBackgroundTexture();
|
||||
}
|
||||
|
||||
void Scoreboard::setPos(SDL_Rect rect)
|
||||
{
|
||||
this->rect = rect;
|
||||
|
||||
// Anclas para los elementos
|
||||
offset1 = rect.y + 2;
|
||||
offset2 = offset1 + 7;
|
||||
offset3 = offset2 + 7;
|
||||
offset4 = offset3 + 7;
|
||||
|
||||
offsetLeft = rect.x + 45;
|
||||
offsetRight = rect.x + rect.w - 45;
|
||||
offsetCenterX = rect.x + (rect.w / 2);
|
||||
// Recrea la textura de fondo
|
||||
if (background)
|
||||
{
|
||||
SDL_DestroyTexture(background);
|
||||
}
|
||||
background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||
SDL_SetTextureBlendMode(background, SDL_BLENDMODE_BLEND);
|
||||
fillBackgroundTexture();
|
||||
}
|
||||
|
||||
// Rellena la textura de fondo
|
||||
void Scoreboard::fillBackgroundTexture()
|
||||
{
|
||||
// Cambia el destino del renderizador
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, background);
|
||||
|
||||
// Dibuja el fondo del marcador
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
SDL_RenderFillRect(renderer, nullptr);
|
||||
|
||||
// Dibuja la linea que separa el marcador de la zona de juego
|
||||
//SDL_SetRenderDrawColor(renderer, 13, 26, 43, 255);
|
||||
//SDL_RenderDrawLine(renderer, 0, 160, 255, 160);
|
||||
|
||||
// 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));
|
||||
|
||||
// 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));
|
||||
|
||||
// STAGE
|
||||
textScoreBoard->writeCentered(offsetStage.x, offsetStage.y, lang->getText(57) + std::to_string(stage));
|
||||
|
||||
// POWERMETER
|
||||
powerMeterSprite->setPosY(offsetPowerMeter.y);
|
||||
powerMeterSprite->setSpriteClip(0, 0, 40, 7);
|
||||
powerMeterSprite->render();
|
||||
powerMeterSprite->setSpriteClip(40, 0, int(power * 40.0f), 7);
|
||||
powerMeterSprite->render();
|
||||
|
||||
// HI-SCORE
|
||||
textScoreBoard->writeCentered(offsetHiScoreLabel.x, offsetHiScoreLabel.y, lang->getText(56));
|
||||
textScoreBoard->writeCentered(offsetHiScore.x, offsetHiScore.y, hiScoreName + updateScoreText(hiScore));
|
||||
|
||||
// Deja el renderizador apuntando a la pantalla
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
}
|
||||
@@ -22,14 +22,14 @@ class Scoreboard
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||
Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase
|
||||
Sprite *powerMeterSprite; // Sprite para el medidor de poder de la fase
|
||||
Text *textScoreBoard; // Fuente para el marcador del juego
|
||||
SDL_Texture *background; // Textura para dibujar el marcador
|
||||
|
||||
// Variables
|
||||
struct options_t *options; // Variable con todas las variables de las opciones del programa
|
||||
@@ -43,13 +43,22 @@ private:
|
||||
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
||||
color_t color; // Color del marcador
|
||||
SDL_Rect rect; // Posición y dimensiones del marcador
|
||||
int offset1; // Anclas para los elementos del marcador
|
||||
int offset2; // Anclas para los elementos del marcador
|
||||
int offset3; // Anclas para los elementos del marcador
|
||||
int offset4; // Anclas para los elementos del marcador
|
||||
int offsetLeft; // Anclas para los elementos del marcador
|
||||
int offsetRight; // Anclas para los elementos del marcador
|
||||
int offsetCenterX; // Anclas para los elementos del marcador
|
||||
|
||||
SDL_Point offsetScoreP1Label;
|
||||
SDL_Point offsetScoreP1;
|
||||
SDL_Point offsetScoreP2Label;
|
||||
SDL_Point offsetScoreP2;
|
||||
|
||||
SDL_Point offsetMultP1Label;
|
||||
SDL_Point offsetMultP1;
|
||||
SDL_Point offsetMultP2Label;
|
||||
SDL_Point offsetMultP2;
|
||||
|
||||
SDL_Point offsetHiScoreLabel;
|
||||
SDL_Point offsetHiScore;
|
||||
|
||||
SDL_Point offsetStage;
|
||||
SDL_Point offsetPowerMeter;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -75,6 +84,9 @@ public:
|
||||
private:
|
||||
// Transforma un valor numérico en una cadena de 6 cifras
|
||||
std::string updateScoreText(Uint32 num);
|
||||
|
||||
// Rellena la textura de fondo
|
||||
void fillBackgroundTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user