Dual input for P1 done
This commit is contained in:
@@ -33,15 +33,15 @@ Director::Director(std::string path)
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||
mOptions->player1Input = INPUT_USE_KEYBOARD;
|
||||
mOptions->player2Input = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->input[0] = INPUT_USE_KEYBOARD;
|
||||
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->filter = FILTER_NEAREST;
|
||||
mOptions->vSync = true;
|
||||
}
|
||||
|
||||
// Crea los objetos
|
||||
mInput1 = new Input(mOptions->player1Input);
|
||||
mInput2 = new Input(mOptions->player2Input);
|
||||
mInput = new Input();
|
||||
//mInput2 = new Input(mOptions->input[1]);
|
||||
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
||||
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
||||
|
||||
@@ -71,11 +71,8 @@ Director::~Director()
|
||||
{
|
||||
saveConfigFile();
|
||||
|
||||
delete mInput1;
|
||||
mInput1 = nullptr;
|
||||
|
||||
delete mInput2;
|
||||
mInput2 = nullptr;
|
||||
delete mInput;
|
||||
mInput = nullptr;
|
||||
|
||||
delete mLang;
|
||||
mLang = nullptr;
|
||||
@@ -101,36 +98,36 @@ void Director::init(Uint8 name)
|
||||
// Textos
|
||||
mLang->setLang(mOptions->language);
|
||||
|
||||
// Teclado
|
||||
mInput1->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||
mInput1->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||
mInput1->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||
mInput1->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||
mInput1->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||
mInput1->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
// Controles
|
||||
mInput->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||
mInput->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||
mInput->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||
mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||
mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN);
|
||||
mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE);
|
||||
#ifdef __MIPSEL__
|
||||
mInput1->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
|
||||
mInput1->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
|
||||
mInput1->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
|
||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_LSHIFT);
|
||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_SPACE);
|
||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_LCTRL);
|
||||
#else
|
||||
mInput1->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||
mInput1->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||
mInput1->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||
mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Q);
|
||||
mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_W);
|
||||
mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_E);
|
||||
#endif
|
||||
mInput1->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||
mInput1->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||
mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); // PAUSE
|
||||
mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); // ESCAPE
|
||||
|
||||
mInput2->bindGameController(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
mInput2->bindGameController(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||
mInput2->bindGameController(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||
mInput2->bindGameController(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
mInput2->bindGameController(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_A);
|
||||
mInput2->bindGameController(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_B);
|
||||
mInput2->bindGameController(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
||||
mInput2->bindGameController(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
||||
mInput2->bindGameController(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
||||
mInput2->bindGameController(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
||||
mInput2->bindGameController(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
||||
mInput->bindGameController(INPUT_UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
mInput->bindGameController(INPUT_DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||
mInput->bindGameController(INPUT_LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||||
mInput->bindGameController(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
mInput->bindGameController(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B);
|
||||
mInput->bindGameController(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A);
|
||||
mInput->bindGameController(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X);
|
||||
mInput->bindGameController(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y);
|
||||
mInput->bindGameController(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B);
|
||||
mInput->bindGameController(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); // PAUSE
|
||||
mInput->bindGameController(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); // ESCAPE
|
||||
}
|
||||
|
||||
// Inicializa JailAudio
|
||||
@@ -421,8 +418,8 @@ bool Director::loadConfigFile()
|
||||
mOptions->windowSize = 3;
|
||||
mOptions->language = en_UK;
|
||||
mOptions->difficulty = DIFFICULTY_NORMAL;
|
||||
mOptions->player1Input = INPUT_USE_KEYBOARD;
|
||||
mOptions->player2Input = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->input[0] = INPUT_USE_KEYBOARD;
|
||||
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
||||
mOptions->filter = FILTER_NEAREST;
|
||||
mOptions->vSync = true;
|
||||
|
||||
@@ -449,8 +446,8 @@ bool Director::loadConfigFile()
|
||||
SDL_RWwrite(file, &mOptions->windowSize, sizeof(mOptions->windowSize), 1);
|
||||
SDL_RWwrite(file, &mOptions->language, sizeof(mOptions->language), 1);
|
||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||
SDL_RWwrite(file, &mOptions->player1Input, sizeof(mOptions->player1Input), 1);
|
||||
SDL_RWwrite(file, &mOptions->player2Input, sizeof(mOptions->player2Input), 1);
|
||||
SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 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->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->language, sizeof(mOptions->language), 1);
|
||||
SDL_RWread(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||
SDL_RWread(file, &mOptions->player1Input, sizeof(mOptions->player1Input), 1);
|
||||
SDL_RWread(file, &mOptions->player2Input, sizeof(mOptions->player2Input), 1);
|
||||
SDL_RWread(file, &mOptions->input[0], sizeof(mOptions->input[0]), 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->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->language, sizeof(mOptions->language), 1);
|
||||
SDL_RWwrite(file, &mOptions->difficulty, sizeof(mOptions->difficulty), 1);
|
||||
SDL_RWwrite(file, &mOptions->player1Input, sizeof(mOptions->player1Input), 1);
|
||||
SDL_RWwrite(file, &mOptions->player2Input, sizeof(mOptions->player2Input), 1);
|
||||
SDL_RWwrite(file, &mOptions->input[0], sizeof(mOptions->input[0]), 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->vSync, sizeof(mOptions->vSync), 1);
|
||||
|
||||
@@ -570,7 +567,7 @@ void Director::runIntro()
|
||||
|
||||
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));
|
||||
delete mTitle;
|
||||
}
|
||||
@@ -578,9 +575,9 @@ void Director::runTitle()
|
||||
void Director::runGame()
|
||||
{
|
||||
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)
|
||||
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());
|
||||
delete mGame;
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ private:
|
||||
Intro *mIntro; // Objeto para la sección de la intro
|
||||
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
|
||||
Game *mGame; // Objeto para la sección del juego
|
||||
Input *mInput1; // Objeto Input para gestionar las entradas
|
||||
Input *mInput2; // Objeto Input para gestionar las entradas
|
||||
Input *mInput; // Objeto Input para gestionar las entradas
|
||||
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
|
||||
|
||||
@@ -5,19 +5,22 @@
|
||||
#endif
|
||||
|
||||
// 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
|
||||
mRenderer = renderer;
|
||||
mFileList = filelist;
|
||||
mLang = lang;
|
||||
mInput[0] = input1;
|
||||
mInput[1] = input2;
|
||||
mInput = input;
|
||||
mOptions = options;
|
||||
mOnePlayerControl = mOptions->input[0];
|
||||
|
||||
// Pasa variables
|
||||
mDemo.enabled = demo;
|
||||
mNumPlayers = numPlayers;
|
||||
mDifficulty = difficulty;
|
||||
if (mNumPlayers == 1)
|
||||
mOptions->input[0] = INPUT_USE_ANY;
|
||||
mDifficulty = mOptions->difficulty;
|
||||
|
||||
// Crea los objetos
|
||||
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);
|
||||
mTextBig = new Text(mFileList[47], mTextureTextBig, mRenderer);
|
||||
|
||||
mMenuGameOver = new Menu(mRenderer, mText, mInput[0], mFileList);
|
||||
mMenuPause = new Menu(mRenderer, mText, mInput[0], mFileList);
|
||||
mMenuGameOver = new Menu(mRenderer, mText, mInput, mFileList);
|
||||
mMenuPause = new Menu(mRenderer, mText, mInput, mFileList);
|
||||
|
||||
mFade = new Fade(mRenderer);
|
||||
mEventHandler = new SDL_Event();
|
||||
@@ -90,11 +93,12 @@ Game::~Game()
|
||||
saveScoreFile();
|
||||
saveDemoFile();
|
||||
|
||||
mOptions->input[0] = mOnePlayerControl;
|
||||
|
||||
mRenderer = nullptr;
|
||||
mFileList = nullptr;
|
||||
mLang = nullptr;
|
||||
mInput[0] = nullptr;
|
||||
mInput[1] = nullptr;
|
||||
mInput = nullptr;
|
||||
|
||||
for (int i = 0; i < mNumPlayers; i++)
|
||||
{
|
||||
@@ -315,10 +319,6 @@ void Game::init()
|
||||
mMenaceThreshold = 0;
|
||||
mHiScoreAchieved = false;
|
||||
mCurrentStage = 0;
|
||||
|
||||
// BORRAR
|
||||
mCurrentStage = 9;
|
||||
|
||||
mStageBitmapCounter = STAGE_COUNTER;
|
||||
mDeathCounter = DEATH_COUNTER;
|
||||
mExplosionTime = false;
|
||||
@@ -370,9 +370,6 @@ void Game::init()
|
||||
initEnemyPools();
|
||||
initGameStages();
|
||||
|
||||
// BORRAR
|
||||
mStage[mCurrentStage].currentPower = mStage[mCurrentStage].powerToComplete - 10;
|
||||
|
||||
// Modo debug
|
||||
mDebug.enabled = false;
|
||||
mDebug.enemySet = 0;
|
||||
@@ -1704,7 +1701,7 @@ void Game::updateStage()
|
||||
{
|
||||
// Cambio de fase
|
||||
mCurrentStage++;
|
||||
if (mCurrentStage == 10)
|
||||
if (mCurrentStage == 10) // Ha llegado al final el juego
|
||||
{
|
||||
mGameCompleted = true; // Marca el juego como completado
|
||||
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
|
||||
if (mPlayer[i]->isAlive())
|
||||
mPlayer[i]->addScore(1000000);
|
||||
updateHiScore();
|
||||
JA_StopMusic();
|
||||
}
|
||||
JA_PlaySound(mSoundStageChange);
|
||||
@@ -2844,7 +2842,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// Incrementa el contador de la demo
|
||||
@@ -2859,7 +2857,7 @@ void Game::checkGameInput()
|
||||
if (mPlayer[i]->isAlive())
|
||||
{
|
||||
// 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);
|
||||
mDemo.keys.left = 1;
|
||||
@@ -2867,7 +2865,7 @@ void Game::checkGameInput()
|
||||
else
|
||||
{
|
||||
// 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);
|
||||
mDemo.keys.right = 1;
|
||||
@@ -2880,7 +2878,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
}
|
||||
// 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())
|
||||
{
|
||||
@@ -2896,7 +2894,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
@@ -2912,7 +2910,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
@@ -2928,7 +2926,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
|
||||
int mNumPlayers; // Numero de jugadores
|
||||
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
|
||||
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
|
||||
Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
|
||||
//Uint32 mScore; // Puntuación actual
|
||||
Uint32 mHiScore; // Puntuación máxima
|
||||
bool mHiScoreAchieved; // Indica si se ha superado la puntuación máxima
|
||||
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
|
||||
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 mDifficulty; // Dificultad del juego
|
||||
Uint8 mDifficulty; // Dificultad del juego
|
||||
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
|
||||
{
|
||||
@@ -213,7 +214,7 @@ private:
|
||||
|
||||
public:
|
||||
// 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
|
||||
~Game();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Input::Input(int source)
|
||||
Input::Input()
|
||||
{
|
||||
// Inicializa las variables
|
||||
for (int i = 0; i < 17; i++)
|
||||
@@ -15,21 +15,7 @@ Input::Input(int source)
|
||||
mGameControllerBindings[i].active = false;
|
||||
}
|
||||
|
||||
mSource = source;
|
||||
|
||||
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));
|
||||
discoverGameController();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -50,18 +36,21 @@ void Input::bindGameController(Uint8 input, SDL_GameControllerButton button)
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||
return true;
|
||||
successKeyboard = true;
|
||||
else
|
||||
return false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -70,11 +59,11 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
||||
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||
{
|
||||
mKeyBindings[input].active = true;
|
||||
return true;
|
||||
successKeyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -82,23 +71,24 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
||||
if (mKeystates[mKeyBindings[input].scancode] == 0)
|
||||
{
|
||||
mKeyBindings[input].active = false;
|
||||
return false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Utiliza mando
|
||||
|
||||
if ((device == INPUT_USE_GAMECONTROLLER) || (device == INPUT_USE_ANY))
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
||||
return true;
|
||||
successGameController = true;
|
||||
else
|
||||
return false;
|
||||
successGameController = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,11 +97,11 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) != 0)
|
||||
{
|
||||
mGameControllerBindings[input].active = true;
|
||||
return true;
|
||||
successGameController = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
successGameController = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -119,15 +109,17 @@ bool Input::checkInput(Uint8 input, bool repeat)
|
||||
if (SDL_GameControllerGetButton(mGameController, mGameControllerBindings[input].button) == 0)
|
||||
{
|
||||
mGameControllerBindings[input].active = false;
|
||||
return false;
|
||||
successGameController = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
successGameController = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (successKeyboard || successGameController);
|
||||
}
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
@@ -168,9 +160,3 @@ bool Input::discoverGameController()
|
||||
|
||||
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_GAMECONTROLLER 1
|
||||
#define INPUT_USE_ANY 2
|
||||
|
||||
// Clase Input
|
||||
class Input
|
||||
@@ -52,14 +53,12 @@ private:
|
||||
std::vector<SDL_GameController*> mConnectedControllers;
|
||||
int mNumGamepads;
|
||||
|
||||
int mSource; // Indica si el objeto usará un mando o un teclado
|
||||
|
||||
// Comprueba si hay un mando conectado
|
||||
bool discoverGameController();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Input(int source);
|
||||
Input();
|
||||
|
||||
// Destructor
|
||||
~Input();
|
||||
@@ -71,10 +70,7 @@ public:
|
||||
void bindGameController(Uint8 input, SDL_GameControllerButton button);
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool checkInput(Uint8 input, bool repeat);
|
||||
|
||||
// Establece el método de entrada
|
||||
void setSource(Uint8 value);
|
||||
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -343,7 +343,7 @@ void Title::updateMenuLabels()
|
||||
|
||||
i++;
|
||||
// PLAYER 1 CONTROLS - OPTIONS
|
||||
switch (mOptions->player1Input)
|
||||
switch (mOptions->input[0])
|
||||
{
|
||||
case INPUT_USE_KEYBOARD:
|
||||
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
||||
@@ -364,7 +364,7 @@ void Title::updateMenuLabels()
|
||||
|
||||
i++;
|
||||
// PLAYER 2 CONTROLS - OPTIONS
|
||||
switch (mOptions->player2Input)
|
||||
switch (mOptions->input[1])
|
||||
{
|
||||
case INPUT_USE_KEYBOARD:
|
||||
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
||||
@@ -733,11 +733,11 @@ section_t Title::run(Uint8 subsection)
|
||||
updateMenuLabels();
|
||||
break;
|
||||
case 1: // PLAYER 1 CONTROLS
|
||||
SwitchInputs(1);
|
||||
switchInputs(1);
|
||||
updateMenuLabels();
|
||||
break;
|
||||
case 3: // PLAYER 2 CONTROLS
|
||||
SwitchInputs(2);
|
||||
switchInputs(2);
|
||||
updateMenuLabels();
|
||||
break;
|
||||
case 5: // Language
|
||||
@@ -880,18 +880,18 @@ void Title::runInstructions(Uint8 mode)
|
||||
// Ejecuta el juego en modo demo
|
||||
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();
|
||||
delete mDemoGame;
|
||||
}
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
void Title::SwitchInputs(int value)
|
||||
void Title::switchInputs(int value)
|
||||
{
|
||||
Uint8 temp;
|
||||
temp = mOptions->player1Input;
|
||||
mOptions->player1Input = mOptions->player2Input;
|
||||
mOptions->player2Input = temp;
|
||||
temp = mOptions->input[0];
|
||||
mOptions->input[0] = mOptions->input[1];
|
||||
mOptions->input[1] = temp;
|
||||
}
|
||||
|
||||
// Crea el mosaico de fondo del titulo
|
||||
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
void runDemoGame();
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
void SwitchInputs(int value);
|
||||
void switchInputs(int value);
|
||||
|
||||
// Crea el mosaico de fondo del titulo
|
||||
void createTiledBackground();
|
||||
|
||||
@@ -43,8 +43,7 @@ struct demoKeys_t
|
||||
struct options_t
|
||||
{
|
||||
Uint8 difficulty; // Dificultad del juego
|
||||
Uint8 player1Input; // Modo de control para el jugador 1 (teclado o mando)
|
||||
Uint8 player2Input; // Modo de control para el jugador 2 (teclado o mando)
|
||||
Uint8 input[2]; // Modo de control (teclado o mando)
|
||||
Uint8 language; // Idioma usado en el juego
|
||||
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
|
||||
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
|
||||
|
||||
Reference in New Issue
Block a user