on master help sign in
adjust vty-rouge some
7c1c789Corey O'Connor
test/Rouge.hs+16−11
@@ -44,24 +44,29 @@ type Game = RWST Vty () World IO
44
44
45main = do
45main = do
46 vty <- mkVty
46 vty <- mkVty
47− level_0 <- mkLevel 0
47+ level_0 <- mkLevel 1
48 let world_0 = World (Dude (fst $ start level_0) (snd $ start level_0)) level_0
48 let world_0 = World (Dude (fst $ start level_0) (snd $ start level_0)) level_0
49 (_final_world, ()) <- execRWST (play >> view) vty world_0
49 (_final_world, ()) <- execRWST (play >> view) vty world_0
50 shutdown vty
50 shutdown vty
51
51
52−mkLevel _difficulty = do
52+mkLevel difficulty = do
53+ let size = 80 * difficulty
53− level_width <- randomRIO (200,300)
54+ [level_width, level_height] <- replicateM 2 $ randomRIO (size,size)
54− level_height <- randomRIO (200,300)
55+ let randomP = (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
55− start <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
56+ start <- randomP
56− end <- (,) <$> randomRIO (2, level_width-3) <*> randomRIO (2, level_height-3)
57+ end <- randomP
57 -- first the base geography: all rocks
58 -- first the base geography: all rocks
58 let base_geo = array ((0,0), (level_width, level_height))
59 let base_geo = array ((0,0), (level_width, level_height))
59 [((x,y),Rock) | x <- [0..level_width-1], y <- [0..level_height-1]]
60 [((x,y),Rock) | x <- [0..level_width-1], y <- [0..level_height-1]]
60 -- next the empty spaces that make the rooms
61 -- next the empty spaces that make the rooms
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
61− geo <- add_room start base_geo level_width level_height
65+ geo <- foldM (add_room level_width level_height) base_geo (start : end : centers)
62 return $ Level start end geo (build_geo_image geo)
66 return $ Level start end geo (build_geo_image geo)
67+ where
63
68
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
65 size <- randomRIO (5,15)
70 size <- randomRIO (5,15)
66 let x_min = max 1 (center_x - size)
71 let x_min = max 1 (center_x - size)
67 x_max = min (level_width - 1) (center_x + size)
72 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
71 return (geo // room)
76 return (geo // room)
72
77
73image_for_geo EmptySpace = char (def_attr `with_back_color` green) ' '
78image_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'
75
80
76−pieceA = def_attr `with_fore_color` red
81+pieceA = def_attr `with_fore_color` blue `with_back_color` green
77dumpA = def_attr `with_style` reverse_video
82dumpA = def_attr `with_style` reverse_video
78
83
79play = do
84play = do
@@ -113,7 +118,7 @@ view = do
113 DisplayRegion w h <- asks terminal >>= liftIO . display_bounds
118 DisplayRegion w h <- asks terminal >>= liftIO . display_bounds
114 the_dude <- gets dude
119 the_dude <- gets dude
115 let ox = (w `div` 2) - dude_x the_dude
120 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
117 -- translate the world images to place the dude in the center of the level.
122 -- translate the world images to place the dude in the center of the level.
118 world' <- map (translate ox oy) <$> world
123 world' <- map (translate ox oy) <$> world
119 let pic = pic_for_layers $ info : world'
124 let pic = pic_for_layers $ info : world'