Convertit "param" a variable global en lloc de anar marejant amb punterets i passant 8.000.000 de paràmetres
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
#include "game.h"
|
||||
#include "param.h"
|
||||
|
||||
#define GAME_OVER_COUNTER 350
|
||||
|
||||
// Constructor
|
||||
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, param_t *param, section_t *section, JA_Music_t *music)
|
||||
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->param = param;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
this->music = music;
|
||||
@@ -22,12 +22,12 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
difficulty = options->game.difficulty;
|
||||
|
||||
// Crea los objetos
|
||||
fade = new Fade(renderer, param);
|
||||
fade = new Fade(renderer);
|
||||
eventHandler = new SDL_Event();
|
||||
scoreboard = new Scoreboard(renderer, asset, options);
|
||||
background = new Background(renderer, asset, param);
|
||||
background = new Background(renderer, asset);
|
||||
explosions = new Explosions();
|
||||
enemyFormations = new EnemyFormations(param);
|
||||
enemyFormations = new EnemyFormations();
|
||||
|
||||
// Carga los recursos
|
||||
loadMedia();
|
||||
@@ -41,7 +41,7 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]);
|
||||
}
|
||||
|
||||
background->setPos(param->game.playArea.rect);
|
||||
background->setPos(param.game.playArea.rect);
|
||||
|
||||
n1000Sprite = new SmartSprite(gameTextTexture);
|
||||
n2500Sprite = new SmartSprite(gameTextTexture);
|
||||
@@ -52,7 +52,7 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
explosions->addTexture(3, explosionsTextures[2], explosionsAnimations[2]);
|
||||
explosions->addTexture(4, explosionsTextures[3], explosionsAnimations[3]);
|
||||
|
||||
canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->game.playArea.rect.w, param->game.playArea.rect.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'
|
||||
@@ -107,14 +107,14 @@ void Game::init(int playerID)
|
||||
players.clear();
|
||||
|
||||
// Crea los dos jugadores
|
||||
Player *player1 = new Player(1, (param->game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[0], playerAnimations);
|
||||
Player *player1 = new Player(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[0], playerAnimations);
|
||||
player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL);
|
||||
player1->setName(lang::getText(53));
|
||||
const int controller1 = getController(player1->getId());
|
||||
player1->setController(controller1);
|
||||
players.push_back(player1);
|
||||
|
||||
Player *player2 = new Player(2, (param->game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param->game.playArea.rect.h - 30, ¶m->game.playArea.rect, playerTextures[1], playerAnimations);
|
||||
Player *player2 = new Player(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, ¶m.game.playArea.rect, playerTextures[1], playerAnimations);
|
||||
player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL);
|
||||
player2->setName(lang::getText(54));
|
||||
const int controller2 = getController(player2->getId());
|
||||
@@ -159,7 +159,7 @@ void Game::init(int playerID)
|
||||
}
|
||||
|
||||
// Variables para el marcador
|
||||
scoreboard->setPos({param->scoreboard.x, param->scoreboard.y, param->scoreboard.w, param->scoreboard.h});
|
||||
scoreboard->setPos({param.scoreboard.x, param.scoreboard.y, param.scoreboard.w, param.scoreboard.h});
|
||||
for (auto player : players)
|
||||
{
|
||||
scoreboard->setName(player->getScoreBoardPanel(), player->getName());
|
||||
@@ -269,7 +269,7 @@ void Game::init(int playerID)
|
||||
|
||||
// Inicializa el objeto para el fundido
|
||||
fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b);
|
||||
fade->setPost(param->fade.postDuration);
|
||||
fade->setPost(param.fade.postDuration);
|
||||
fade->setType(FADE_VENETIAN);
|
||||
|
||||
// Con los globos creados, calcula el nivel de amenaza
|
||||
@@ -977,7 +977,7 @@ void Game::renderBalloons()
|
||||
int Game::createBalloon(float x, int y, int kind, float velx, float speed, int creationtimer)
|
||||
{
|
||||
const int index = (kind - 1) % 4;
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index], param);
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index]);
|
||||
balloons.push_back(b);
|
||||
return (int)(balloons.size() - 1);
|
||||
}
|
||||
@@ -989,8 +989,8 @@ void Game::createPowerBall()
|
||||
const int posY = -BLOCK;
|
||||
|
||||
const int left = PLAY_AREA_LEFT;
|
||||
const int center = param->game.playArea.centerX - (BALLOON_WIDTH_4 / 2);
|
||||
const int right = param->game.playArea.rect.w - 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;
|
||||
@@ -999,7 +999,7 @@ void Game::createPowerBall()
|
||||
const int x[values] = {left, left, center, center, right, right};
|
||||
const float vx[values] = {vpos, vpos, vpos, vneg, vneg, vneg};
|
||||
|
||||
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 300, balloonTextures[4], balloonAnimations[4], param);
|
||||
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 300, balloonTextures[4], balloonAnimations[4]);
|
||||
balloons.push_back(b);
|
||||
|
||||
powerBallEnabled = true;
|
||||
@@ -1480,7 +1480,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, &(param->game.playArea.rect), bulletTexture);
|
||||
Bullet *b = new Bullet(x, y, kind, poweredUp, owner, &(param.game.playArea.rect), bulletTexture);
|
||||
bullets.push_back(b);
|
||||
}
|
||||
|
||||
@@ -1605,7 +1605,7 @@ int Game::dropItem()
|
||||
// Crea un objeto item
|
||||
void Game::createItem(int kind, float x, float y)
|
||||
{
|
||||
Item *item = new Item(kind, x, y, &(param->game.playArea.rect), 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);
|
||||
}
|
||||
|
||||
@@ -1665,17 +1665,17 @@ void Game::throwCoffee(int x, int y)
|
||||
|
||||
ss->setPosX(x - 8);
|
||||
ss->setPosY(y - 8);
|
||||
ss->setWidth(param->game.itemSize);
|
||||
ss->setHeight(param->game.itemSize);
|
||||
ss->setWidth(param.game.itemSize);
|
||||
ss->setHeight(param.game.itemSize);
|
||||
ss->setVelX(-1.0f + ((rand() % 5) * 0.5f));
|
||||
ss->setVelY(-4.0f);
|
||||
ss->setAccelX(0.0f);
|
||||
ss->setAccelY(0.2f);
|
||||
ss->setDestX(x + (ss->getVelX() * 50));
|
||||
ss->setDestY(param->game.height + 1);
|
||||
ss->setDestY(param.game.height + 1);
|
||||
ss->setEnabled(true);
|
||||
ss->setEnabledCounter(1);
|
||||
ss->setSpriteClip(0, param->game.itemSize, param->game.itemSize, param->game.itemSize);
|
||||
ss->setSpriteClip(0, param.game.itemSize, param.game.itemSize, param.game.itemSize);
|
||||
ss->setRotate(true);
|
||||
ss->setRotateSpeed(10);
|
||||
ss->setRotateAmount(90.0);
|
||||
@@ -1995,7 +1995,7 @@ void Game::render()
|
||||
screen->start();
|
||||
|
||||
// Copia la textura con la zona de juego a la pantalla
|
||||
SDL_RenderCopy(renderer, canvas, nullptr, ¶m->game.playArea.rect);
|
||||
SDL_RenderCopy(renderer, canvas, nullptr, ¶m.game.playArea.rect);
|
||||
|
||||
// Dibuja el marcador
|
||||
scoreboard->render();
|
||||
@@ -2283,7 +2283,7 @@ void Game::renderMessages()
|
||||
// GetReady
|
||||
if ((counter < STAGE_COUNTER) && (!demo.enabled))
|
||||
{
|
||||
textNokiaBig2->write((int)getReadyBitmapPath[counter], param->game.playArea.centerY - 8, lang::getText(75), -2);
|
||||
textNokiaBig2->write((int)getReadyBitmapPath[counter], param.game.playArea.centerY - 8, lang::getText(75), -2);
|
||||
}
|
||||
|
||||
// Time Stopped
|
||||
@@ -2291,7 +2291,7 @@ void Game::renderMessages()
|
||||
{
|
||||
if ((timeStoppedCounter > 100) || (timeStoppedCounter % 10 > 4))
|
||||
{
|
||||
textNokia2->writeDX(TXT_CENTER, param->game.playArea.centerX, param->game.playArea.firstQuarterY, 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)
|
||||
@@ -2329,13 +2329,13 @@ void Game::renderMessages()
|
||||
|
||||
if (!gameCompleted)
|
||||
{ // Escribe el número de fases restantes
|
||||
textNokiaBig2->writeDX(TXT_CENTER, param->game.playArea.centerX, 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, 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2439,8 +2439,8 @@ void Game::initPaths()
|
||||
// Letrero de STAGE #
|
||||
const int firstPart = STAGE_COUNTER / 4; // 50
|
||||
const int secondPart = firstPart * 3; // 150
|
||||
const int centerPoint = param->game.playArea.centerY - (BLOCK * 2);
|
||||
const int distance = (param->game.playArea.rect.h) - (param->game.playArea.centerY - 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)
|
||||
{
|
||||
@@ -2464,10 +2464,10 @@ void Game::initPaths()
|
||||
const int size = textNokiaBig2->lenght(lang::getText(75), -2);
|
||||
|
||||
const float start1 = PLAY_AREA_LEFT - size;
|
||||
const float finish1 = param->game.playArea.centerX - (size / 2);
|
||||
const float finish1 = param.game.playArea.centerX - (size / 2);
|
||||
|
||||
const float start2 = finish1;
|
||||
const float finish2 = param->game.playArea.rect.w;
|
||||
const float finish2 = param.game.playArea.rect.w;
|
||||
|
||||
const float distance1 = finish1 - start1;
|
||||
const float distance2 = finish2 - start2;
|
||||
@@ -2600,7 +2600,7 @@ void Game::checkEvents()
|
||||
{
|
||||
// CREA UN SPRITE DE 1000 PUNTOS
|
||||
case SDLK_h:
|
||||
createItemScoreSprite(param->game.width / 2, param->game.width / 2, n1000Sprite);
|
||||
createItemScoreSprite(param.game.width / 2, param.game.width / 2, n1000Sprite);
|
||||
break;
|
||||
|
||||
// CREA UNA POWERBALL
|
||||
|
||||
Reference in New Issue
Block a user