From c4ae3b0ee4bd338995cfecf34e0aeb49f05fa70e Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Tue, 2 Sep 2014 21:35:58 +0200 Subject: Initial commit --- src/Input.elm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Input.elm (limited to 'src/Input.elm') 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 + } -- cgit v1.2.3