Write basic game structure
This commit is contained in:
parent
1c6b2bd4a1
commit
e788ddee39
4 changed files with 83 additions and 12 deletions
33
src/Game/Engine.hs
Normal file
33
src/Game/Engine.hs
Normal 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 -< ()
|
||||
Loading…
Add table
Add a link
Reference in a new issue