Working on support for various controllers
This commit is contained in:
@@ -33,17 +33,14 @@ 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->input[0] = INPUT_USE_KEYBOARD;
|
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
mInput = new Input(mFileList[53]);
|
mInput = new Input(mFileList[53]);
|
||||||
//mInput2 = new Input(mOptions->input[1]);
|
|
||||||
//mInput[0] = new Input(INPUT_USE_KEYBOARD);
|
|
||||||
//mInput[1] = new Input(INPUT_USE_GAMECONTROLLER);
|
|
||||||
|
|
||||||
// Inicializa SDL
|
// Inicializa SDL
|
||||||
initSDL();
|
initSDL();
|
||||||
@@ -346,8 +343,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->input[0] = INPUT_USE_KEYBOARD;
|
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
mOptions->filter = FILTER_NEAREST;
|
mOptions->filter = FILTER_NEAREST;
|
||||||
mOptions->vSync = true;
|
mOptions->vSync = true;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "fade.h"
|
#include "fade.h"
|
||||||
#include <math.h>
|
//#include <math.h>
|
||||||
|
|
||||||
#ifndef DIRECTOR_H
|
#ifndef DIRECTOR_H
|
||||||
#define DIRECTOR_H
|
#define DIRECTOR_H
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ Game::Game(int numPlayers, SDL_Renderer *renderer, std::string *filelist, Lang *
|
|||||||
mLang = lang;
|
mLang = lang;
|
||||||
mInput = input;
|
mInput = input;
|
||||||
mOptions = options;
|
mOptions = options;
|
||||||
mOnePlayerControl = mOptions->input[0];
|
mOnePlayerControl = mOptions->input[0].deviceType;
|
||||||
|
|
||||||
// Pasa variables
|
// Pasa variables
|
||||||
mDemo.enabled = demo;
|
mDemo.enabled = demo;
|
||||||
mNumPlayers = numPlayers;
|
mNumPlayers = numPlayers;
|
||||||
if (mNumPlayers == 1)
|
if (mNumPlayers == 1)
|
||||||
mOptions->input[0] = INPUT_USE_ANY;
|
mOptions->input[0].deviceType = INPUT_USE_ANY;
|
||||||
mDifficulty = mOptions->difficulty;
|
mDifficulty = mOptions->difficulty;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
@@ -93,7 +93,7 @@ Game::~Game()
|
|||||||
saveScoreFile();
|
saveScoreFile();
|
||||||
saveDemoFile();
|
saveDemoFile();
|
||||||
|
|
||||||
mOptions->input[0] = mOnePlayerControl;
|
mOptions->input[0].deviceType = mOnePlayerControl;
|
||||||
|
|
||||||
mRenderer = nullptr;
|
mRenderer = nullptr;
|
||||||
mFileList = nullptr;
|
mFileList = nullptr;
|
||||||
@@ -2861,7 +2861,7 @@ void Game::checkGameInput()
|
|||||||
if (mPlayer[i]->isAlive())
|
if (mPlayer[i]->isAlive())
|
||||||
{
|
{
|
||||||
// Input a la izquierda
|
// Input a la izquierda
|
||||||
if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i]))
|
if (mInput->checkInput(INPUT_LEFT, REPEAT_TRUE, mOptions->input[i].deviceType))
|
||||||
{
|
{
|
||||||
mPlayer[i]->setInput(INPUT_LEFT);
|
mPlayer[i]->setInput(INPUT_LEFT);
|
||||||
mDemo.keys.left = 1;
|
mDemo.keys.left = 1;
|
||||||
@@ -2869,7 +2869,7 @@ void Game::checkGameInput()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Input a la derecha
|
// Input a la derecha
|
||||||
if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i]))
|
if (mInput->checkInput(INPUT_RIGHT, REPEAT_TRUE, mOptions->input[i].deviceType))
|
||||||
{
|
{
|
||||||
mPlayer[i]->setInput(INPUT_RIGHT);
|
mPlayer[i]->setInput(INPUT_RIGHT);
|
||||||
mDemo.keys.right = 1;
|
mDemo.keys.right = 1;
|
||||||
@@ -2882,7 +2882,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Comprueba el input de disparar al centro
|
// Comprueba el input de disparar al centro
|
||||||
if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i]))
|
if (mInput->checkInput(INPUT_BUTTON_2, REPEAT_TRUE, mOptions->input[i].deviceType))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->canFire())
|
if (mPlayer[i]->canFire())
|
||||||
{
|
{
|
||||||
@@ -2898,7 +2898,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de disparar a la izquierda
|
// Comprueba el input de disparar a la izquierda
|
||||||
if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i]))
|
if (mInput->checkInput(INPUT_BUTTON_1, REPEAT_TRUE, mOptions->input[i].deviceType))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->canFire())
|
if (mPlayer[i]->canFire())
|
||||||
{
|
{
|
||||||
@@ -2914,7 +2914,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de disparar a la derecha
|
// Comprueba el input de disparar a la derecha
|
||||||
if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i]))
|
if (mInput->checkInput(INPUT_BUTTON_3, REPEAT_TRUE, mOptions->input[i].deviceType))
|
||||||
{
|
{
|
||||||
if (mPlayer[i]->canFire())
|
if (mPlayer[i]->canFire())
|
||||||
{
|
{
|
||||||
@@ -2930,7 +2930,7 @@ void Game::checkGameInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el input de pausa
|
// Comprueba el input de pausa
|
||||||
if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i]))
|
if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE, mOptions->input[i].deviceType))
|
||||||
{
|
{
|
||||||
mSection.subsection = GAME_SECTION_PAUSE;
|
mSection.subsection = GAME_SECTION_PAUSE;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
//#include <stdio.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
// Contestar cuantos joystics ha detectado
|
||||||
|
// Preguntarlepor los joystics que ha encontrado para ir poniendolos en la variable de opciones
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(std::string file)
|
Input::Input(std::string file)
|
||||||
{
|
{
|
||||||
@@ -24,9 +28,6 @@ Input::Input(std::string file)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Input::~Input()
|
Input::~Input()
|
||||||
{
|
{
|
||||||
//SDL_GameControllerClose(mGameController);
|
|
||||||
//if (mGameController)
|
|
||||||
//mGameController = nullptr;
|
|
||||||
for (int i = 0; i < mNumGamepads; i++)
|
for (int i = 0; i < mNumGamepads; i++)
|
||||||
mConnectedControllers[i] = nullptr;
|
mConnectedControllers[i] = nullptr;
|
||||||
}
|
}
|
||||||
@@ -49,6 +50,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
bool successKeyboard = false;
|
bool successKeyboard = false;
|
||||||
bool successGameController = false;
|
bool successGameController = false;
|
||||||
|
|
||||||
|
if (device == INPUT_USE_ANY)
|
||||||
|
index = 0;
|
||||||
|
|
||||||
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
if ((device == INPUT_USE_KEYBOARD) || (device == INPUT_USE_ANY))
|
||||||
{
|
{
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
const Uint8 *mKeystates = SDL_GetKeyboardState(NULL);
|
||||||
|
|||||||
@@ -138,8 +138,8 @@ void Title::init(bool demo, Uint8 subsection)
|
|||||||
|
|
||||||
if (!mInput->gameControllerFound())
|
if (!mInput->gameControllerFound())
|
||||||
{
|
{
|
||||||
mOptions->input[0] = INPUT_USE_KEYBOARD;
|
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el bitmap de Coffee
|
// Inicializa el bitmap de Coffee
|
||||||
@@ -349,7 +349,7 @@ void Title::updateMenuLabels()
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 1 CONTROLS - OPTIONS
|
// PLAYER 1 CONTROLS - OPTIONS
|
||||||
switch (mOptions->input[0])
|
switch (mOptions->input[0].deviceType)
|
||||||
{
|
{
|
||||||
case INPUT_USE_KEYBOARD:
|
case INPUT_USE_KEYBOARD:
|
||||||
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
||||||
@@ -378,7 +378,7 @@ void Title::updateMenuLabels()
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
// PLAYER 2 CONTROLS - OPTIONS
|
// PLAYER 2 CONTROLS - OPTIONS
|
||||||
switch (mOptions->input[1])
|
switch (mOptions->input[1].deviceType)
|
||||||
{
|
{
|
||||||
case INPUT_USE_KEYBOARD:
|
case INPUT_USE_KEYBOARD:
|
||||||
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
mMenu.options->setItemCaption(i, mLang->getText(69)); // KEYBOARD
|
||||||
@@ -911,14 +911,14 @@ void Title::runDemoGame()
|
|||||||
void Title::switchInputs(int value)
|
void Title::switchInputs(int value)
|
||||||
{
|
{
|
||||||
Uint8 temp;
|
Uint8 temp;
|
||||||
temp = mOptions->input[0];
|
temp = mOptions->input[0].deviceType;
|
||||||
mOptions->input[0] = mOptions->input[1];
|
mOptions->input[0].deviceType = mOptions->input[1].deviceType;
|
||||||
mOptions->input[1] = temp;
|
mOptions->input[1].deviceType = temp;
|
||||||
|
|
||||||
if (!mInput->gameControllerFound())
|
if (!mInput->gameControllerFound())
|
||||||
{
|
{
|
||||||
mOptions->input[0] = INPUT_USE_KEYBOARD;
|
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
|
||||||
mOptions->input[1] = INPUT_USE_GAMECONTROLLER;
|
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
#include "ifdefs.h"
|
||||||
#include "ltexture.h"
|
#include "ltexture.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
@@ -39,11 +40,19 @@ struct demoKeys_t
|
|||||||
Uint8 fireRight;
|
Uint8 fireRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Estructura para albergar métodos de control
|
||||||
|
struct input_t
|
||||||
|
{
|
||||||
|
int id; // Identificador en el vector de mandos
|
||||||
|
std::string name; // Nombre del dispositivo
|
||||||
|
Uint8 deviceType; // Tipo de dispositivo (teclado o mando)
|
||||||
|
};
|
||||||
|
|
||||||
// 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 input[2]; // Modo de control (teclado o mando)
|
input_t input[2]; // Modo de control (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
|
||||||
|
|||||||
Reference in New Issue
Block a user