From 06d2da164a61bd612c699bc6850f5cca13959b2d Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 11 Oct 2018 18:54:02 +0200 Subject: [PATCH] Controllers are working Still needs some tweaks and some gui changes. Also stumbled upon a bug. --- src/input.c | 15 +++++++++++---- src/main.c | 11 ++++++----- src/skill.c | 2 +- src/skillbar.c | 1 + 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/input.c b/src/input.c index 0d6992d..1767b65 100644 --- a/src/input.c +++ b/src/input.c @@ -105,7 +105,7 @@ get_event_button(SDL_Event *event) case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: key = KEY_RIGHT; break; case SDL_CONTROLLER_BUTTON_A: - key = KEY_NUM1 & KEY_ENTER; break; + key = KEY_NUM1 | KEY_ENTER; break; case SDL_CONTROLLER_BUTTON_X: key = KEY_NUM2; break; case SDL_CONTROLLER_BUTTON_Y: @@ -115,7 +115,11 @@ get_event_button(SDL_Event *event) case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: key = KEY_NUM5; break; case SDL_CONTROLLER_BUTTON_START: + key = KEY_ENTER; break; + case SDL_CONTROLLER_BUTTON_BACK: key = KEY_ESC; break; + case SDL_CONTROLLER_BUTTON_LEFTSTICK: + key = KEY_SPACE; break; default: key = 0; break; } @@ -128,8 +132,6 @@ get_axis_motion(SDL_Event *event) Uint64 key; int angle = event->caxis.value; switch (event->caxis.axis) { - case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: - key = KEY_SPACE; break; case SDL_CONTROLLER_AXIS_LEFTX: key = angle < 0 ? KEY_LEFT : KEY_RIGHT; break; case SDL_CONTROLLER_AXIS_LEFTY: @@ -140,6 +142,11 @@ get_axis_motion(SDL_Event *event) return key; } +static Uint32 +get_button_modkey(SDL_Event *event) { + +} + static Uint32 get_event_modkey(SDL_Event *event) { @@ -221,7 +228,7 @@ input_handle_event(Input *input, SDL_Event *event) input->keyState &= ~get_event_button(event); } 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); else input->keyState &= ~get_axis_motion(event); diff --git a/src/main.c b/src/main.c index aae0664..1356eee 100644 --- a/src/main.c +++ b/src/main.c @@ -87,9 +87,9 @@ static char *skills_tooltip[] = { " Skills are listed in the bar below the game screen.", "", "", "", - " SKILL INFO: ", "SHIFT", " + ", "", - " Where is the button corresponding to the skill", - " Eg. ", "1", "2", "3", "4", "5", "", + " SKILL INFO: SHIFT + ", "", + " Where is the number corresponding to the skill", "", + " Eg. 1, 2, 3, 4, 5", "", "", " DISABLE TOOLTIPS: CTRL + D", "", "", @@ -102,6 +102,7 @@ static char *how_to_play_tooltip[] = { "HOW TO PLAY", "", "", " NAVIGATION: Use ARROWS or WASD or HJKL to move", "", + " Controller: RIGHT STICK or D-PAD", "", "", " ATTACK: Walk into a monster to attack it", "", "", @@ -184,7 +185,7 @@ bool initSDL(void) { 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()); return false; @@ -216,7 +217,7 @@ bool initSDL(void) gController = SDL_GameControllerOpen(i); if (gController) { - info("Game controller connected"); + info("Game controller connected: %s", SDL_GameControllerName(gController)); break; } } diff --git a/src/skill.c b/src/skill.c index 5182a39..532e016 100644 --- a/src/skill.c +++ b/src/skill.c @@ -659,7 +659,7 @@ skill_charge(Skill *skill, SkillData *data) Position lastAvailableDest = playerStartPos; while (position_in_roommatrix(&destination)) { - if (space->occupied) { + if (space->occupied || space->monster) { if (!space->monster || passThroughCount >= chargeThroughLvl) break; else diff --git a/src/skillbar.c b/src/skillbar.c index 85608e0..60fa34d 100644 --- a/src/skillbar.c +++ b/src/skillbar.c @@ -43,6 +43,7 @@ create_controller_button_sprite(Position pos, SDL_Rect clip) Sprite *s = sprite_create(); sprite_set_texture(s, t, 0); s->pos = pos; + s->fixed = true; s->clip = clip; s->dim = DIM(16, 16); return s;