Implement game engine

This commit is contained in:
Kiana Sheibani 2023-01-25 15:48:50 -05:00
parent 338305e32c
commit 3780e967cd
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 22 additions and 3 deletions

View file

@ -31,8 +31,17 @@ handleEvents = mapMaybe getDir <$> liftTransS (constM ask)
getDir _ = Nothing
tick :: Monad m => MSF (DrawerT m) (Maybe Direction) GameState
tick = next initialState $ feedback initialState $ proc (dir, state) -> do
returnA -< (state, state)
tick =
next initialState $
mealy
( \input state ->
let moveDir = setDir state.moveDir input
snakePos = movePos moveDir <$> state.snakePos
berryPos = state.berryPos
newstate = GameState {..}
in (newstate, newstate)
)
initialState
mainSF :: Monad m => MSF (DrawerT m) () ()
mainSF = proc () -> do