-
Notifications
You must be signed in to change notification settings - Fork 1
/
Input.elm
36 lines (28 loc) · 1.03 KB
/
Input.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Input where
import Keyboard
import List
import Signal exposing (..)
import Time exposing (..)
onTrue : Signal Bool -> Signal ()
onTrue = map (\_ -> ()) << filter identity False << dropRepeats
onFalse : Signal Bool -> Signal ()
onFalse = map (\_ -> ()) << filter not False << dropRepeats
onPressed : Keyboard.KeyCode -> Signal ()
onPressed = onTrue << Keyboard.isDown
onReleased : Keyboard.KeyCode -> Signal ()
onReleased = onFalse << Keyboard.isDown
type Input = None |
LeftArrow |
RightArrow |
UpArrow |
DownArrow |
Spacebar |
NewTimeStep Time
keyPressed : Keyboard.KeyCode -> Input -> Signal Input
keyPressed key action = merge (constant None) <| always action <~ onPressed key
input : Signal Input
input = let keyPressInput =
mergeMany <| List.map2 keyPressed
[37, 39, 40, 38, 32]
[LeftArrow, RightArrow, DownArrow, UpArrow, Spacebar]
in merge (NewTimeStep <~ fps 60) keyPressInput