Last active
July 28, 2017 22:53
-
-
Save xarvh/11d64ef600df1d5007d17c0ecafcb853 to your computer and use it in GitHub Desktop.
API options comparison for elm-gamepad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
As a game developer, I want to allow the player to remap the game controls, to allow them using non-recognised pads and suit their personal comfort. | |
As a game developer, I want to access specific gamepad inputs with consistent naming that does not depend on hardware or user preferences. | |
-} | |
-- Option A | |
import Gamepad | |
import Gamepad.Remap | |
requiredInputs : Gamepad.Remap.MappableInputs | |
requiredInputs = | |
{ mappableInputs | |
| leftX = "Move > Right" | |
, leftY = "Move ^ Up" | |
, rightX = "Aim > Right" | |
, rightY = "Aim ^ Up" | |
, a = "Fire" | |
, b = "Fire (alternate button)" | |
} | |
moveX pad = | |
Gamepad.leftX pad | |
moveY pad = | |
Gamepad.leftY pad | |
aimX pad = | |
Gamepad.rightX pad | |
aimY pad = | |
Gamepad.rightY pad | |
shootIsPressed pad = | |
Gamepad.aIsPressed pad || Gamepad.bIsPressed pad | |
-- Option B | |
import Gamepad exposing (Input(..)) | |
import Gamepad.Remap | |
requiredInputs : List ( Input, String ) | |
requiredInputs = | |
[ ( LeftX, "Move > Right" ) | |
, ( LeftY, "Move ^ Up" ) | |
, ( RightX, "Aim > Right" ) | |
, ( RightY, "Aim ^ Up" ) | |
, ( A, "Fire" ) | |
, ( B, "Fire (alternate button)" ) | |
] | |
moveX pad = | |
Gamepad.getValue LeftX pad | |
moveY pad = | |
Gamepad.getValue LeftY pad | |
aimX pad = | |
Gamepad.getValue RightX pad | |
aimY pad = | |
Gamepad.getValue RightY pad | |
shootIsPressed pad = | |
Gamepad.isPressed A pad || Gamepad.isPressed B pad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment