Dual input for P1 done
This commit is contained in:
@@ -33,15 +33,15 @@ Director::Director(std::string path)
|
|||||||
mOptions->windowSize = 3;
|
mOptions->windowSize = 3;
|
||||||
mOptions->language = en_UK;
|
mOptions->language = en_UK;
|
||||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||||
mOptions->player1Input = INPUT_USE_KEYBOARD;
|
mOptions->input[0] = INPUT_USE_KEYBOARD;
|
||||||
mOptions->player2Input = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
mInput1 = new Input(mOptions->player1Input);
|
mInput = new Input();
|
||||||
mInput2 = new Input(mOptions->player2Input);
|
//mInput2 = new Input(mOptions->input[1]);
|
||||||
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
||||||
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
||||||
|
|
||||||
@@ -71,11 +71,8 @@ Director::~Director()
|
|||||||
{
|
{
|
||||||
saveConfigFile();
|
saveConfigFile();
|
||||||
|
|
||||||
delete mInput1;
|
delete mInput;
|
||||||
mInput1 = nullptr;
|
mInput = nullptr;
|
||||||
|
|
||||||
delete mInput2;
|
|
||||||
mInput2 = nullptr;
|
|
||||||
|
|
||||||
delete mLang;
|
delete mLang;
|
||||||
mLang = nullptr;
|
mLang = nullptr;
|
||||||
@@ -101,36 +98,36 @@ void Director::init(Uint8 name)
|
|||||||
// Textos
|
// Textos
|
||||||
mLang->setLang(mOptions->language);
|
mLang->setLang(mOptions->language);
|
||||||
|
|
||||||
// Teclado
|
// Controles
|
||||||
mInput1->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
mInput->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||||
mInput1->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
mInput->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||||
mInput1->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
mInput->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||||
mInput1->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||||
mInput1->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||||
mInput1->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||||
#ifdef __MIPSEL__
|
#ifdef __MIPSEL__
|
||||||
mInput1->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
|
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
|
||||||
mInput1->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
|
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
|
||||||
mInput1->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
|
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
|
||||||
#else
|
#else
|
||||||
mInput1->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||||
mInput1->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||||
mInput1->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||||
#endif
|
#endif
|
||||||
mInput1->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||||
mInput1->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||||
|
|
||||||
mInput2->bindGameController(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
mInput->bindGameController(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||||
mInput2->bindGameController(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
mInput->bindGameController(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||||
mInput2->bindGameController(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
mInput->bindGameController(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||||
mInput2->bindGameController(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
mInput->bindGameController(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||||
mInput2->bindGameController(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_A);
|
mInput->bindGameController(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
|
||||||
mInput2->bindGameController(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_B);
|
mInput->bindGameController(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
|
||||||
mInput2->bindGameController(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
mInput->bindGameController(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
||||||
mInput2->bindGameController(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
mInput->bindGameController(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
||||||
mInput2->bindGameController(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
mInput->bindGameController(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
||||||
mInput2->bindGameController(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
mInput->bindGameController(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
||||||
mInput2->bindGameController(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
mInput->bindGameController(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa JailAudio
|
// Inicializa JailAudio
|
||||||
@@ -421,8 +418,8 @@ bool Director::loadConfigFile()
|
|||||||
mOptions->windowSize = 3;
|
mOptions->windowSize = 3;
|
||||||
mOptions->language = en_UK;
|
mOptions->language = en_UK;
|
||||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||||
mOptions->player1Input = INPUT_USE_KEYBOARD;
|
mOptions->input[0] = INPUT_USE_KEYBOARD;
|
||||||
mOptions->player2Input = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
|
|
||||||
@@ -449,8 +446,8 @@ bool Director::loadConfigFile()
|
|||||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||||
SDL_RWwrite(file, &mOptions->player1Input, sizeof(mOptions->player1Input), 1);
|
SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1);
|
||||||
SDL_RWwrite(file, &mOptions->player2Input, sizeof(mOptions->player2Input), 1);
|
SDL_RWwrite(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
|
||||||
@@ -472,8 +469,8 @@ bool Director::loadConfigFile()
|
|||||||
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
SDL_RWread(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||||
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
|
SDL_RWread(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||||
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||||
SDL_RWread(file, &mOptions->player1Input, sizeof(mOptions->player1Input), 1);
|
SDL_RWread(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1);
|
||||||
SDL_RWread(file, &mOptions->player2Input, sizeof(mOptions->player2Input), 1);
|
SDL_RWread(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1);
|
||||||
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
|
||||||
@@ -513,8 +510,8 @@ bool Director::saveConfigFile()
|
|||||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||||
SDL_RWwrite(file, &mOptions->player1Input, sizeof(mOptions->player1Input), 1);
|
SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 1);
|
||||||
SDL_RWwrite(file, &mOptions->player2Input, sizeof(mOptions->player2Input), 1);
|
SDL_RWwrite(file, &mOptions->input[1], sizeof(mOptions->input[1]), 1);
|
||||||
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
|
||||||
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
|
||||||
|
|
||||||
@@ -570,7 +567,7 @@ void Director::runIntro()
|
|||||||
|
|
||||||
void Director::runTitle()
|
void Director::runTitle()
|
||||||
{
|
{
|
||||||
mTitle = new Title(mWindow, mRenderer, mInput1, mFileList, mOptions, mLang);
|
mTitle = new Title(mWindow, mRenderer, mInput, mFileList, mOptions, mLang);
|
||||||
setSection(mTitle->run(mSection.subsection));
|
setSection(mTitle->run(mSection.subsection));
|
||||||
delete mTitle;
|
delete mTitle;
|
||||||
}
|
}
|
||||||
@@ -578,9 +575,9 @@ void Director::runTitle()
|
|||||||
void Director::runGame()
|
void Director::runGame()
|
||||||
{
|
{
|
||||||
if (mSection.subsection == GAME_SECTION_PLAY_1P)
|
if (mSection.subsection == GAME_SECTION_PLAY_1P)
|
||||||
mGame = new Game(1, mRenderer, mFileList, mLang, mInput1, mInput2, false, mOptions->difficulty);
|
mGame = new Game(1, mRenderer, mFileList, mLang, mInput, false, mOptions);
|
||||||
if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
if (mSection.subsection == GAME_SECTION_PLAY_2P)
|
||||||
mGame = new Game(2, mRenderer, mFileList, mLang, mInput1, mInput2, false, mOptions->difficulty);
|
mGame = new Game(2, mRenderer, mFileList, mLang, mInput, false, mOptions);
|
||||||
setSection(mGame->run());
|
setSection(mGame->run());
|
||||||
delete mGame;
|
delete mGame;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ private:
|
|||||||
Intro *mIntro; // Objeto para la sección de la intro
|
Intro *mIntro; // Objeto para la sección de la intro
|
||||||
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
||||||
Game *mGame; // Objeto para la sección del juego
|
Game *mGame; // Objeto para la sección del juego
|
||||||
Input *mInput1; // Objeto Input para gestionar las entradas
|
Input *mInput; // Objeto Input para gestionar las entradas
|
||||||
Input *mInput2; // Objeto Input para gestionar las entradas
|
|
||||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
|
|
||||||
std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos
|
std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos
|
||||||
|
|||||||
@@ -5,19 +5,22 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input1, Input *input2, bool demo, int difficulty)
|
Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
mRenderer = renderer;
|
mRenderer = renderer;
|
||||||
mFileList = filelist;
|
mFileList = filelist;
|
||||||
mLang = lang;
|
mLang = lang;
|
||||||
mInput[0] = input1;
|
mInput = input;
|
||||||
mInput[1] = input2;
|
mOptions = options;
|
||||||
|
mOnePlayerControl = mOptions->input[0];
|
||||||
|
|
||||||
// Pasa variables
|
// Pasa variables
|
||||||
mDemo.enabled = demo;
|
mDemo.enabled = demo;
|
||||||
mNumPlayers = numPlayers;
|
mNumPlayers = numPlayers;
|
||||||
mDifficulty = difficulty;
|
if (mNumPlayers == 1)
|
||||||
|
mOptions->input[0] = INPUT_USE_ANY;
|
||||||
|
mDifficulty = mOptions->difficulty;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
for (int i = 0; i < mNumPlayers; i++)
|
||||||
@@ -52,8 +55,8 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *
|
|||||||
mTextScoreBoard = new Text(mFileList[46], mTextureTextScoreBoard, mRenderer);
|
mTextScoreBoard = new Text(mFileList[46], mTextureTextScoreBoard, mRenderer);
|
||||||
mTextBig = new Text(mFileList[47], mTextureTextBig, mRenderer);
|
mTextBig = new Text(mFileList[47], mTextureTextBig, mRenderer);
|
||||||
|
|
||||||
mMenuGameOver = new Menu(mRenderer, mText, mInput[0], mFileList);
|
mMenuGameOver = new Menu(mRenderer, mText, mInput, mFileList);
|
||||||
mMenuPause = new Menu(mRenderer, mText, mInput[0], mFileList);
|
mMenuPause = new Menu(mRenderer, mText, mInput, mFileList);
|
||||||
|
|
||||||
mFade = new Fade(mRenderer);
|
mFade = new Fade(mRenderer);
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
@@ -90,11 +93,12 @@ Game::~Game()
|
|||||||
saveScoreFile();
|
saveScoreFile();
|
||||||
saveDemoFile();
|
saveDemoFile();
|
||||||
|
|
||||||
|
mOptions->input[0] = mOnePlayerControl;
|
||||||
|
|
||||||
mRenderer = nullptr;
|
mRenderer = nullptr;
|
||||||
mFileList = nullptr;
|
mFileList = nullptr;
|
||||||
mLang = nullptr;
|
mLang = nullptr;
|
||||||
mInput[0] = nullptr;
|
mInput = nullptr;
|
||||||
mInput[1] = nullptr;
|
|
||||||
|
|
||||||
for (int i = 0; i < mNumPlayers; i++)
|
for (int i = 0; i < mNumPlayers; i++)
|
||||||
{
|
{
|
||||||
@@ -315,10 +319,6 @@ void Game::init()
|
|||||||
mMenaceThreshold = 0;
|
mMenaceThreshold = 0;
|
||||||
mHiScoreAchieved = false;
|
mHiScoreAchieved = false;
|
||||||
mCurrentStage = 0;
|
mCurrentStage = 0;
|
||||||
|
|
||||||
// BORRAR
|
|
||||||
mCurrentStage = 9;
|
|
||||||
|
|
||||||
mStageBitmapCounter = STAGE_COUNTER;
|
mStageBitmapCounter = STAGE_COUNTER;
|
||||||
mDeathCounter = DEATH_COUNTER;
|
mDeathCounter = DEATH_COUNTER;
|
||||||
mExplosionTime = false;
|
mExplosionTime = false;
|
||||||
@@ -370,9 +370,6 @@ void Game::init()
|
|||||||
initEnemyPools();
|
initEnemyPools();
|
||||||
initGameStages();
|
initGameStages();
|
||||||
|
|
||||||
// BORRAR
|
|
||||||
mStage[mCurrentStage].currentPower = mStage[mCurrentStage].powerToComplete - 10;
|
|
||||||
|
|
||||||
// Modo debug
|
// Modo debug
|
||||||
mDebug.enabled = false;
|
mDebug.enabled = false;
|
||||||
mDebug.enemySet = 0;
|
mDebug.enemySet = 0;
|
||||||
@@ -1704,7 +1701,7 @@ void Game::updateStage()
|
|||||||
{
|
{
|
||||||
// Cambio de fase
|
// Cambio de fase
|
||||||
mCurrentStage++;
|
mCurrentStage++;
|
||||||
if (mCurrentStage == 10)
|
if (mCurrentStage == 10) // Ha llegado al final el juego
|
||||||
{
|
{
|
||||||
mGameCompleted = true; // Marca el juego como completado
|
mGameCompleted = true; // Marca el juego como completado
|
||||||
mCurrentStage = 9; // Deja el valor dentro de los limites
|
mCurrentStage = 9; // Deja el valor dentro de los limites
|
||||||
@@ -1715,6 +1712,7 @@ void Game::updateStage()
|
|||||||
for (int i = 0; i < mNumPlayers; i++) // Añade un millon de puntos a los jugadores que queden vivos
|
for (int i = 0; i < mNumPlayers; i++) // Añade un millon de puntos a los jugadores que queden vivos
|
||||||
if (mPlayer[i]->isAlive())
|
if (mPlayer[i]->isAlive())
|
||||||
mPlayer[i]->addScore(1000000);
|
mPlayer[i]->addScore(1000000);
|
||||||
|
updateHiScore();
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
}
|
}
|
||||||
JA_PlaySound(mSoundStageChange);
|
JA_PlaySound(mSoundStageChange);
|
||||||
@@ -2844,7 +2842,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de pausa
|
// Comprueba el input de pausa
|
||||||
if (mInput[0]->checkInput(INPUT_BUTTON_PAUSE, REPEAT_FALSE))
|
if (mInput->checkInput(INPUT_BUTTON_PAUSE, REPEAT_FALSE))
|
||||||
mSection.name = PROG_SECTION_TITLE;
|
mSection.name = PROG_SECTION_TITLE;
|
||||||
|
|
||||||
// Incrementa el contador de la demo
|
// Incrementa el contador de la demo
|
||||||
@@ -2859,7 +2857,7 @@ void Game::checkGameInput()
|
|||||||
if (mPlayer[i]->isAlive())
|
if (mPlayer[i]->isAlive())
|
||||||
{
|
{
|
||||||
// Input a la izquierda
|
// Input a la izquierda
|
||||||
if (mInput[i]->checkInput(INPUT_LEFT, REPEAT_TRUE))
|
if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i]))
|
||||||
{
|
{
|
||||||
mPlayer[i]->setInput(INPUT_LEFT);
|
mPlayer[i]->setInput(INPUT_LEFT);
|
||||||
mDemo.keys.left = 1;
|
mDemo.keys.left = 1;
|
||||||
@@ -2867,7 +2865,7 @@ void Game::checkGameInput()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Input a la derecha
|
// Input a la derecha
|
||||||
if (mInput[i]->checkInput(INPUT_RIGHT, REPEAT_TRUE))
|
if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i]))
|
||||||
{
|
{
|
||||||
mPlayer[i]->setInput(INPUT_RIGHT);
|
mPlayer[i]->setInput(INPUT_RIGHT);
|
||||||
mDemo.keys.right = 1;
|
mDemo.keys.right = 1;
|
||||||
@@ -2880,7 +2878,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Comprueba el input de disparar al centro
|
// Comprueba el input de disparar al centro
|
||||||
if (mInput[i]->checkInput(INPUT_BUTTON_2, REPEAT_TRUE))
|
if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i]))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->canFire())
|
if (mPlayer[i]->canFire())
|
||||||
{
|
{
|
||||||
@@ -2896,7 +2894,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de disparar a la izquierda
|
// Comprueba el input de disparar a la izquierda
|
||||||
if (mInput[i]->checkInput(INPUT_BUTTON_1, REPEAT_TRUE))
|
if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i]))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->canFire())
|
if (mPlayer[i]->canFire())
|
||||||
{
|
{
|
||||||
@@ -2912,7 +2910,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de disparar a la derecha
|
// Comprueba el input de disparar a la derecha
|
||||||
if (mInput[i]->checkInput(INPUT_BUTTON_3, REPEAT_TRUE))
|
if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i]))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->canFire())
|
if (mPlayer[i]->canFire())
|
||||||
{
|
{
|
||||||
@@ -2928,7 +2926,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de pausa
|
// Comprueba el input de pausa
|
||||||
if (mInput[i]->checkInput(INPUT_CANCEL, REPEAT_FALSE))
|
if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i]))
|
||||||
{
|
{
|
||||||
mSection.subsection = GAME_SECTION_PAUSE;
|
mSection.subsection = GAME_SECTION_PAUSE;
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ private:
|
|||||||
|
|
||||||
int mNumPlayers; // Numero de jugadores
|
int mNumPlayers; // Numero de jugadores
|
||||||
Player *mPlayer[2]; // Vector con los jugadores jugador
|
Player *mPlayer[2]; // Vector con los jugadores jugador
|
||||||
Input *mInput[2]; // Manejador de entrada, uno por cada jugador
|
Input *mInput; // Manejador de entrada
|
||||||
|
|
||||||
Balloon *mBalloon[MAX_BALLOONS]; // Vector con los objetos globo
|
Balloon *mBalloon[MAX_BALLOONS]; // Vector con los objetos globo
|
||||||
Bullet *mBullet[MAX_BULLETS]; // Vector con los objetos bala
|
Bullet *mBullet[MAX_BULLETS]; // Vector con los objetos bala
|
||||||
@@ -154,7 +154,6 @@ private:
|
|||||||
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
|
||||||
//Uint32 mScore; // Puntuación actual
|
|
||||||
Uint32 mHiScore; // Puntuación máxima
|
Uint32 mHiScore; // Puntuación máxima
|
||||||
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
||||||
section_t mSection; // Seccion actual dentro del juego
|
section_t mSection; // Seccion actual dentro del juego
|
||||||
@@ -189,8 +188,10 @@ private:
|
|||||||
float mSin[360]; // Vector con los valores del seno para 360 grados
|
float mSin[360]; // Vector con los valores del seno para 360 grados
|
||||||
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
bool mGameCompleted; // Indica si se ha completado la partida, llegando al final de la ultima pantalla
|
||||||
int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
int mGameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
|
||||||
int mDifficulty; // Dificultad del juego
|
Uint8 mDifficulty; // Dificultad del juego
|
||||||
float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
float mDifficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||||
|
struct options_t *mOptions; // Variable con todas las variables de las opciones del programa
|
||||||
|
Uint8 mOnePlayerControl; // Variable para almacenar el valor de las opciones
|
||||||
|
|
||||||
struct demo_t
|
struct demo_t
|
||||||
{
|
{
|
||||||
@@ -213,7 +214,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input1, Input *input2, bool demo, int difficulty);
|
Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *lang, Input *input, bool demo, options_t *options);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(int source)
|
Input::Input()
|
||||||
{
|
{
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
for (int i = 0; i < 17; i++)
|
for (int i = 0; i < 17; i++)
|
||||||
@@ -15,21 +15,7 @@ Input::Input(int source)
|
|||||||
mGameControllerBindings[i].active = false;
|
mGameControllerBindings[i].active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSource = source;
|
discoverGameController();
|
||||||
|
|
||||||
if (mSource == INPUT_USE_KEYBOARD)
|
|
||||||
printf("\nInput requested KEYBOARD\n");
|
|
||||||
else
|
|
||||||
printf("\nInput requested GAMECONTROLLER");
|
|
||||||
|
|
||||||
if (mSource == INPUT_USE_GAMECONTROLLER)
|
|
||||||
if (!discoverGameController())
|
|
||||||
mSource = INPUT_USE_KEYBOARD;
|
|
||||||
|
|
||||||
if (mSource == INPUT_USE_KEYBOARD)
|
|
||||||
printf("Input asigned was KEYBOARD\n");
|
|
||||||
else
|
|
||||||
printf("Input asigned was GAMECONTROLLER (%s)\n", SDL_GameControllerNameForIndex(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -50,18 +36,21 @@ void Input::bindGameController(Uint8 input, SDL_GameControllerButton button)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool Input::checkInput(Uint8 input, bool repeat)
|
bool Input::checkInput(Uint8 input, bool repeat, int device)
|
||||||
{
|
{
|
||||||
if (mSource == INPUT_USE_KEYBOARD)
|
bool successKeyboard = false;
|
||||||
|
bool successGameController = false;
|
||||||
|
|
||||||
|
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
||||||
{
|
{
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||||
return true;
|
successKeyboard = true;
|
||||||
else
|
else
|
||||||
return false;
|
successKeyboard = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -70,11 +59,11 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
|||||||
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||||
{
|
{
|
||||||
mKeyBindings[input].active = true;
|
mKeyBindings[input].active = true;
|
||||||
return true;
|
successKeyboard = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
successKeyboard = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -82,23 +71,24 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
|||||||
if (mKeystates[mKeyBindings[input].scancode] == 0)
|
if (mKeystates[mKeyBindings[input].scancode] == 0)
|
||||||
{
|
{
|
||||||
mKeyBindings[input].active = false;
|
mKeyBindings[input].active = false;
|
||||||
return false;
|
successKeyboard = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
successKeyboard = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Utiliza mando
|
|
||||||
|
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||||
{
|
{
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
||||||
return true;
|
successGameController = true;
|
||||||
else
|
else
|
||||||
return false;
|
successGameController = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -107,11 +97,11 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
|||||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
||||||
{
|
{
|
||||||
mGameControllerBindings[input].active = true;
|
mGameControllerBindings[input].active = true;
|
||||||
return true;
|
successGameController = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
successGameController = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -119,15 +109,17 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
|||||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) == 0)
|
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) == 0)
|
||||||
{
|
{
|
||||||
mGameControllerBindings[input].active = false;
|
mGameControllerBindings[input].active = false;
|
||||||
return false;
|
successGameController = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
successGameController = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (successKeyboard || successGameController);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si hay un mando conectado
|
// Comprueba si hay un mando conectado
|
||||||
@@ -167,10 +159,4 @@ bool Input::discoverGameController()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el método de entrada
|
|
||||||
void Input::setSource(Uint8 value)
|
|
||||||
{
|
|
||||||
mSource = value;
|
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#define INPUT_USE_KEYBOARD 0
|
#define INPUT_USE_KEYBOARD 0
|
||||||
#define INPUT_USE_GAMECONTROLLER 1
|
#define INPUT_USE_GAMECONTROLLER 1
|
||||||
|
#define INPUT_USE_ANY 2
|
||||||
|
|
||||||
// Clase Input
|
// Clase Input
|
||||||
class Input
|
class Input
|
||||||
@@ -52,14 +53,12 @@ private:
|
|||||||
std::vector<SDL_GameController*> mConnectedControllers;
|
std::vector<SDL_GameController*> mConnectedControllers;
|
||||||
int mNumGamepads;
|
int mNumGamepads;
|
||||||
|
|
||||||
int mSource; // Indica si el objeto usará un mando o un teclado
|
|
||||||
|
|
||||||
// Comprueba si hay un mando conectado
|
// Comprueba si hay un mando conectado
|
||||||
bool discoverGameController();
|
bool discoverGameController();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Input(int source);
|
Input();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Input();
|
~Input();
|
||||||
@@ -71,10 +70,7 @@ public:
|
|||||||
void bindGameController(Uint8 input, SDL_GameControllerButton button);
|
void bindGameController(Uint8 input, SDL_GameControllerButton button);
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool checkInput(Uint8 input, bool repeat);
|
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY);
|
||||||
|
|
||||||
// Establece el método de entrada
|
|
||||||
void setSource(Uint8 value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ void Title::updateMenuLabels()
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 1 CONTROLS - OPTIONS
|
// PLAYER 1 CONTROLS - OPTIONS
|
||||||
switch (mOptions->player1Input)
|
switch (mOptions->input[0])
|
||||||
{
|
{
|
||||||
case INPUT_USE_KEYBOARD:
|
case INPUT_USE_KEYBOARD:
|
||||||
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
||||||
@@ -364,7 +364,7 @@ void Title::updateMenuLabels()
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 2 CONTROLS - OPTIONS
|
// PLAYER 2 CONTROLS - OPTIONS
|
||||||
switch (mOptions->player2Input)
|
switch (mOptions->input[1])
|
||||||
{
|
{
|
||||||
case INPUT_USE_KEYBOARD:
|
case INPUT_USE_KEYBOARD:
|
||||||
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
||||||
@@ -733,11 +733,11 @@ section_t Title::run(Uint8 subsection)
|
|||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
break;
|
break;
|
||||||
case 1: // PLAYER 1 CONTROLS
|
case 1: // PLAYER 1 CONTROLS
|
||||||
SwitchInputs(1);
|
switchInputs(1);
|
||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
break;
|
break;
|
||||||
case 3: // PLAYER 2 CONTROLS
|
case 3: // PLAYER 2 CONTROLS
|
||||||
SwitchInputs(2);
|
switchInputs(2);
|
||||||
updateMenuLabels();
|
updateMenuLabels();
|
||||||
break;
|
break;
|
||||||
case 5: // Language
|
case 5: // Language
|
||||||
@@ -880,18 +880,18 @@ void Title::runInstructions(Uint8 mode)
|
|||||||
// Ejecuta el juego en modo demo
|
// Ejecuta el juego en modo demo
|
||||||
void Title::runDemoGame()
|
void Title::runDemoGame()
|
||||||
{
|
{
|
||||||
mDemoGame = new Game(1, mRenderer, mFileList, mLang, mInput, mInput, true, DIFFICULTY_NORMAL);
|
mDemoGame = new Game(1, mRenderer, mFileList, mLang, mInput, true, mOptions);
|
||||||
mDemoGame->run();
|
mDemoGame->run();
|
||||||
delete mDemoGame;
|
delete mDemoGame;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica las opciones para los controles de los jugadores
|
// Modifica las opciones para los controles de los jugadores
|
||||||
void Title::SwitchInputs(int value)
|
void Title::switchInputs(int value)
|
||||||
{
|
{
|
||||||
Uint8 temp;
|
Uint8 temp;
|
||||||
temp = mOptions->player1Input;
|
temp = mOptions->input[0];
|
||||||
mOptions->player1Input = mOptions->player2Input;
|
mOptions->input[0] = mOptions->input[1];
|
||||||
mOptions->player2Input = temp;
|
mOptions->input[1] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea el mosaico de fondo del titulo
|
// Crea el mosaico de fondo del titulo
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ private:
|
|||||||
void runDemoGame();
|
void runDemoGame();
|
||||||
|
|
||||||
// Modifica las opciones para los controles de los jugadores
|
// Modifica las opciones para los controles de los jugadores
|
||||||
void SwitchInputs(int value);
|
void switchInputs(int value);
|
||||||
|
|
||||||
// Crea el mosaico de fondo del titulo
|
// Crea el mosaico de fondo del titulo
|
||||||
void createTiledBackground();
|
void createTiledBackground();
|
||||||
|
|||||||
@@ -42,14 +42,13 @@ struct demoKeys_t
|
|||||||
// Estructura con todas las opciones de configuración del programa
|
// Estructura con todas las opciones de configuración del programa
|
||||||
struct options_t
|
struct options_t
|
||||||
{
|
{
|
||||||
Uint8 difficulty; // Dificultad del juego
|
Uint8 difficulty; // Dificultad del juego
|
||||||
Uint8 player1Input; // Modo de control para el jugador 1 (teclado o mando)
|
Uint8 input[2]; // Modo de control (teclado o mando)
|
||||||
Uint8 player2Input; // Modo de control para el jugador 2 (teclado o mando)
|
Uint8 language; // Idioma usado en el juego
|
||||||
Uint8 language; // Idioma usado en el juego
|
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
||||||
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
|
||||||
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
bool vSync; // Indica si se quiere usar vsync o no
|
||||||
bool vSync; // Indica si se quiere usar vsync o no
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
Reference in New Issue
Block a user