diff options
author | Griffin Smith <root@gws.fyi> | 2019-09-10T00·54-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-09-10T00·54-0400 |
commit | 9ebdc6fbb446fea5e505172a6b3dd459beaf3552 (patch) | |
tree | a1403026afb597e12c25e84ef8991f062655e5b8 /src/Xanthous/Generators.hs | |
parent | e01cf9b0565eaa9c09e19f66331a2010aea908cb (diff) |
Convert generated levels to walls
Add support for converting generated levels to walls, and merge one into the entity map at the beginning of the game. There's nothing here that guarantees the character ends up *inside* the level though (they almost always don't) so that'll have to be slotted into the level generation process.
Diffstat (limited to 'src/Xanthous/Generators.hs')
-rw-r--r-- | src/Xanthous/Generators.hs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/Xanthous/Generators.hs b/src/Xanthous/Generators.hs index c266742b0590..740b39c5f082 100644 --- a/src/Xanthous/Generators.hs +++ b/src/Xanthous/Generators.hs @@ -1,14 +1,19 @@ {-# LANGUAGE GADTs #-} - +-------------------------------------------------------------------------------- module Xanthous.Generators where - -import Xanthous.Prelude -import Data.Array.Unboxed -import System.Random (RandomGen) +-------------------------------------------------------------------------------- +import Xanthous.Prelude +import Data.Array.Unboxed +import System.Random (RandomGen) import qualified Options.Applicative as Opt - +-------------------------------------------------------------------------------- import qualified Xanthous.Generators.CaveAutomata as CaveAutomata -import Xanthous.Data (Dimensions) +import Xanthous.Generators.Util +import Xanthous.Data (Dimensions, Position(Position)) +import Xanthous.Data.EntityMap (EntityMap) +import qualified Xanthous.Data.EntityMap as EntityMap +import Xanthous.Entities.Environment +-------------------------------------------------------------------------------- data Generator = CaveAutomata deriving stock (Show, Eq) @@ -52,3 +57,14 @@ showCells arr = row r = foldMap (showCell . (, r)) [minX..maxX] rows = row <$> [minY..maxY] in intercalate "\n" rows + +cellsToWalls :: UArray (Word, Word) Bool -> EntityMap Wall +cellsToWalls cells = foldl' maybeInsertWall mempty . assocs $ cells + where + maybeInsertWall em (pos@(x, y), True) + | not (surroundedOnAllSides pos) = + let x' = fromIntegral x + y' = fromIntegral y + in EntityMap.insertAt (Position x' y') Wall em + maybeInsertWall em _ = em + surroundedOnAllSides pos = numAliveNeighbors cells pos == 8 |