-- | This module defines how to turn
-- the game state into a picture
module View where
import Graphics.Gloss
import Model
view :: GameState -> IO Picture
view gState@GameState{textures = ts} = do
x <- ts
return (viewPure gState x)
viewPure :: GameState -> [Picture] -> Picture
viewPure gstate@GameState {pakMan = p} ts = drawPakMan p ts --pictures ( map (\(f,o) -> f o ts) [(drawPakMan, p)] )
pakManSpritePos :: Int
pakManSpritePos = 0
ghostSpritePos = 4
tileSpritePos = 8
drawPakMan :: PakMan -> [Picture] -> Picture
drawPakMan p@(PakMan (Pos x y) d _) ps = translate2Screen x y (ps !! ( (pakManSpritePos) + (directionToOffset d) )) --
directionToOffset :: Direction -> Int
directionToOffset DUp = 0
directionToOffset DDown = 1
directionToOffset DLeft = 2
directionToOffset DRight = 3
translate2Screen :: Int -> Int -> Picture -> Picture
translate2Screen x y = translate (fromIntegral $ x-640) (fromIntegral $ -y+360)
If more code is needed please ask!