-- | Main function
main :: IO ()
main = do
wall <- loadBMP "wall.bmp" -- loads wall image
play initialState drawState reactEvent reactTime
-- | Function that creates the game
play :: State -> (State -> Picture) -> (Event -> State -> State) -> (Float -> State -> State) -> IO ()
play initialState drawState reactEvent reactTime = play
(InWindow "Game" (900, 900) (0, 0)) -- Window ize
(greyN 0.5) -- background coloer
1 -- refresh rate
initialState -- initial state
drawState -- draws game state
reactEvent -- teacts to evente
reactTime -- reacts to time
-- | One game represenction
type State = (Map,Picture)
-- | Initial game state
initialState :: State
initialState = ((map 13 0),wall)
功能地图创建我的地图。 我的游戏已经运行良好,但我需要用一些BMP图像替换我使用的表示(来自光泽的圆圈),但是当我尝试加载这个墙时,我甚至无法加载它会出现错误我在这里分享的最后一行: 不在范围内&#39;墙&#39;
有人能看出为什么会这样吗?
答案 0 :(得分:2)
定义main
时,您在此处创建的变量无法在main
的定义之外访问。 initialState
超出了main
的定义。
您需要将wall
传递到initialState
,方法是更改main
和initialState
,如下所示:
main :: IO ()
main = do
wall <- loadBMP "wall.bmp" -- loads wall image
play (initialState wall) drawState reactEvent reactTime
initialState :: Picture -> State
initialState wall = ((map 13 0),wall)