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
49
50
51
|
module Input where
import Char (toCode)
import RandomValues (RandomValues)
import Keyboard (KeyCode, keysDown, arrows)
import Random
import Vec2 (Vec2)
type Input =
{ dir : Vec2
, inputKeysDown : [KeyCode]
, delta : Time
, randomValues : RandomValues
}
getInput : Signal Input
getInput =
let dtSignal = delta
dirSignal = lift recordIntToVec2 arrows
randomFloatsSignal = Random.floatList (lift (\_ -> 6) dtSignal)
randomValuesSignal = lift floatsToRandomValues randomFloatsSignal
in sampleOn dtSignal <| Input <~ dirSignal
~ keysDown
~ 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 [angle1, x1, y1, angle2, x2, y2] =
let point1 =
{ angle = angle1
, x = x1
, y = y1
}
point2 =
{ angle = angle2
, x = x2
, y = y2
}
in { point1 = point1
, point2 = point2
}
|