@@ -49,6 +49,8 @@ main = do
49 (_finalWorld, ()) <- execRWST play vty world0
49 (_finalWorld, ()) <- execRWST play vty world0
50 shutdown vty
50 shutdown vty
52+-- |Generate a level randomly using the specified difficulty. Higher
53+-- difficulty means the level will have more rooms and cover a larger area.
52mkLevel :: Int -> IO Level
54mkLevel :: Int -> IO Level
53mkLevel difficulty = do
55mkLevel difficulty = do
54 let size = 80 * difficulty
56 let size = 80 * difficulty
@@ -66,7 +68,16 @@ mkLevel difficulty = do
66 geo <- foldM (addRoom levelWidth levelHeight) baseGeo (start : end : centers)
68 geo <- foldM (addRoom levelWidth levelHeight) baseGeo (start : end : centers)
67 return $ Level start end geo (buildGeoImage geo)
69 return $ Level start end geo (buildGeoImage geo)
71+-- |Add a room to a geography and return a new geography. Adds a
72+-- randomly-sized room centered at the specified coordinates.
69−addRoom :: Int -> Int -> Geo -> (Int, Int) -> IO Geo
73+addRoom :: Int
75+ -- ^The width and height of the geographical area
77+ -- ^The geographical area to which a new room should be added
79+ -- ^The desired center of the new room.
70addRoom levelWidth levelHeight geo (centerX, centerY) = do
81addRoom levelWidth levelHeight geo (centerX, centerY) = do
71 size <- randomRIO (5,15)
82 size <- randomRIO (5,15)
72 let xMin = max 1 (centerX - size)
83 let xMin = max 1 (centerX - size)