build map encasing

This commit is contained in:
nek0 2023-12-11 13:17:37 +01:00
parent c1717bc7d1
commit ad52b9c037

View file

@ -1,8 +1,13 @@
module Server.Map where
import Control.Monad (foldM)
import qualified Data.Matrix as M
import qualified Data.Vector as V
import Linear
import System.Random
import Library.Types
@ -48,8 +53,11 @@ generateMap
-> Int -- ^ Map's width
-> IO ServerMap -- ^ resulting Map
generateMap mapRows mapColumns = do
let initMap = M.matrix mapRows mapColumns (const Air)
divide 0 0 mapRows mapColumns initMap
let initMap = M.matrix mapRows mapColumns (const Air)
wallRow = M.rowVector $ V.replicate (mapRows + 2) Wall
wallCol = M.colVector $ V.replicate mapColumns Wall
builtMap <- divide 0 0 mapRows mapColumns initMap
pure $ wallRow M.<-> (wallCol M.<|> builtMap M.<|> wallCol) M.<-> wallRow
where
divide :: Int -> Int -> Int -> Int -> ServerMap -> IO ServerMap
divide rowOffset colOffset rowSize colSize tilemap