@@ -29,6 +29,9 @@ data Level = Level
29 { start :: (Int, Int)
29 { start :: (Int, Int)
30 , end :: (Int, Int)
30 , end :: (Int, Int)
31 , geo :: Array (Int, Int) LevelPiece
31 , geo :: Array (Int, Int) LevelPiece
32+ -- building the geo image is expensive. Cache it. Though VTY should go through greater lengths
33+ -- to avoid the need to cache images.
33 deriving (Show,Eq)
36 deriving (Show,Eq)
@@ -47,8 +50,8 @@ main = do
47 shutdown vty
50 shutdown vty
49mkLevel _difficulty = do
52mkLevel _difficulty = do
50− level_width <- randomRIO (40,80)
53+ level_width <- randomRIO (200,300)
51− level_height <- randomRIO (40,80)
54+ level_height <- randomRIO (200,300)
52 start <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
55 start <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
53 end <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
56 end <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
54 -- first the base geography: all rocks
57 -- first the base geography: all rocks
@@ -56,7 +59,7 @@ mkLevel _difficulty = do
56 [((x,y),Rock) | x <- [0..level_width-1], y <- [0..level_height-1]]
59 [((x,y),Rock) | x <- [0..level_width-1], y <- [0..level_height-1]]
57 -- next the empty spaces that make the rooms
60 -- next the empty spaces that make the rooms
58 geo <- add_room start base_geo level_width level_height
61 geo <- add_room start base_geo level_width level_height
59− return $ Level start end geo
62+ return $ Level start end geo (build_geo_image geo)
61add_room (center_x, center_y) geo level_width level_height = do
64add_room (center_x, center_y) geo level_width level_height = do
62 size <- randomRIO (5,15)
65 size <- randomRIO (5,15)
@@ -122,10 +125,16 @@ world = do
122 the_dude <- gets dude
125 the_dude <- gets dude
123 the_level <- gets level
126 the_level <- gets level
124 let dude_image = translate (dude_x the_dude) (dude_y the_dude) (char pieceA '@')
127 let dude_image = translate (dude_x the_dude) (dude_y the_dude) (char pieceA '@')
128+ return [dude_image, geo_image the_level]
130+build_geo_image geo =
125− (geo_width, geo_height) = snd $ bounds (geo the_level)
131+ let (geo_width, geo_height) = snd $ bounds geo
132+ -- seems like a the repeated index operation should be removable. This is not performing random
133+ -- access but (presumably) access in order of index.
126− geo_image = vert_cat [ geo_row | y <- [0..geo_height-1],
134+ in vert_cat [ geo_row
135+ | y <- [0..geo_height-1]
127− let geo_row = horiz_cat [ i | x <- [0..geo_width-1],
136+ , let geo_row = horiz_cat [ i
137+ | x <- [0..geo_width-1]
128− let i = image_for_geo (geo the_level ! (x,y))
138+ , let i = image_for_geo (geo ! (x,y))
131− return [dude_image, geo_image]
140+ ]