Implmement display system

This commit is contained in:
Kiana Sheibani 2023-01-25 15:49:30 -05:00
parent 3780e967cd
commit ebb27755d2
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 26 additions and 1 deletions

24
src/Game/Display.hs Normal file
View file

@ -0,0 +1,24 @@
{-# LANGUAGE Arrows #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE ViewPatterns #-}
module Game.Display where
import Control.Monad
import Control.Monad.Trans.MSF.Reader
import Control.Monad.Trans.MSF.Writer
import Data.Maybe
import Data.MonadicStreamFunction
import Game.State
import Game.Utils
import Graphics.Gloss
import Graphics.Gloss.Interface.IO.Game
getSquare :: (Int, Int) -> Picture
getSquare (toEnum -> x, toEnum -> y) =
translate (x * 25) (y * 25) $ rectangleSolid 25 25
displayState :: Monad m => MSF (DrawerT m) GameState ()
displayState = proc state -> do
draw -< mconcat $ color green . getSquare <$> state.snakePos
draw -< color red $ getSquare state.berryPos

View file

@ -59,4 +59,5 @@ mainSF = proc () -> do
-- undefined is safe here because the first frame is guaranteed to be a tick -- undefined is safe here because the first frame is guaranteed to be a tick
state <- hold undefined -< state' state <- hold undefined -< state'
returnA -< () -- Display the current state
displayState -< state