Refactor level/room generation modules
This commit is contained in:
+4
-119
@@ -36,78 +36,7 @@ import Data.Graph.Inductive.NodeMap
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
-- }}}
|
||||
|
||||
|
||||
|
||||
lev1 :: RandomGen g => State g (Tree Room)
|
||||
lev1 = do
|
||||
firstWeapon <- takeOne $ [[branchRectWith weaponRoom,blockedCorridor]] ++ replicate 5 [weaponRoom]
|
||||
iterateWhile boundClip $ fmap (shiftRoomTree . expandTreeBy id)
|
||||
$ sequence $ treePost
|
||||
(
|
||||
-- [randomiseLinks =<< pistolerRoom]
|
||||
[return $ return $ Right deadEndRoom
|
||||
]
|
||||
++ [slowDoorRoom]
|
||||
++ [return $ connectRoom corridor
|
||||
,return $ connectRoom door]
|
||||
-- ++ [randomiseLinks =<< longRoom]
|
||||
++ [randomiseLinks =<< pistolerRoom]
|
||||
-- ++ [randomiseLinks =<< shooterRoom]
|
||||
++ [return $ connectRoom door]
|
||||
-- ++ [return $ connectRoom $ set rmPS [PS (100,100) 0 $ PutCrit explosiveBarrel
|
||||
-- ,PS (105,110) 0 $ PutCrit explosiveBarrel
|
||||
-- ,PS (115,110) 0 $ PutCrit autoCrit
|
||||
-- ,PS (135,110) 0 $ PutCrit explosiveBarrel
|
||||
-- ,PS (105,140) 0 $ PutCrit explosiveBarrel
|
||||
-- ]
|
||||
-- $ roomRect 300 300]
|
||||
++ [randomiseLinks =<< shooterRoom]
|
||||
++ (replicate 3 $ randomiseLinks corridor)
|
||||
++ [return $ connectRoom (set rmPS [PS (20,40) 0 basicLS] corridor)]
|
||||
-- ++ [randomiseLinks =<< longRoom]
|
||||
++ [return $ connectRoom corridor]
|
||||
++ firstWeapon
|
||||
++ (replicate 3 $ randomiseLinks corridor)
|
||||
++ [return $ connectRoom corridor]
|
||||
++[return $ connectRoom corridor,return $ connectRoom door]
|
||||
++ [shootingRange]
|
||||
++ (replicate 3 $ randomiseLinks corridor)
|
||||
++[roomMiniIntro]
|
||||
++ (replicate 3 $ randomiseLinks corridor)
|
||||
++ [return $ connectRoom corridor
|
||||
,return $ connectRoom door
|
||||
,slowDoorRoom]
|
||||
++ [return $ connectRoom corridor
|
||||
,spawnerRoom
|
||||
,return $ connectRoom corridor
|
||||
]
|
||||
)
|
||||
$ randomiseLinks corridor
|
||||
|
||||
|
||||
|
||||
|
||||
generateLevel :: Int -> World -> World
|
||||
generateLevel i w =
|
||||
do haltSound $ ((generateFromTree $ levelTree i) w)
|
||||
|
||||
levelTree :: Int -> State StdGen (Tree Room)
|
||||
levelTree 1 = lev1
|
||||
|
||||
levelPortalAt :: Point2 -> Int -> PressPlate
|
||||
levelPortalAt p x
|
||||
= PressPlate
|
||||
{ _ppPict = onLayer PressPlateLayer $ color blue $ circle 10
|
||||
, _ppPos = p
|
||||
, _ppRot = 0
|
||||
, _ppEvent = \pp w -> if dist (_crPos (you w)) (_ppPos pp) < 10
|
||||
then generateLevel x w
|
||||
else w
|
||||
, _ppID = -1
|
||||
, _ppText = "Portal to level "++ show x
|
||||
}
|
||||
|
||||
-- definition of individual rooms
|
||||
airlockOneWay :: Int -> Room
|
||||
airlockOneWay n = Room
|
||||
{ _rmPolys = [rectNSWE 90 0 0 40]
|
||||
@@ -497,6 +426,8 @@ roomOctogon = Room
|
||||
,((-35,55),3*pi/4)
|
||||
,( (0,40),pi)
|
||||
]
|
||||
allPairs :: Eq a => [a] -> [(a,a)]
|
||||
allPairs xs = [(x,y) | x <- xs, y <- xs, x /= y]
|
||||
|
||||
randomCorridorFrom :: RandomGen g => [a] -> State g (Tree (Either a a))
|
||||
randomCorridorFrom xs = do
|
||||
@@ -504,13 +435,6 @@ randomCorridorFrom xs = do
|
||||
return $ treeTrunk (map Left $ init rooms) (Node (Right (last rooms)) [])
|
||||
|
||||
|
||||
|
||||
--splitWall :: Float -> Wall -> [[Point]]
|
||||
--splitWall x wl =
|
||||
|
||||
sWalls g = wallsFromTree $ evalState (iterateWhile boundClip lev1) $ g
|
||||
|
||||
|
||||
randFirstWeapon :: State StdGen PSType
|
||||
randFirstWeapon = do
|
||||
r <- state $ randomR (-pi,pi)
|
||||
@@ -599,22 +523,6 @@ blockedCorridor = do
|
||||
sequence $ treePost (replicate n $ fmap Left $ randLinks corridor)
|
||||
$ fmap Right $ return $ set rmPS plmnts corridor
|
||||
|
||||
-- weaponBehindV :: RandomGen g => State g (Tree (Either Room Room))
|
||||
-- weaponBehindV = do
|
||||
-- wpPos <- takeOne [(x,y) | x <- [70,-70], y <- [90,230]]
|
||||
-- (ps,_) <- takeNMore 2 ([], [(x,y) | x <- [60,-60], y <- [100,220]])
|
||||
-- r <- state $ randomR (0,pi)
|
||||
-- let crPos1 = ps !! 0
|
||||
-- let crPos2 = ps !! 1
|
||||
-- let d p = argV $ (0,160) -.- p
|
||||
-- let plmnts = [PS wpPos 0 $ RandPS randFirstWeapon
|
||||
-- ,PS crPos1 (d crPos1) $ randC1
|
||||
-- ,PS crPos2 (d crPos2) $ randC1
|
||||
-- ,PS (0,295) r $ PutBlock [5,5,5] (makeColorI 150 75 0 250)
|
||||
-- $ reverse $ rectNSWE 10 (-10) (-10) 10
|
||||
-- ]
|
||||
-- return $ connectRoom $ set rmPS plmnts $ roomVs
|
||||
|
||||
weaponLongCorridor :: RandomGen g => State g (Tree (Either Room Room))
|
||||
weaponLongCorridor = do
|
||||
root <- takeOne $ [tEast, tWest]
|
||||
@@ -662,28 +570,6 @@ roomCCrits = do
|
||||
$ zipWith (+.+) [(x,y) | x<-[110,130,150,170,190], y<- [70,90,110,130,150]] ps
|
||||
return $ connectRoom $ over rmPS (++plmnts) $ roomC 200 200
|
||||
|
||||
--
|
||||
-- roomSwarm :: RandomGen g => State g (Tree (Either Room Room))
|
||||
-- roomSwarm = do
|
||||
-- ps <- sequence $ replicate 25 $ randInCirc 200
|
||||
-- let plmnts = map (\p -> PS ((500,500) +.+ p) 0 $ PutCrit swarmCrit) ps
|
||||
-- return $ connectRoom $ set rmPS plmnts $ roomRect 1000 1000
|
||||
--
|
||||
|
||||
|
||||
roomToLevel2 :: RandomGen g => State g (Tree (Either Room Room))
|
||||
roomToLevel2 = join $ takeOne
|
||||
[ portalRoom1
|
||||
]
|
||||
|
||||
portalRoom1 :: RandomGen g => State g (Tree (Either Room Room))
|
||||
portalRoom1 = return $ connectRoom $ (roomRect 300 300) { _rmPS = plmnts}
|
||||
where plmnts = [PS (0,0) (0-pi/2) $ PutPressPlate (levelPortalAt (200,120) 1)
|
||||
,PS (60,100) pi $ PutCrit autoCrit
|
||||
]
|
||||
|
||||
|
||||
|
||||
branchRectWith :: RandomGen g => State g (Tree (Either Room Room)) -> State g (Tree (Either Room Room))
|
||||
branchRectWith t = do
|
||||
x <- state $ randomR (100,200)
|
||||
@@ -838,7 +724,7 @@ pistolerRoom = do
|
||||
f <- takeOne [f2]
|
||||
h <- state $ randomR (400,800)
|
||||
let w = h
|
||||
i <- takeOne [2,4,6,8]
|
||||
i <- takeOne [4,6,8]
|
||||
let j = fromIntegral (i+1)
|
||||
-- the 20+etc here is to correct for the pathfinding grid, which matches up to
|
||||
-- edges based on the size of doors (i.e. the line next to the wall is 20
|
||||
@@ -887,7 +773,6 @@ shootingRange = do
|
||||
,Left $ roomPadCut (rectNSWE 20 (-20) (-80) 80) (0,20)
|
||||
]
|
||||
(Right rm3)
|
||||
|
||||
|
||||
spawnerRoom :: RandomGen g => State g (Tree (Either Room Room))
|
||||
spawnerRoom = do
|
||||
|
||||
Reference in New Issue
Block a user