aboutsummaryrefslogtreecommitdiff
path: root/src/Input.elm
blob: d8614b01c7a9a0a5ea412608252962a2e094e017 (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
32
33
34
35
36
37
38
39
module Input where

import Keyboard
import Random
import RandomValues (RandomValues)

import Vec2 (Vec2)

type Input =
  { dir : Vec2
  , delta : Time
  , randomValues : RandomValues
  }

getInput : Signal Input
getInput =
  let dtSignal = delta
      dirSignal = lift recordIntToVec2 Keyboard.arrows
      randomFloatsSignal = Random.floatList (lift (\_ -> 3) dtSignal)
      randomValuesSignal = lift floatsToRandomValues randomFloatsSignal
  in  sampleOn dtSignal <| Input <~ dirSignal
                                  ~ dtSignal
                                  ~ randomValuesSignal

delta : Signal Time
delta = lift (\ms -> ms) (fps 25)

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

floatsToRandomValues : [Float] -> RandomValues
floatsToRandomValues [enemyAngle, enemyX, enemyY] =
  { enemyAngle = enemyAngle
  , enemyX = enemyX
  , enemyY = enemyY
  }