module Input where import Terminal.Game data Input = KUp | KDown | KLeft | KRight | KSpace | KRestart | KHelp | KExit | NoKey deriving (Eq, Show) data Cardinal = N | S | W | E deriving (Eq, Show) ----------- -- Input -- ----------- eventInput :: Event -> Input eventInput Tick = NoKey eventInput (KeyPress c) | c == 'w' = KUp | c == 'z' = KUp -- azerty support | c == 's' = KDown | c == 'a' = KLeft | c == 'q' = KLeft | c == 'd' = KRight | c == ' ' = KSpace | c == 'r' = KRestart | c == 'h' = KHelp | c == 'l' = KExit | otherwise = NoKey -- WASD isMovKey :: Input -> Bool isMovKey k = elem k [KUp, KDown, KLeft, KRight, KSpace] -- non WASD isMenuKey :: Input -> Bool isMenuKey k = elem k [KRestart, KHelp, KExit] turnAround :: Cardinal -> Cardinal turnAround N = S turnAround S = N turnAround E = W turnAround W = E