añadido recalculateAnchors a la clase scoreboard
This commit is contained in:
@@ -20,32 +20,10 @@ 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, 256, 32};
|
rect = {0, 0, 320, 40};
|
||||||
|
|
||||||
const int left = 45;
|
// Recalcula las anclas de los elementos
|
||||||
const int right = rect.w - left;
|
recalculateAnchors();
|
||||||
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
|
// Crea objetos
|
||||||
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
|
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
|
||||||
@@ -167,30 +145,8 @@ void Scoreboard::setPos(SDL_Rect rect)
|
|||||||
{
|
{
|
||||||
this->rect = rect;
|
this->rect = rect;
|
||||||
|
|
||||||
const int left = rect.w / 6;
|
// Recalcula las anclas de los elementos
|
||||||
const int right = rect.w - left;
|
recalculateAnchors();
|
||||||
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};
|
|
||||||
|
|
||||||
powerMeterSprite->setPosX(offsetPowerMeter.x - 20);
|
powerMeterSprite->setPosX(offsetPowerMeter.x - 20);
|
||||||
powerMeterSprite->setPosY(offsetPowerMeter.y);
|
powerMeterSprite->setPosY(offsetPowerMeter.y);
|
||||||
@@ -248,3 +204,40 @@ void Scoreboard::fillBackgroundTexture()
|
|||||||
// Deja el renderizador apuntando donde estaba
|
// Deja el renderizador apuntando donde estaba
|
||||||
SDL_SetRenderTarget(renderer, temp);
|
SDL_SetRenderTarget(renderer, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recalcula las anclas de los elementos
|
||||||
|
void Scoreboard::recalculateAnchors()
|
||||||
|
{
|
||||||
|
// Constantes para definir las zonas del marcador: 4 filas y 3 columnas
|
||||||
|
const int rowSize = rect.h / 4;
|
||||||
|
const int textHeight = 7;
|
||||||
|
const int row1 = (rowSize * 0) + (textHeight / 2);
|
||||||
|
const int row2 = (rowSize * 1) + (textHeight / 2) - 1;
|
||||||
|
const int row3 = (rowSize * 2) + (textHeight / 2) - 2;
|
||||||
|
const int row4 = (rowSize * 3) + (textHeight / 2) - 3;
|
||||||
|
|
||||||
|
const int halfColSize = rect.w / 6;
|
||||||
|
const int col1 = halfColSize;
|
||||||
|
const int col2 = halfColSize * 3;
|
||||||
|
const int col3 = halfColSize * 5;
|
||||||
|
|
||||||
|
// Primera fila
|
||||||
|
offsetScoreP1Label = {col1, row1};
|
||||||
|
offsetStage = {col2, row1};
|
||||||
|
offsetScoreP2Label = {col3, row1};
|
||||||
|
|
||||||
|
// Segunda fila
|
||||||
|
offsetScoreP1 = {col1, row2};
|
||||||
|
offsetPowerMeter = {col2, row2};
|
||||||
|
offsetScoreP2 = {col3, row2};
|
||||||
|
|
||||||
|
// Tercera fila
|
||||||
|
offsetMultP1Label = {col1, row3};
|
||||||
|
offsetHiScoreLabel = {col2, row3};
|
||||||
|
offsetMultP2Label = {col3, row3};
|
||||||
|
|
||||||
|
// Cuarta fila
|
||||||
|
offsetMultP1 = {col1, row4};
|
||||||
|
offsetHiScore = {col2, row4};
|
||||||
|
offsetMultP2 = {col3, row4};
|
||||||
|
}
|
||||||
@@ -55,6 +55,15 @@ private:
|
|||||||
SDL_Point offsetStage;
|
SDL_Point offsetStage;
|
||||||
SDL_Point offsetPowerMeter;
|
SDL_Point offsetPowerMeter;
|
||||||
|
|
||||||
|
// Recalcula las anclas de los elementos
|
||||||
|
void recalculateAnchors();
|
||||||
|
|
||||||
|
// Transforma un valor numérico en una cadena de 6 cifras
|
||||||
|
std::string updateScoreText(Uint32 num);
|
||||||
|
|
||||||
|
// Rellena la textura de fondo
|
||||||
|
void fillBackgroundTexture();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options);
|
Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options);
|
||||||
@@ -75,13 +84,6 @@ public:
|
|||||||
void setHiScoreName(std::string name);
|
void setHiScoreName(std::string name);
|
||||||
void setColor(color_t color);
|
void setColor(color_t color);
|
||||||
void setPos(SDL_Rect rect);
|
void setPos(SDL_Rect rect);
|
||||||
|
|
||||||
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user