Un altre punteret a pendre per cul: options
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
#include "game.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
|
||||
#define GAME_OVER_COUNTER 350
|
||||
|
||||
// Constructor
|
||||
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
this->music = music;
|
||||
renderer = screen->getRenderer();
|
||||
@@ -19,12 +19,12 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
this->demo.enabled = demo;
|
||||
this->currentStage = currentStage;
|
||||
lastStageReached = currentStage;
|
||||
difficulty = options->game.difficulty;
|
||||
difficulty = options.game.difficulty;
|
||||
|
||||
// Crea los objetos
|
||||
fade = new Fade(renderer);
|
||||
eventHandler = new SDL_Event();
|
||||
scoreboard = new Scoreboard(renderer, asset, options);
|
||||
scoreboard = new Scoreboard(renderer, asset);
|
||||
background = new Background(renderer, asset);
|
||||
explosions = new Explosions();
|
||||
enemyFormations = new EnemyFormations();
|
||||
@@ -62,7 +62,7 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
Game::~Game()
|
||||
{
|
||||
// Guarda las puntuaciones en un fichero
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
manager->saveToFile(asset->get("score.bin"));
|
||||
delete manager;
|
||||
#ifdef RECORDING
|
||||
@@ -171,8 +171,8 @@ void Game::init(int playerID)
|
||||
scoreboard->setMode(SCOREBOARD_CENTER_PANEL, SCOREBOARD_MODE_STAGE_INFO);
|
||||
|
||||
// Resto de variables
|
||||
hiScore.score = options->game.hiScoreTable[0].score;
|
||||
hiScore.name = options->game.hiScoreTable[0].name;
|
||||
hiScore.score = options.game.hiScoreTable[0].score;
|
||||
hiScore.name = options.game.hiScoreTable[0].name;
|
||||
paused = false;
|
||||
gameCompleted = false;
|
||||
gameCompletedCounter = 0;
|
||||
@@ -328,7 +328,7 @@ void Game::init(int playerID)
|
||||
// Carga los recursos necesarios para la sección 'Game'
|
||||
void Game::loadMedia()
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << std::endl
|
||||
<< "** LOADING RESOURCES FOR GAME SECTION" << std::endl;
|
||||
@@ -521,7 +521,7 @@ void Game::loadMedia()
|
||||
stageChangeSound = JA_LoadSound(asset->get("stage_change.wav").c_str());
|
||||
coffeeMachineSound = JA_LoadSound(asset->get("title.wav").c_str());
|
||||
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "** RESOURCES FOR GAME SECTION LOADED" << std::endl
|
||||
<< std::endl;
|
||||
@@ -652,7 +652,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
// El fichero no existe
|
||||
if (file == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
}
|
||||
@@ -663,7 +663,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
// Si no existe el fichero
|
||||
if (file != nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "New file (" << filename.c_str() << ") created!" << std::endl;
|
||||
}
|
||||
@@ -687,7 +687,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
}
|
||||
else
|
||||
{ // Si no puede crear el fichero
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Error: Unable to create file " << filename.c_str() << std::endl;
|
||||
}
|
||||
@@ -698,7 +698,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
else
|
||||
{
|
||||
// Mensaje de proceder a la carga de los datos
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Reading file: " << filename.c_str() << std::endl;
|
||||
}
|
||||
@@ -735,7 +735,7 @@ bool Game::saveDemoFile()
|
||||
SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1);
|
||||
}
|
||||
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Writing file " << filename.c_str() << std::endl;
|
||||
}
|
||||
@@ -745,7 +745,7 @@ bool Game::saveDemoFile()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -2063,10 +2063,10 @@ void Game::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
|
||||
JA_EnableMusic(options->audio.music.enabled);
|
||||
JA_EnableSound(options->audio.sound.enabled);
|
||||
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
|
||||
options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled;
|
||||
JA_EnableMusic(options.audio.music.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
screen->showNotification("Audio " + boolToOnOff(options.audio.music.enabled));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2159,11 +2159,11 @@ void Game::checkInput()
|
||||
for (auto player : players)
|
||||
{
|
||||
const int controllerIndex = player->getController();
|
||||
const bool autofire = player->isPowerUp() || options->game.autofire;
|
||||
const bool autofire = player->isPowerUp() || options.game.autofire;
|
||||
if (player->isPlaying())
|
||||
{
|
||||
// Input a la izquierda
|
||||
if (input->checkInput(input_left, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_left, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_left);
|
||||
#ifdef RECORDING
|
||||
@@ -2173,7 +2173,7 @@ void Game::checkInput()
|
||||
else
|
||||
{
|
||||
// Input a la derecha
|
||||
if (input->checkInput(input_right, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_right, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_right);
|
||||
#ifdef RECORDING
|
||||
@@ -2190,7 +2190,7 @@ void Game::checkInput()
|
||||
}
|
||||
}
|
||||
// Comprueba el input de disparar al centro
|
||||
if (input->checkInput(input_fire_center, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_fire_center, autofire, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2207,7 +2207,7 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la izquierda
|
||||
else if (input->checkInput(input_fire_left, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
else if (input->checkInput(input_fire_left, autofire, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2224,7 +2224,7 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la derecha
|
||||
else if (input->checkInput(input_fire_right, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
else if (input->checkInput(input_fire_right, autofire, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2252,7 +2252,7 @@ void Game::checkInput()
|
||||
else
|
||||
{
|
||||
// Si no está jugando, el botón de start le permite continuar jugando
|
||||
if (input->checkInput(input_start, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_start, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
// Si no ha entrado ya en el estado de game over, entonces se puede continuar
|
||||
if (gameOverCounter == GAME_OVER_COUNTER)
|
||||
@@ -2262,9 +2262,9 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Si está continuando, los botones de fuego hacen decrementar el contador
|
||||
const bool fire1 = input->checkInput(input_fire_left, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
||||
const bool fire2 = input->checkInput(input_fire_center, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
||||
const bool fire3 = input->checkInput(input_fire_right, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
||||
const bool fire1 = input->checkInput(input_fire_left, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||
const bool fire2 = input->checkInput(input_fire_center, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||
const bool fire3 = input->checkInput(input_fire_right, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||
if (fire1 || fire2 || fire3)
|
||||
{
|
||||
player->decContinueCounter();
|
||||
@@ -2391,7 +2391,7 @@ void Game::run()
|
||||
// Vuelve a dejar el sonido como estaba
|
||||
if (demo.enabled)
|
||||
{
|
||||
JA_EnableSound(options->audio.sound.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2648,7 +2648,7 @@ void Game::loadAnimations(std::string filePath, std::vector<std::string> *buffer
|
||||
|
||||
if (file)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
|
||||
}
|
||||
@@ -2752,7 +2752,7 @@ void Game::pause(bool value)
|
||||
void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
{
|
||||
const hiScoreEntry_t entry = {name, score};
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
manager->add(entry);
|
||||
delete manager;
|
||||
}
|
||||
@@ -2805,9 +2805,9 @@ Player *Game::getPlayer(int id)
|
||||
// Obtiene un controlador a partir del "id" del jugador
|
||||
int Game::getController(int playerId)
|
||||
{
|
||||
for (int i = 0; i < (int)options->controller.size(); ++i)
|
||||
for (int i = 0; i < (int)options.controller.size(); ++i)
|
||||
{
|
||||
if (options->controller[i].playerId == playerId)
|
||||
if (options.controller[i].playerId == playerId)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user