Ya se pueden definir los botones para cada jugador. Falta guardarlos en el fichero de configuración
This commit is contained in:
@@ -256,7 +256,7 @@ void AnimatedSprite::animate()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el numero de frames de la animación actual
|
||||
// Obtiene el número de frames de la animación actual
|
||||
int AnimatedSprite::getNumFrames()
|
||||
{
|
||||
return (int)animation[currentAnimation].frames.size();
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Obtiene el numero de frames de la animación actual
|
||||
// Obtiene el número de frames de la animación actual
|
||||
int getNumFrames();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
|
||||
@@ -246,12 +246,15 @@ bool Input::discoverGameController()
|
||||
}
|
||||
}
|
||||
|
||||
const int nJoysticks = SDL_NumJoysticks();
|
||||
numJoysticks = SDL_NumJoysticks();
|
||||
numGamepads = 0;
|
||||
|
||||
// Cuenta el numero de mandos
|
||||
for (int i = 0; i < nJoysticks; ++i)
|
||||
// Cuenta el número de mandos
|
||||
joysticks.clear();
|
||||
for (int i = 0; i < numJoysticks; ++i)
|
||||
{
|
||||
SDL_Joystick *joy = SDL_JoystickOpen(i);
|
||||
joysticks.push_back(joy);
|
||||
if (SDL_IsGameController(i))
|
||||
{
|
||||
numGamepads++;
|
||||
@@ -261,7 +264,7 @@ bool Input::discoverGameController()
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "\nChecking for game controllers...\n";
|
||||
std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
||||
std::cout << numJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
||||
}
|
||||
|
||||
if (numGamepads > 0)
|
||||
@@ -326,7 +329,7 @@ std::string Input::getControllerName(int index)
|
||||
}
|
||||
}
|
||||
|
||||
// Obten el numero de mandos conectados
|
||||
// Obten el número de mandos conectados
|
||||
int Input::getNumControllers()
|
||||
{
|
||||
return numGamepads;
|
||||
@@ -351,3 +354,12 @@ void Input::enable()
|
||||
enabled = true;
|
||||
disabledUntil = d_notDisabled;
|
||||
}
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
int Input::getJoyIndex(int id)
|
||||
{
|
||||
for (int i = 0; i < numJoysticks; ++i)
|
||||
if (SDL_JoystickInstanceID(joysticks[i]) == id)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
@@ -76,12 +76,14 @@ private:
|
||||
|
||||
// Variables
|
||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||
std::vector<SDL_Joystick *> joysticks; // Vector con todos los joysticks conectados
|
||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
||||
std::vector<inputs_e> gameInputs; // Inputs usados para jugar, normalmente direcciones y botones
|
||||
std::vector<inputs_e> buttonInputs; // Inputs asignados al jugador y a botones, excluyendo direcciones
|
||||
int numGamepads; // Numero de mandos conectados
|
||||
int numJoysticks; // Número de joysticks conectados
|
||||
int numGamepads; // Número de mandos conectados
|
||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||
bool verbose; // Indica si ha de mostrar mensajes
|
||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
||||
@@ -115,7 +117,7 @@ public:
|
||||
// Comprueba si hay algun mando conectado
|
||||
bool gameControllerFound();
|
||||
|
||||
// Obten el numero de mandos conectados
|
||||
// Obten el número de mandos conectados
|
||||
int getNumControllers();
|
||||
|
||||
// Obten el nombre de un mando de juego
|
||||
@@ -129,6 +131,9 @@ public:
|
||||
|
||||
// Hablita las entradas
|
||||
void enable();
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
int getJoyIndex(int id);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
bool resizing; // Indica si el selector está cambiando de tamaño
|
||||
float y; // Coordenada actual, usado para el desplazamiento
|
||||
float h; // Altura actual, usado para el cambio de tamaño
|
||||
int numJumps; // Numero de pasos preestablecido para llegar al destino
|
||||
int numJumps; // Número de pasos preestablecido para llegar al destino
|
||||
int index; // Elemento del menu que tiene el foco
|
||||
int previousIndex; // Elemento que tenia el foco previamente
|
||||
color_t previousItemColor; // Color del item nque tenia el foco previamente
|
||||
|
||||
@@ -40,10 +40,15 @@ DefineButtons::DefineButtons(SDL_Renderer *renderer, Input *input, Text *text, p
|
||||
button.button = SDL_CONTROLLER_BUTTON_START;
|
||||
buttons.push_back(button);
|
||||
|
||||
button.label = "QUIT";
|
||||
button.label = "SALIR DEL JUEGO";
|
||||
button.input = input_exit;
|
||||
button.button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
buttons.push_back(button);
|
||||
|
||||
for (int i = 0; i < input->getNumControllers(); ++i)
|
||||
{
|
||||
controllerNames.push_back(input->getControllerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -64,16 +69,21 @@ void DefineButtons::render()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
text->writeCentered(x, y - 10, "PLAYER " + std::to_string(indexController + 1));
|
||||
text->writeCentered(x, y - 20, "PLAYER " + std::to_string(indexController + 1));
|
||||
text->writeCentered(x, y - 10, controllerNames[indexController]);
|
||||
text->writeCentered(x, y, buttons[indexButton].label);
|
||||
}
|
||||
}
|
||||
|
||||
int getJoyIndex(int id);
|
||||
|
||||
void DefineButtons::doJoystickButtonDown(SDL_JoyButtonEvent *event)
|
||||
{
|
||||
//int i = getJoyIndex(event->which);
|
||||
int i = input->getJoyIndex(event->which);
|
||||
|
||||
// Solo pillamos botones del mando que toca
|
||||
if (i != indexController)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buttons[indexButton].button = (SDL_GameControllerButton)event->button;
|
||||
incIndexButton();
|
||||
@@ -91,57 +101,6 @@ void DefineButtons::checkInput()
|
||||
{
|
||||
if (event.type == SDL_JOYBUTTONDOWN)
|
||||
doJoystickButtonDown(&event.jbutton);
|
||||
|
||||
/*if (eventHandler->type == SDL_JOYBUTTONDOWN)
|
||||
{
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_A)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_A;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_B)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_B;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_X)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_X;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_Y)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_Y;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_BACK)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_BACK;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_START)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_START;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_LEFTSHOULDER)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
|
||||
incIndexButton();
|
||||
}
|
||||
|
||||
if (eventHandler->jbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
|
||||
{
|
||||
buttons[indexButton].button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
|
||||
incIndexButton();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ private:
|
||||
std::vector<db_button_t> buttons; // Vector con las nuevas definiciones de botones/acciones
|
||||
int indexController; // Indice del controlador a reasignar
|
||||
int indexButton; // Indice para saber qué bot´çon se está definiendo
|
||||
std::vector<std::string> controllerNames; // Nombres de los mandos
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void incIndexButton();
|
||||
|
||||
@@ -1988,7 +1988,7 @@ void Game::startAllBalloons()
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el numero de globos activos
|
||||
// Obtiene el número de globos activos
|
||||
Uint8 Game::countBalloons()
|
||||
{
|
||||
Uint8 num = 0;
|
||||
@@ -2977,7 +2977,7 @@ void Game::renderMessages()
|
||||
}
|
||||
|
||||
if (!gameCompleted)
|
||||
{ // Escribe el numero de fases restantes
|
||||
{ // Escribe el número de fases restantes
|
||||
textNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -81,7 +81,7 @@ private:
|
||||
Uint16 powerToComplete; // Cantidad de poder que se necesita para completar la fase
|
||||
Uint8 maxMenace; // Umbral máximo de amenaza de la fase
|
||||
Uint8 minMenace; // Umbral mínimo de amenaza de la fase
|
||||
Uint8 number; // Numero de fase
|
||||
Uint8 number; // Número de fase
|
||||
};
|
||||
|
||||
struct helper_t
|
||||
@@ -185,7 +185,7 @@ private:
|
||||
float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
|
||||
Uint16 deathCounter; // Contador para la animación de muerte del jugador
|
||||
Uint8 menaceCurrent; // Nivel de amenaza actual
|
||||
Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
|
||||
Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
|
||||
bool timeStopped; // Indica si el tiempo está detenido
|
||||
Uint16 timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
|
||||
Uint32 counter; // Contador para el juego
|
||||
@@ -208,7 +208,7 @@ private:
|
||||
param_t *param; // Puntero con todos los parametros del programa
|
||||
enemyFormation_t enemyFormation[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas
|
||||
enemyPool_t enemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
|
||||
Uint8 lastStageReached; // Contiene el numero de la última pantalla que se ha alcanzado
|
||||
Uint8 lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
demo_t demo; // Variable con todas las variables relacionadas con el modo demo
|
||||
int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases
|
||||
bool paused; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
|
||||
@@ -316,7 +316,7 @@ private:
|
||||
// Pone en marcha todos los globos
|
||||
void startAllBalloons();
|
||||
|
||||
// Obtiene el numero de globos activos
|
||||
// Obtiene el número de globos activos
|
||||
Uint8 countBalloons();
|
||||
|
||||
// Vacia el vector de globos
|
||||
|
||||
@@ -26,7 +26,7 @@ objetos bala. Se encarga de comprobar las entradas de teclado o gamepad para
|
||||
cerrar la aplicacion, saltar al estado de pausa y para mover al jugador. Recorre
|
||||
el vector de globos y de balas y si tienen algun tipo asignado las gestiona.
|
||||
Comprueba las colisiones entre los globos y el jugador y entre las balas y los
|
||||
globos. Tiene ademas un nivel de amenaza que calcula en funcion del numero de globos
|
||||
globos. Tiene ademas un nivel de amenaza que calcula en funcion del número de globos
|
||||
en pantalla y que se va incrementando conforme aumenta la puntuación del jugador.
|
||||
|
||||
Los objetos globo tienen varios contadores para alternar de un estado a otro.
|
||||
|
||||
@@ -544,7 +544,7 @@ void Player::disableInput()
|
||||
input = false;
|
||||
}
|
||||
|
||||
// Devuelve el numero de cafes actuales
|
||||
// Devuelve el número de cafes actuales
|
||||
Uint8 Player::getCoffees()
|
||||
{
|
||||
return coffees;
|
||||
|
||||
@@ -202,7 +202,7 @@ public:
|
||||
// Deshabilita la entrada de ordenes
|
||||
void disableInput();
|
||||
|
||||
// Devuelve el numero de cafes actuales
|
||||
// Devuelve el número de cafes actuales
|
||||
Uint8 getCoffees();
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
|
||||
// Variables
|
||||
struct options_t *options; // Variable con todas las variables de las opciones del programa
|
||||
int stage; // Numero de fase actual
|
||||
int stage; // Número de fase actual
|
||||
int score1; // Puntuación del jugador 1
|
||||
int score2; // Puntuación del jugador 2
|
||||
float mult1; // Multiplicador del jugador 1
|
||||
|
||||
Reference in New Issue
Block a user