-
Notifications
You must be signed in to change notification settings - Fork 3
/
Subscriptions.elm
48 lines (36 loc) · 997 Bytes
/
Subscriptions.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
37
38
39
40
41
42
43
44
45
46
47
48
module Subscriptions exposing (..)
import Msg exposing (Msg(..))
import Model exposing (Model, GameState(..))
import Keyboard exposing (..)
import Time
import Char
key_to_msg : KeyCode -> Msg
key_to_msg n =
case n of
32 -> -- Space bar
Enter
13 -> -- Enter
Enter
_ ->
case Char.fromCode n of
'M' ->
Menu
'R' ->
RestartLevel
'W' ->
Arrows (0, -1)
'A' ->
Arrows (-1, 0)
'S' ->
Arrows (0, 1)
'D' ->
Arrows (1, 0)
_ ->
Nop
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ Time.every (Time.millisecond * 10) Msg.Tick
, Time.every (Time.second / 2) (\_ -> Msg.PlayerAnimation)
, Keyboard.downs key_to_msg
]