Input unit: Generalizados los tipos de input. Ya no son específicos de cada juego
This commit is contained in:
16
main.cpp
16
main.cpp
@@ -93,10 +93,10 @@ int main(int argc, char *argv[])
|
|||||||
Input *input = new Input(asset->get("gamecontrollerdb.txt"));
|
Input *input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||||
input->setVerbose(options->console);
|
input->setVerbose(options->console);
|
||||||
input->discoverGameController();
|
input->discoverGameController();
|
||||||
input->bindKey(input_up, SDL_SCANCODE_UP);
|
input->bindKey(INPUT_UP, SDL_SCANCODE_UP);
|
||||||
input->bindKey(input_down, SDL_SCANCODE_DOWN);
|
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||||
input->bindKey(input_left, SDL_SCANCODE_LEFT);
|
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||||
input->bindKey(input_right, SDL_SCANCODE_RIGHT);
|
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||||
|
|
||||||
// Inicializa el texto
|
// Inicializa el texto
|
||||||
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
|
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
|
||||||
@@ -156,19 +156,19 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
string inputPressed = "";
|
string inputPressed = "";
|
||||||
if (input->checkInput(input_left))
|
if (input->checkInput(INPUT_LEFT))
|
||||||
{
|
{
|
||||||
inputPressed = "LEFT";
|
inputPressed = "LEFT";
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_right))
|
if (input->checkInput(INPUT_RIGHT))
|
||||||
{
|
{
|
||||||
inputPressed = "RIGHT";
|
inputPressed = "RIGHT";
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_up))
|
if (input->checkInput(INPUT_UP))
|
||||||
{
|
{
|
||||||
inputPressed = "UP";
|
inputPressed = "UP";
|
||||||
}
|
}
|
||||||
if (input->checkInput(input_down))
|
if (input->checkInput(INPUT_DOWN))
|
||||||
{
|
{
|
||||||
inputPressed = "DOWN";
|
inputPressed = "DOWN";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ Input::Input(std::string file)
|
|||||||
keyBindings_t kb;
|
keyBindings_t kb;
|
||||||
kb.scancode = 0;
|
kb.scancode = 0;
|
||||||
kb.active = false;
|
kb.active = false;
|
||||||
keyBindings.resize(input_number_of_inputs, kb);
|
keyBindings.resize(INPUT_TOTAL, kb);
|
||||||
|
|
||||||
GameControllerBindings_t gcb;
|
GameControllerBindings_t gcb;
|
||||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||||
gcb.active = false;
|
gcb.active = false;
|
||||||
gameControllerBindings.resize(input_number_of_inputs, gcb);
|
gameControllerBindings.resize(INPUT_TOTAL, gcb);
|
||||||
|
|
||||||
verbose = true;
|
verbose = true;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
|||||||
@@ -7,35 +7,44 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef INPUT_H
|
||||||
#define INPUT_H
|
#define INPUT_H
|
||||||
|
|
||||||
enum inputs_e
|
// Tipos diferentes de eventos de entrada
|
||||||
{
|
#define INPUT_NULL 0
|
||||||
// Inputs obligatorios
|
#define INPUT_UP 1
|
||||||
input_null,
|
#define INPUT_DOWN 2
|
||||||
input_up,
|
#define INPUT_LEFT 3
|
||||||
input_down,
|
#define INPUT_RIGHT 4
|
||||||
input_left,
|
#define INPUT_BUTTON_1 5
|
||||||
input_right,
|
#define INPUT_BUTTON_2 6
|
||||||
input_pause,
|
#define INPUT_BUTTON_3 7
|
||||||
input_exit,
|
#define INPUT_BUTTON_4 8
|
||||||
input_accept,
|
#define INPUT_BUTTON_5 9
|
||||||
input_cancel,
|
#define INPUT_BUTTON_6 10
|
||||||
|
#define INPUT_BUTTON_7 11
|
||||||
|
#define INPUT_BUTTON_8 12
|
||||||
|
#define INPUT_BUTTON_9 13
|
||||||
|
#define INPUT_BUTTON_10 14
|
||||||
|
#define INPUT_BUTTON_11 15
|
||||||
|
#define INPUT_BUTTON_12 16
|
||||||
|
#define INPUT_BUTTON_13 17
|
||||||
|
#define INPUT_BUTTON_14 18
|
||||||
|
#define INPUT_BUTTON_15 19
|
||||||
|
#define INPUT_BUTTON_16 20
|
||||||
|
#define INPUT_BUTTON_17 21
|
||||||
|
#define INPUT_BUTTON_18 22
|
||||||
|
#define INPUT_BUTTON_19 23
|
||||||
|
#define INPUT_BUTTON_20 24
|
||||||
|
#define INPUT_PAUSE 25
|
||||||
|
#define INPUT_EXIT 26
|
||||||
|
#define INPUT_ACCEPT 27
|
||||||
|
#define INPUT_CANCEL 28
|
||||||
|
|
||||||
// Inputs personalizados
|
#define INPUT_TOTAL 29
|
||||||
input_jump,
|
|
||||||
input_window_fullscreen,
|
|
||||||
input_window_inc_size,
|
|
||||||
input_window_dec_size,
|
|
||||||
input_toggle_border,
|
|
||||||
input_switch_music,
|
|
||||||
input_swap_palette,
|
|
||||||
|
|
||||||
// Input obligatorio
|
|
||||||
input_number_of_inputs
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Para saber si el input se puede repetir sin soltarlo
|
||||||
#define REPEAT_TRUE true
|
#define REPEAT_TRUE true
|
||||||
#define REPEAT_FALSE false
|
#define REPEAT_FALSE false
|
||||||
|
|
||||||
|
// Tipo de control asociado
|
||||||
#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
|
#define INPUT_USE_ANY 2
|
||||||
|
|||||||
Reference in New Issue
Block a user