Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Input Engine

Yannick Willems edited this page Oct 15, 2020 · 3 revisions

De game loop roept telkens getInput aan, een functie in de SDLInputEngineAdapter. Deze functie polled steeds voor input van de user van de verschillende devices die connected zijn. We maken onderscheid tussen drie verschillende devices. getInput returned een Input struct wanneer een bepaald event type triggered.

Index Device Event Trigger Returns
0 Keyboard SDL_KEYDOWN Input { keyCode }
1 Mouse SDL_MOUSEBUTTONDOWN Input { x, y, keyCode }
2 Joystick SDL_CONTROLLERBUTTONDOWN Input { keyCode }

Voor controllers zijn er nog twee verschillende event types. Deze returnen niets.

Event Type Function Returns
SDL_CONTROLLERDEVICEADDED openController -
SDL_CONTROLLERDEVICEREMOVED closeController -

De keyCode variablen worden opgehaald uit een pre-defined key map aan de hand van de SDL_KeyCode. Deze key maps staan hieronder in tablevorm uitgewerkt:

0: Keyboard KeyMap

SDL KeyCode Returned KeyCode Intended Action
SDLK_UP UP Move Up
SDLK_DOWN DOWN Move Down
SDLK_LEFT LEFT Move Left
SDLK_RIGHT RIGHT Move Right
SDLK_w UP Move Up
SDLK_s DOWN Move Down
SDLK_a LEFT Move Left
SDLK_d RIGHT Move Right
SDLK_SPACE SPACE Jump
SDLK_e E Inventory
SDLK_q Q Quit

1: Mouse KeyMap

SDL KeyCode Returned KeyCode Intended Action
SDL_BUTTON_LEFT MOUSE_BUTTON_LEFT Click Left
SDL_BUTTON_RIGHT MOUSE_BUTTON_RIGHT Click Right

2: Controller KeyMap

SDL KeyCode Returned KeyCode Intended Action
SDL_CONTROLLER_BUTTON_A CONTROLLER_BUTTON_A
SDL_CONTROLLER_BUTTON_B CONTROLLER_BUTTON_B
SDL_CONTROLLER_BUTTON_X CONTROLLER_BUTTON_X
SDL_CONTROLLER_BUTTON_Y CONTROLLER_BUTTON_Y
SDL_CONTROLLER_BUTTON_LEFTSHOULDER CONTROLLER_BUTTON_LB
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER CONTROLLER_BUTTON_RB
SDL_CONTROLLER_BUTTON_BACK CONTROLLER_BUTTON_SELECT
SDL_CONTROLLER_BUTTON_START CONTROLLER_BUTTON_START
SDL_CONTROLLER_BUTTON_LEFTSTICK CONTROLLER_BUTTON_L3
SDL_CONTROLLER_BUTTON_RIGHTSTICK CONTROLLER_BUTTON_R3
SDL_CONTROLLER_BUTTON_DPAD_UP CONTOLLER_DPAD_UP
SDL_CONTROLLER_BUTTON_DPAD_DOWN CONTROLLER_DPAD_DOWN
SDL_CONTROLLER_BUTTON_DPAD_LEFT CONTROLLER_DPAD_LEFT
SDL_CONTROLLER_BUTTON_DPAD_RIGHT CONTROLLER_DPAD_RIGHT
CONTROLLER_LEFT_JOYSTICK_UP Move Up
CONTROLLER_LEFT_JOYSTICK_DOWN Move Down
CONTROLLER_LEFT_JOYSTICK_LEFT Move Left
CONTROLLER_LEFT_JOYSTICK_RIGHT Move Right
CONTROLLER_RIGHT_JOYSTICK_UP Camera Up
CONTROLLER_RIGHT_JOYSTICK_DOWN Camera Down
CONTROLLER_RIGHT_JOYSTICK_LEFT Camera Left
CONTROLLER_RIGHT_JOYSTICK_RIGHT Camera Right
Clone this wiki locally