Making a Map in Gloss

In PL class we were asked to make a pacman clone in Gloss, nevertheless I got stuck at making the map.

My approach was taking a .png of the classical pacman first level, and paste it in the render function so I don't need to draw everything by hand.

Nevertheless by doing so, the games lags horribly, I'm assuming that it's because the game renders the map in every step.

Is there some way to just render the map as a background a single time, or avoid the huge lag? Or am I taking a bad approach and it would it be better if I draw the components by hand using the Picture module?

I append the render function just in case I'm wiring it badly:

render :: PacmanGame -> IO Picture
render game = do
  sprite <- fmap (head) (playerSprites $ player game)
  let playerOne = uncurry translate (playerPos $ player game) $ sprite
  map' <- pacmanMap 
  return $ pictures [map', playerOne]

Where pacmanMap :: IO Picture

Upvotes: 0

Views: 173

Answers (1)

Jon Purdy
Jon Purdy

Reputation: 54999

It looks like you’re reloading the file in every call to render. You need to run the pacmanMap :: IO Picture action once, for example at startup in main; then you can just return the resulting static Picture from your render function. For example, you might store the reference to the current background image in the PacmanGame, or pass it as an additional argument to render.

Upvotes: 0

Related Questions