Controllers are working
Still needs some tweaks and some gui changes. Also stumbled upon a bug.
This commit is contained in:
parent
3143236908
commit
06d2da164a
15
src/input.c
15
src/input.c
|
@ -105,7 +105,7 @@ get_event_button(SDL_Event *event)
|
||||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
|
||||||
key = KEY_RIGHT; break;
|
key = KEY_RIGHT; break;
|
||||||
case SDL_CONTROLLER_BUTTON_A:
|
case SDL_CONTROLLER_BUTTON_A:
|
||||||
key = KEY_NUM1 & KEY_ENTER; break;
|
key = KEY_NUM1 | KEY_ENTER; break;
|
||||||
case SDL_CONTROLLER_BUTTON_X:
|
case SDL_CONTROLLER_BUTTON_X:
|
||||||
key = KEY_NUM2; break;
|
key = KEY_NUM2; break;
|
||||||
case SDL_CONTROLLER_BUTTON_Y:
|
case SDL_CONTROLLER_BUTTON_Y:
|
||||||
|
@ -115,7 +115,11 @@ get_event_button(SDL_Event *event)
|
||||||
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
|
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
|
||||||
key = KEY_NUM5; break;
|
key = KEY_NUM5; break;
|
||||||
case SDL_CONTROLLER_BUTTON_START:
|
case SDL_CONTROLLER_BUTTON_START:
|
||||||
|
key = KEY_ENTER; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_BACK:
|
||||||
key = KEY_ESC; break;
|
key = KEY_ESC; break;
|
||||||
|
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
|
||||||
|
key = KEY_SPACE; break;
|
||||||
default:
|
default:
|
||||||
key = 0; break;
|
key = 0; break;
|
||||||
}
|
}
|
||||||
|
@ -128,8 +132,6 @@ get_axis_motion(SDL_Event *event)
|
||||||
Uint64 key;
|
Uint64 key;
|
||||||
int angle = event->caxis.value;
|
int angle = event->caxis.value;
|
||||||
switch (event->caxis.axis) {
|
switch (event->caxis.axis) {
|
||||||
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
|
|
||||||
key = KEY_SPACE; break;
|
|
||||||
case SDL_CONTROLLER_AXIS_LEFTX:
|
case SDL_CONTROLLER_AXIS_LEFTX:
|
||||||
key = angle < 0 ? KEY_LEFT : KEY_RIGHT; break;
|
key = angle < 0 ? KEY_LEFT : KEY_RIGHT; break;
|
||||||
case SDL_CONTROLLER_AXIS_LEFTY:
|
case SDL_CONTROLLER_AXIS_LEFTY:
|
||||||
|
@ -140,6 +142,11 @@ get_axis_motion(SDL_Event *event)
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Uint32
|
||||||
|
get_button_modkey(SDL_Event *event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static Uint32
|
static Uint32
|
||||||
get_event_modkey(SDL_Event *event)
|
get_event_modkey(SDL_Event *event)
|
||||||
{
|
{
|
||||||
|
@ -221,7 +228,7 @@ input_handle_event(Input *input, SDL_Event *event)
|
||||||
input->keyState &= ~get_event_button(event);
|
input->keyState &= ~get_event_button(event);
|
||||||
}
|
}
|
||||||
else if (event->type == SDL_CONTROLLERAXISMOTION) {
|
else if (event->type == SDL_CONTROLLERAXISMOTION) {
|
||||||
if (event->caxis.value > 8000 || event->caxis.value < -8000)
|
if (event->caxis.value > 32000 || event->caxis.value < -32000)
|
||||||
input->keyState |= get_axis_motion(event);
|
input->keyState |= get_axis_motion(event);
|
||||||
else
|
else
|
||||||
input->keyState &= ~get_axis_motion(event);
|
input->keyState &= ~get_axis_motion(event);
|
||||||
|
|
11
src/main.c
11
src/main.c
|
@ -87,9 +87,9 @@ static char *skills_tooltip[] = {
|
||||||
" Skills are listed in the bar below the game screen.", "",
|
" Skills are listed in the bar below the game screen.", "",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
" SKILL INFO: ", "SHIFT", " + <N>", "",
|
" SKILL INFO: SHIFT + <N>", "",
|
||||||
" Where <N> is the button corresponding to the skill",
|
" Where <N> is the number corresponding to the skill", "",
|
||||||
" Eg. ", "1", "2", "3", "4", "5", "",
|
" Eg. 1, 2, 3, 4, 5", "",
|
||||||
"",
|
"",
|
||||||
" DISABLE TOOLTIPS: CTRL + D", "",
|
" DISABLE TOOLTIPS: CTRL + D", "",
|
||||||
"",
|
"",
|
||||||
|
@ -102,6 +102,7 @@ static char *how_to_play_tooltip[] = {
|
||||||
"HOW TO PLAY", "",
|
"HOW TO PLAY", "",
|
||||||
"",
|
"",
|
||||||
" NAVIGATION: Use ARROWS or WASD or HJKL to move", "",
|
" NAVIGATION: Use ARROWS or WASD or HJKL to move", "",
|
||||||
|
" Controller: RIGHT STICK or D-PAD", "",
|
||||||
"",
|
"",
|
||||||
" ATTACK: Walk into a monster to attack it", "",
|
" ATTACK: Walk into a monster to attack it", "",
|
||||||
"",
|
"",
|
||||||
|
@ -184,7 +185,7 @@ bool initSDL(void)
|
||||||
{
|
{
|
||||||
int imgFlags = IMG_INIT_PNG;
|
int imgFlags = IMG_INIT_PNG;
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER) < 0)
|
||||||
{
|
{
|
||||||
error("Could not initiate SDL2: %s", SDL_GetError());
|
error("Could not initiate SDL2: %s", SDL_GetError());
|
||||||
return false;
|
return false;
|
||||||
|
@ -216,7 +217,7 @@ bool initSDL(void)
|
||||||
|
|
||||||
gController = SDL_GameControllerOpen(i);
|
gController = SDL_GameControllerOpen(i);
|
||||||
if (gController) {
|
if (gController) {
|
||||||
info("Game controller connected");
|
info("Game controller connected: %s", SDL_GameControllerName(gController));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -659,7 +659,7 @@ skill_charge(Skill *skill, SkillData *data)
|
||||||
Position lastAvailableDest = playerStartPos;
|
Position lastAvailableDest = playerStartPos;
|
||||||
while (position_in_roommatrix(&destination))
|
while (position_in_roommatrix(&destination))
|
||||||
{
|
{
|
||||||
if (space->occupied) {
|
if (space->occupied || space->monster) {
|
||||||
if (!space->monster || passThroughCount >= chargeThroughLvl)
|
if (!space->monster || passThroughCount >= chargeThroughLvl)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
|
|
@ -43,6 +43,7 @@ create_controller_button_sprite(Position pos, SDL_Rect clip)
|
||||||
Sprite *s = sprite_create();
|
Sprite *s = sprite_create();
|
||||||
sprite_set_texture(s, t, 0);
|
sprite_set_texture(s, t, 0);
|
||||||
s->pos = pos;
|
s->pos = pos;
|
||||||
|
s->fixed = true;
|
||||||
s->clip = clip;
|
s->clip = clip;
|
||||||
s->dim = DIM(16, 16);
|
s->dim = DIM(16, 16);
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in New Issue