@@ -1,3 +1,4 @@
1+{-# LANGUAGE TemplateHaskell #-}
1module Main where
2module Main where
3import Graphics.Vty
4import Graphics.Vty
@@ -7,6 +8,7 @@ import qualified Data.ByteString as B
7import Data.Word
8import Data.Word
9import Control.Applicative
10import Control.Applicative
11+import Control.Lens hiding (Level)
10import Control.Monad
12import Control.Monad
11import Control.Monad.RWS
13import Control.Monad.RWS
12import Control.Monad.Writer
14import Control.Monad.Writer
@@ -46,7 +48,7 @@ main = do
46 vty <- mkVty
48 vty <- mkVty
47 level_0 <- mkLevel 1
49 level_0 <- mkLevel 1
48 let world_0 = World (Dude (fst $ start level_0) (snd $ start level_0)) level_0
50 let world_0 = World (Dude (fst $ start level_0) (snd $ start level_0)) level_0
49− (_final_world, ()) <- execRWST (play >> view) vty world_0
51+ (_final_world, ()) <- execRWST (play >> update_display) vty world_0
50 shutdown vty
52 shutdown vty
52mkLevel difficulty = do
54mkLevel difficulty = do
@@ -82,7 +84,7 @@ pieceA = def_attr `with_fore_color` blue `with_back_color` green
82dumpA = def_attr `with_style` reverse_video
84dumpA = def_attr `with_style` reverse_video
85− view
87+ update_display
86 done <- process_event
88 done <- process_event
87 unless done play
89 unless done play
@@ -111,8 +113,8 @@ move_dude dx dy = do
111 EmptySpace -> put $ world { dude = Dude x' y' }
113 EmptySpace -> put $ world { dude = Dude x' y' }
112 _ -> return ()
114 _ -> return ()
114−view :: Game ()
116+update_display :: Game ()
115−view = do
117+update_display = do
116 let info = string def_attr "Move with the arrows keys. Press ESC to exit."
118 let info = string def_attr "Move with the arrows keys. Press ESC to exit."
117 -- determine offsets to place the dude in the center of the level.
119 -- determine offsets to place the dude in the center of the level.
118 DisplayRegion w h <- asks terminal >>= liftIO . display_bounds
120 DisplayRegion w h <- asks terminal >>= liftIO . display_bounds