diff --git a/src/Dodge/WASD.hs b/src/Dodge/WASD.hs new file mode 100644 index 000000000..8e6c15143 --- /dev/null +++ b/src/Dodge/WASD.hs @@ -0,0 +1,19 @@ +module Dodge.WASD where + +import Data.Foldable +import qualified Data.Map.Strict as M +import Dodge.Data.Input +import Geometry +import qualified SDL + +wasdM :: SDL.Scancode -> Point2 +wasdM scancode = case scancode of + SDL.ScancodeW -> V2 0 1 + SDL.ScancodeS -> V2 0 (-1) + SDL.ScancodeD -> V2 1 0 + SDL.ScancodeA -> V2 (-1) 0 + _ -> V2 0 0 + +wasdDir :: Input -> Point2 +{-# INLINE wasdDir #-} +wasdDir = foldl' (flip $ (+.+) . wasdM) (V2 0 0) . M.keys . _pressedKeys