aboutsummaryrefslogtreecommitdiff
path: root/src/Input.elm
blob: 3723ba3060e89c4c49c780d81116678423b608a9 (plain)
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
module Input where

import Char (toCode)
import Keyboard (KeyCode, keysDown, arrows, isDown)
import Random
import Time (Time, fps)
import Signal (..)

import Vec2 (Vec2)

type alias Input =
  { dir : Vec2
  , inputKeysDown : List KeyCode
  , delta : Time
  }

getInput : Signal Input
getInput =
  let delta = fps 25
      input =
        Input
          <~ map recordIntToVec2 arrows
           ~ keysDown
           ~ delta
  in  sampleOn delta input

recordIntToVec2 : {x : Int, y : Int} -> Vec2
recordIntToVec2 {x, y} =
  { x = toFloat x
  , y = toFloat y
  }