fix: els panels del marcador estiraven els bitmaps al no coincidir srcRect amb dstRect
This commit is contained in:
@@ -11,6 +11,11 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
||||
this->lang = lang;
|
||||
this->options = options;
|
||||
|
||||
// Inicializa punteros
|
||||
gamePowerMeterTexture = nullptr;
|
||||
powerMeterSprite = nullptr;
|
||||
textScoreBoard = nullptr;
|
||||
|
||||
// Inicializa variables
|
||||
stage = 1;
|
||||
score1 = 0;
|
||||
@@ -33,12 +38,11 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lan
|
||||
|
||||
// Crea objetos
|
||||
gamePowerMeterTexture = new Texture(renderer, asset->get("game_power_meter.png"));
|
||||
powerMeterSprite = new Sprite(offsetPowerMeter.x - 20, offsetPowerMeter.y, 40, 7, gamePowerMeterTexture);
|
||||
powerMeterSprite = new Sprite(slot4_2.x - 20, slot4_2.y, 40, 7, gamePowerMeterTexture);
|
||||
textScoreBoard = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
|
||||
|
||||
background = nullptr;
|
||||
|
||||
// Crea la textura de fondo
|
||||
background = nullptr;
|
||||
createBackgroundTexture();
|
||||
|
||||
// Crea las texturas de los paneles
|
||||
@@ -194,9 +198,6 @@ void Scoreboard::setPos(SDL_Rect rect)
|
||||
// Recalcula las anclas de los elementos
|
||||
recalculateAnchors();
|
||||
|
||||
powerMeterSprite->setPosX(offsetPowerMeter.x - 20);
|
||||
powerMeterSprite->setPosY(offsetPowerMeter.y);
|
||||
|
||||
// Crea la textura de fondo
|
||||
createBackgroundTexture();
|
||||
|
||||
@@ -227,35 +228,35 @@ void Scoreboard::fillPanelTextures()
|
||||
{
|
||||
case SCOREBOARD_MODE_SCORE:
|
||||
// SCORE
|
||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
||||
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, lang->getText(53));
|
||||
textScoreBoard->writeCentered(slot4_2.x, slot4_2.y, updateScoreText(score1));
|
||||
|
||||
// MULT
|
||||
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y, lang->getText(55));
|
||||
textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y, std::to_string(mult1).substr(0, 3));
|
||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang->getText(55));
|
||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(mult1).substr(0, 3));
|
||||
break;
|
||||
|
||||
case SCOREBOARD_MODE_DEMO:
|
||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y + 4, "Mode demostracio");
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, "Mode demostracio");
|
||||
if (counter % 10 < 8)
|
||||
{
|
||||
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y - 2, "Pulsa START");
|
||||
textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y - 2, "per jugar");
|
||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, "Pulsa START");
|
||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, "per jugar");
|
||||
}
|
||||
break;
|
||||
|
||||
case SCOREBOARD_MODE_GAME_OVER:
|
||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y + 4, "Game Over");
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y + 4, "Game Over");
|
||||
if (counter % 10 < 8)
|
||||
{
|
||||
textScoreBoard->writeCentered(offsetMultP1Label.x, offsetMultP1Label.y - 2, "Pulsa START");
|
||||
textScoreBoard->writeCentered(offsetMultP1.x, offsetMultP1.y - 2, "per jugar");
|
||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y - 2, "Pulsa START");
|
||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y - 2, "per jugar");
|
||||
}
|
||||
break;
|
||||
|
||||
case SCOREBOARD_MODE_STAGE_INFO:
|
||||
// STAGE
|
||||
textScoreBoard->writeCentered(offsetStage.x, offsetStage.y, lang->getText(57) + std::to_string(stage));
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, lang->getText(57) + std::to_string(stage));
|
||||
|
||||
// POWERMETER
|
||||
powerMeterSprite->setSpriteClip(0, 0, 40, 7);
|
||||
@@ -264,8 +265,8 @@ void Scoreboard::fillPanelTextures()
|
||||
powerMeterSprite->render();
|
||||
|
||||
// HI-SCORE
|
||||
textScoreBoard->writeCentered(offsetHiScoreLabel.x, offsetHiScoreLabel.y, lang->getText(56));
|
||||
textScoreBoard->writeCentered(offsetHiScore.x, offsetHiScore.y, hiScoreName + updateScoreText(hiScore));
|
||||
textScoreBoard->writeCentered(slot4_3.x, slot4_3.y, lang->getText(56));
|
||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, hiScoreName + updateScoreText(hiScore));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -289,7 +290,7 @@ void Scoreboard::fillBackgroundTexture()
|
||||
|
||||
// Dibuja el fondo del marcador
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||
SDL_RenderFillRect(renderer, nullptr);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Copia las texturas de los paneles
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
@@ -304,6 +305,7 @@ void Scoreboard::fillBackgroundTexture()
|
||||
// Recalcula las anclas de los elementos
|
||||
void Scoreboard::recalculateAnchors()
|
||||
{
|
||||
// Recalcula la posición y el tamaño de los paneles
|
||||
const float panelWidth = (float)rect.w / (float)SCOREBOARD_MAX_PANELS;
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
{
|
||||
@@ -326,25 +328,18 @@ void Scoreboard::recalculateAnchors()
|
||||
// Columna
|
||||
const int col = panelWidth / 2;
|
||||
|
||||
// Primera fila
|
||||
offsetScoreP1Label = {col, row1};
|
||||
offsetStage = {col, row1};
|
||||
offsetScoreP2Label = {col, row1};
|
||||
// Slots de 4
|
||||
slot4_1 = {col, row1};
|
||||
slot4_2 = {col, row2};
|
||||
slot4_3 = {col, row3};
|
||||
slot4_4 = {col, row4};
|
||||
|
||||
// Segunda fila
|
||||
offsetScoreP1 = {col, row2};
|
||||
offsetPowerMeter = {col, row2};
|
||||
offsetScoreP2 = {col, row2};
|
||||
|
||||
// Tercera fila
|
||||
offsetMultP1Label = {col, row3};
|
||||
offsetHiScoreLabel = {col, row3};
|
||||
offsetMultP2Label = {col, row3};
|
||||
|
||||
// Cuarta fila
|
||||
offsetMultP1 = {col, row4};
|
||||
offsetHiScore = {col, row4};
|
||||
offsetMultP2 = {col, row4};
|
||||
// Recoloca los sprites
|
||||
if (powerMeterSprite)
|
||||
{
|
||||
powerMeterSprite->setPosX(slot4_2.x - 20);
|
||||
powerMeterSprite->setPosY(slot4_2.y);
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el modo del marcador
|
||||
@@ -383,7 +378,7 @@ void Scoreboard::createPanelTextures()
|
||||
// Crea las texturas para cada panel
|
||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||
{
|
||||
SDL_Texture *tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w / SCOREBOARD_MAX_PANELS, rect.h);
|
||||
SDL_Texture *tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, panel[i].pos.w, panel[i].pos.h);
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
panelTexture.push_back(tex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user