on master help sign in
adjust vty-rouge some
commit7c1c7894ab5f820050384dfde7a55699d485ed90 authorCorey O'Connor <corey@ooyala.com> dateSun 24 Nov 2013, 19:48 (13 years ago) parentd05afa1
1 file changed+16−11
test/Rouge.hs+16−11
test/Rouge.hs+16−11
@@ -44,24 +44,29 @@ type Game = RWST Vty () World IO
4444
4545main = do
4646 vty <- mkVty
47− level_0 <- mkLevel 0
47+ level_0 <- mkLevel 1
4848 let world_0 = World (Dude (fst $ start level_0) (snd $ start level_0)) level_0
4949 (_final_world, ()) <- execRWST (play >> view) vty world_0
5050 shutdown vty
5151
52−mkLevel _difficulty = do
53− level_width <- randomRIO (200,300)
54− level_height <- randomRIO (200,300)
55− start <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
56− end <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
52+mkLevel difficulty = do
53+ let size = 80 * difficulty
54+ [level_width, level_height] <- replicateM 2 $ randomRIO (size,size)
55+ let randomP = (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
56+ start <- randomP
57+ end <- randomP
5758 -- first the base geography: all rocks
5859 let base_geo = array ((0,0), (level_width, level_height))
5960 [((x,y),Rock) | x <- [0..level_width-1], y <- [0..level_height-1]]
6061 -- next the empty spaces that make the rooms
61− geo <- add_room start base_geo level_width level_height
62+ -- for this we generate a number of center points
63+ centers <- replicateM (2 ^ difficulty + difficulty) randomP
64+ -- generate rooms for all those points, plus the start and end
65+ geo <- foldM (add_room level_width level_height) base_geo (start : end : centers)
6266 return $ Level start end geo (build_geo_image geo)
67+ where
6368
64−add_room (center_x, center_y) geo level_width level_height = do
69+add_room level_width level_height geo (center_x, center_y) = do
6570 size <- randomRIO (5,15)
6671 let x_min = max 1 (center_x - size)
6772 x_max = min (level_width - 1) (center_x + size)
@@ -71,9 +76,9 @@ add_room (center_x, center_y) geo level_width level_height = do
7176 return (geo // room)
7277
7378image_for_geo EmptySpace = char (def_attr `with_back_color` green) ' '
74−image_for_geo Rock = char (def_attr `with_fore_color` white) 'X'
79+image_for_geo Rock = char def_attr 'X'
7580
76−pieceA = def_attr `with_fore_color` red
81+pieceA = def_attr `with_fore_color` blue `with_back_color` green
7782dumpA = def_attr `with_style` reverse_video
7883
7984play = do
@@ -113,7 +118,7 @@ view = do
113118 DisplayRegion w h <- asks terminal >>= liftIO . display_bounds
114119 the_dude <- gets dude
115120 let ox = (w `div` 2) - dude_x the_dude
116− oy = (h `div` 2) - dude_y the_dude + image_height info
121+ oy = (h `div` 2) - dude_y the_dude
117122 -- translate the world images to place the dude in the center of the level.
118123 world' <- map (translate ox oy) <$> world
119124 let pic = pic_for_layers $ info : world'