Write basic game structure

This commit is contained in:
Kiana Sheibani 2023-01-25 12:10:17 -05:00
parent 1c6b2bd4a1
commit e788ddee39
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 83 additions and 12 deletions

33
src/Game/Engine.hs Normal file
View file

@ -0,0 +1,33 @@
{-# LANGUAGE Arrows #-}
module Game.Engine where
import Data.MonadicStreamFunction
import Game.State
import Game.Utils
handleEvents :: Monad m => MSF (DrawerT m) () [Direction]
handleEvents = proc () -> do
returnA -< []
tick :: Monad m => MSF (DrawerT m) (Maybe Direction) GameState
tick = next initialState $ feedback initialState $ proc (dir, state) -> do
returnA -< (state, state)
mainSF :: Monad m => MSF (DrawerT m) () ()
mainSF = proc () -> do
n <- count -< ()
let isTick = n `mod` 20 == 1
-- handle inputs (buffer)
dirs <- handleEvents -< ()
dir <- fifoGate -< (dirs, isTick)
state' <-
if isTick
then fmap Just tick -< dir
else returnA -< Nothing
-- undefined is safe here because the first frame is guaranteed to be a tick
state <- hold undefined -< state'
returnA -< ()