From 35990c53bfe76c1063079b4d7b8d31744e89a3c0 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 25 Apr 2023 15:46:03 +0100 Subject: [PATCH] Add file --- src/Dodge/WASD.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/Dodge/WASD.hs 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