aboutsummaryrefslogtreecommitdiff
path: root/src/Input.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2014-09-02 21:35:58 +0200
committerJoris Guyonvarch2014-09-02 21:35:58 +0200
commitc4ae3b0ee4bd338995cfecf34e0aeb49f05fa70e (patch)
tree71530e9e2cfcbe888cb086593ea1e4d0bcc269a6 /src/Input.elm
Initial commit
Diffstat (limited to 'src/Input.elm')
-rw-r--r--src/Input.elm39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Input.elm b/src/Input.elm
new file mode 100644
index 0000000..d8614b0
--- /dev/null
+++ b/src/Input.elm
@@ -0,0 +1,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
+ }