El marcador ya se puede pintar en cualquier coordenada
This commit is contained in:
@@ -247,7 +247,7 @@ void Game::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Marcador
|
// Marcador
|
||||||
scoreboard->setPos({0, 20, 256, 32});
|
scoreboard->setPos({10, 20, 256, 32});
|
||||||
if (difficulty == DIFFICULTY_NORMAL)
|
if (difficulty == DIFFICULTY_NORMAL)
|
||||||
{
|
{
|
||||||
scoreboard->setColor({46, 63, 71});
|
scoreboard->setColor({46, 63, 71});
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
|||||||
this->lang = lang;
|
this->lang = lang;
|
||||||
this->options = options;
|
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
|
// Inicializa variables
|
||||||
stage = 1;
|
stage = 1;
|
||||||
score1 = 0;
|
score1 = 0;
|
||||||
@@ -25,14 +20,44 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
|||||||
power = 0;
|
power = 0;
|
||||||
hiScoreName = "";
|
hiScoreName = "";
|
||||||
color = {0, 0, 0};
|
color = {0, 0, 0};
|
||||||
rect = {0, 0, 0, 0};
|
rect = {0, 0, 256, 32};
|
||||||
offset1 = 0;
|
|
||||||
offset2 = 0;
|
const int left = 45;
|
||||||
offset3 = 0;
|
const int right = rect.w - left;
|
||||||
offset4 = 0;
|
const int center = rect.w / 2;
|
||||||
offsetLeft = 0;
|
const int desp = 7;
|
||||||
offsetRight = 0;
|
const int line1 = 2;
|
||||||
offsetCenterX = 0;
|
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()
|
Scoreboard::~Scoreboard()
|
||||||
@@ -41,6 +66,7 @@ Scoreboard::~Scoreboard()
|
|||||||
delete gamePowerMeterTexture;
|
delete gamePowerMeterTexture;
|
||||||
delete powerMeterSprite;
|
delete powerMeterSprite;
|
||||||
delete textScoreBoard;
|
delete textScoreBoard;
|
||||||
|
SDL_DestroyTexture(background);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
@@ -87,43 +113,8 @@ std::string Scoreboard::updateScoreText(Uint32 num)
|
|||||||
// Pinta el marcador
|
// Pinta el marcador
|
||||||
void Scoreboard::render()
|
void Scoreboard::render()
|
||||||
{
|
{
|
||||||
// Dibuja el fondo del marcador
|
fillBackgroundTexture();
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
SDL_RenderCopy(renderer, background, nullptr, &rect);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scoreboard::setScore1(int score)
|
void Scoreboard::setScore1(int score)
|
||||||
@@ -169,19 +160,68 @@ void Scoreboard::setHiScoreName(std::string name)
|
|||||||
void Scoreboard::setColor(color_t color)
|
void Scoreboard::setColor(color_t color)
|
||||||
{
|
{
|
||||||
this->color = color;
|
this->color = color;
|
||||||
|
fillBackgroundTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scoreboard::setPos(SDL_Rect rect)
|
void Scoreboard::setPos(SDL_Rect rect)
|
||||||
{
|
{
|
||||||
this->rect = rect;
|
this->rect = rect;
|
||||||
|
|
||||||
// Anclas para los elementos
|
// Recrea la textura de fondo
|
||||||
offset1 = rect.y + 2;
|
if (background)
|
||||||
offset2 = offset1 + 7;
|
{
|
||||||
offset3 = offset2 + 7;
|
SDL_DestroyTexture(background);
|
||||||
offset4 = offset3 + 7;
|
}
|
||||||
|
background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
|
||||||
|
SDL_SetTextureBlendMode(background, SDL_BLENDMODE_BLEND);
|
||||||
|
fillBackgroundTexture();
|
||||||
|
}
|
||||||
|
|
||||||
offsetLeft = rect.x + 45;
|
// Rellena la textura de fondo
|
||||||
offsetRight = rect.x + rect.w - 45;
|
void Scoreboard::fillBackgroundTexture()
|
||||||
offsetCenterX = rect.x + (rect.w / 2);
|
{
|
||||||
|
// 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:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||||
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *lang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
|
||||||
Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase
|
Texture *gamePowerMeterTexture; // Textura con el marcador de poder de la fase
|
||||||
Sprite *powerMeterSprite; // Sprite para el medidor de poder de la fase
|
Sprite *powerMeterSprite; // Sprite para el medidor de poder de la fase
|
||||||
Text *textScoreBoard; // Fuente para el marcador del juego
|
Text *textScoreBoard; // Fuente para el marcador del juego
|
||||||
|
SDL_Texture *background; // Textura para dibujar el marcador
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
struct options_t *options; // Variable con todas las variables de las opciones del programa
|
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
|
std::string hiScoreName; // Nombre del jugador con la máxima puntuación
|
||||||
color_t color; // Color del marcador
|
color_t color; // Color del marcador
|
||||||
SDL_Rect rect; // Posición y dimensiones 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
|
SDL_Point offsetScoreP1Label;
|
||||||
int offset3; // Anclas para los elementos del marcador
|
SDL_Point offsetScoreP1;
|
||||||
int offset4; // Anclas para los elementos del marcador
|
SDL_Point offsetScoreP2Label;
|
||||||
int offsetLeft; // Anclas para los elementos del marcador
|
SDL_Point offsetScoreP2;
|
||||||
int offsetRight; // Anclas para los elementos del marcador
|
|
||||||
int offsetCenterX; // Anclas para los elementos del marcador
|
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:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -75,6 +84,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
// Transforma un valor numérico en una cadena de 6 cifras
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
std::string updateScoreText(Uint32 num);
|
std::string updateScoreText(Uint32 num);
|
||||||
|
|
||||||
|
// Rellena la textura de fondo
|
||||||
|
void fillBackgroundTexture();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user