Cambiados muchos DEFINEs por variables de param

This commit is contained in:
2024-09-06 08:41:10 +02:00
parent c5bab7019c
commit 62b1ba84ac
23 changed files with 215 additions and 158 deletions

View File

@@ -28,7 +28,7 @@ Game::Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *l
scoreboard = new Scoreboard(renderer, asset, lang, options);
background = new Background(renderer, asset, param);
explosions = new Explosions();
enemyFormations = new EnemyFormations();
enemyFormations = new EnemyFormations(param);
// Carga los recursos
loadMedia();
@@ -42,6 +42,8 @@ Game::Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *l
loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]);
}
background->setPos(param->game.playArea.rect);
n1000Sprite = new SmartSprite(gameTextTexture);
n2500Sprite = new SmartSprite(gameTextTexture);
n5000Sprite = new SmartSprite(gameTextTexture);
@@ -51,7 +53,7 @@ Game::Game(int playerID, int currentStage, Screen *screen, Asset *asset, Lang *l
explosions->addTexture(3, explosionsTextures[2], explosionsAnimations[2]);
explosions->addTexture(4, explosionsTextures[3], explosionsAnimations[3]);
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, playArea.w, playArea.h);
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.playArea.rect.w, param->game.playArea.rect.h);
SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND);
// Inicializa las variables necesarias para la sección 'Game'
@@ -106,12 +108,12 @@ void Game::init(int playerID)
players.clear();
// Crea los dos jugadores
Player *player1 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[0], playerAnimations);
Player *player1 = new Player((param->game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, &param->game.playArea.rect ,playerTextures[0], playerAnimations);
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
player1->setName(lang->getText(53));
players.push_back(player1);
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 30, playerTextures[1], playerAnimations);
Player *player2 = new Player((param->game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, &param->game.playArea.rect, playerTextures[1], playerAnimations);
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
player2->setName(lang->getText(54));
players.push_back(player2);
@@ -977,11 +979,11 @@ int Game::createBalloon(float x, int y, int kind, float velx, float speed, int c
void Game::createPowerBall()
{
const int values = 6;
const int posY = PLAY_AREA_TOP - BLOCK;
const int posY = -BLOCK;
const int left = PLAY_AREA_LEFT;
const int center = PLAY_AREA_CENTER_X - (BALLOON_WIDTH_4 / 2);
const int right = PLAY_AREA_RIGHT - BALLOON_WIDTH_4;
const int center = param->game.playArea.centerX - (BALLOON_WIDTH_4 / 2);
const int right = param->game.playArea.rect.w - BALLOON_WIDTH_4;
const float vpos = BALLOON_VELX_POSITIVE;
const float vneg = BALLOON_VELX_NEGATIVE;
@@ -1466,7 +1468,7 @@ void Game::renderBullets()
// Crea un objeto bala
void Game::createBullet(int x, int y, int kind, bool poweredUp, int owner)
{
Bullet *b = new Bullet(x, y, kind, poweredUp, owner, bulletTexture);
Bullet *b = new Bullet(x, y, kind, poweredUp, owner, &param->game.playArea.rect, bulletTexture);
bullets.push_back(b);
}
@@ -1591,7 +1593,7 @@ int Game::dropItem()
// Crea un objeto item
void Game::createItem(int kind, float x, float y)
{
Item *item = new Item(kind, x, y, itemTextures[kind - 1], itemAnimations[kind - 1]);
Item *item = new Item(kind, x, y, &param->game.playArea.rect, itemTextures[kind - 1], itemAnimations[kind - 1]);
items.push_back(item);
}
@@ -1849,7 +1851,7 @@ void Game::update()
}
#endif
if (!paused)
{
{
// Actualiza el objeto fade
fade->update();
@@ -1989,7 +1991,7 @@ void Game::render()
screen->start();
// Copia la textura con la zona de juego a la pantalla
SDL_RenderCopy(renderer, canvas, nullptr, &playArea);
SDL_RenderCopy(renderer, canvas, nullptr, &param->game.playArea.rect);
// Dibuja el marcador
scoreboard->render();
@@ -1997,12 +1999,6 @@ void Game::render()
// Dibuja el separador del marcador de la zona de juego
renderSeparator();
#ifdef DEBUG
// text->write(0, 0, "P1 ALIVE: " + boolToString(players[0]->isAlive()));
// text->write(0, 10, "P2 ALIVE: " + boolToString(players[1]->isAlive()));
// text->write(0, 20, "ALL DEAD: " + boolToString(allPlayersAreWaiting()));
#endif
// Dibuja el fade
fade->render();
@@ -2277,7 +2273,7 @@ void Game::renderMessages()
// GetReady
if ((counter < STAGE_COUNTER) && (!demo.enabled))
{
textNokiaBig2->write((int)getReadyBitmapPath[counter], PLAY_AREA_CENTER_Y - 8, lang->getText(75), -2);
textNokiaBig2->write((int)getReadyBitmapPath[counter], param->game.playArea.centerY - 8, lang->getText(75), -2);
}
// Time Stopped
@@ -2285,7 +2281,7 @@ void Game::renderMessages()
{
if ((timeStoppedCounter > 100) || (timeStoppedCounter % 10 > 4))
{
textNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, lang->getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor);
textNokia2->writeDX(TXT_CENTER, param->game.playArea.centerX, param->game.playArea.firstQuarterY, lang->getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor);
}
if (timeStoppedCounter > 100)
@@ -2323,13 +2319,13 @@ void Game::renderMessages()
if (!gameCompleted)
{ // Escribe el número de fases restantes
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor);
textNokiaBig2->writeDX(TXT_CENTER, param->game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor);
}
else
{ // Escribe el texto de juego completado
text = lang->getText(50);
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor);
textNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang->getText(76), -1, noColor, 1, shdwTxtColor);
textNokiaBig2->writeDX(TXT_CENTER, param->game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor);
textNokia2->writeDX(TXT_CENTER, param->game.playArea.centerX, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang->getText(76), -1, noColor, 1, shdwTxtColor);
}
}
}
@@ -2433,8 +2429,8 @@ void Game::initPaths()
// Letrero de STAGE #
const int firstPart = STAGE_COUNTER / 4; // 50
const int secondPart = firstPart * 3; // 150
const int centerPoint = PLAY_AREA_CENTER_Y - (BLOCK * 2);
const int distance = (PLAY_AREA_BOTTOM) - (PLAY_AREA_CENTER_Y - 16);
const int centerPoint = param->game.playArea.centerY - (BLOCK * 2);
const int distance = (param->game.playArea.rect.h) - (param->game.playArea.centerY - 16);
for (int i = 0; i < STAGE_COUNTER; ++i)
{
@@ -2458,10 +2454,10 @@ void Game::initPaths()
const int size = textNokiaBig2->lenght(lang->getText(75), -2);
const float start1 = PLAY_AREA_LEFT - size;
const float finish1 = PLAY_AREA_CENTER_X - (size / 2);
const float finish1 = param->game.playArea.centerX - (size / 2);
const float start2 = finish1;
const float finish2 = PLAY_AREA_RIGHT;
const float finish2 = param->game.playArea.rect.w;
const float distance1 = finish1 - start1;
const float distance2 = finish2 - start2;