#1 Rendering of level

This commit is contained in:
Tibo De Peuter 2022-12-20 23:59:35 +01:00
parent fb4bc5bb36
commit 55212c1440
10 changed files with 58 additions and 4 deletions

BIN
assets/entities/door.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/environment/exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/environment/tile.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/environment/void.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/environment/wall.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/items/dagger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

BIN
assets/items/key.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -5,6 +5,7 @@ import GHC.IO (unsafePerformIO)
import Graphics.Gloss.Juicy (loadJuicyPNG)
import Data.Maybe (fromJust)
import Graphics.Gloss.Data.Picture (scale)
import Graphics.Gloss.Data.Bitmap (BitmapData(..))
----------------------------- Constants ------------------------------
@ -28,6 +29,15 @@ allEntities = [
("door", "door.png")
]
allEnvironment :: [(String, FilePath)]
allEnvironment = [
("void", "void.png"),
("tile", "tile.png"),
("wall", "wall.png"),
("entrance", "entrance.png"),
("exit", "exit.png")
]
allItems :: [(String, FilePath)]
allItems = [
("dagger", "dagger.png"),
@ -39,7 +49,7 @@ library :: [(String, Picture)]
library = unknown:entities ++ environment ++ gui ++ items
where unknown = ("unkown", renderPNG (assetsFolder ++ unknownImage))
entities = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "entities/" ++ s))) allEntities
environment = []
environment = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "environment/" ++ s))) allEnvironment
gui = []
items = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "items/" ++ s))) allItems
@ -57,6 +67,7 @@ getRender id = get filtered
get [] = snd $ head library
get ((_, res):_) = res
-- Move a picture by game coordinates
setRenderPos :: Int -> Int -> Picture -> Picture
setRenderPos x y = translate floatX floatY
where floatX = fromIntegral x * zoom * resolution

View file

@ -1,10 +1,53 @@
module RPGEngine.Render.Level
module RPGEngine.Render.Level
( renderLevel
) where
import Graphics.Gloss
import RPGEngine.Data
import RPGEngine.Render.Core (getRender, setRenderPos, zoom, resolution)
-- TODO
renderLevel :: Level -> Picture
renderLevel _ = text "Level"
renderLevel Level{ layout = l, items = i, entities = e } = level
where level = pictures [void, layout, items, entities]
void = createVoid
layout = renderLayout l
items = renderItems i
entities = renderEntities e
renderLayout :: Layout -> Picture
renderLayout strips = pictures [setRenderPos 0 y (renderStrip (strips !! y)) | y <- [0 .. count]]
where count = length strips - 1
renderStrip :: [Physical] -> Picture
renderStrip list = pictures physicals
where physicals = [setRenderPos x 0 (image (list !! x)) | x <- [0 .. count]]
image Void = getRender "void"
image Walkable = getRender "tile"
image Blocked = getRender "wall"
image Entrance = pictures [getRender "tile", getRender "entrance"]
image Exit = pictures [getRender "tile", getRender "exit"]
count = length list - 1
renderItems :: [Item] -> Picture
renderItems list = pictures $ map renderItem list
renderItem :: Item -> Picture
renderItem Item{ itemId = id, itemX = x, itemY = y} = setRenderPos x y image
where image = getRender id
renderEntities :: [Entity] -> Picture
renderEntities list = pictures $ map renderEntity list
renderEntity :: Entity -> Picture
renderEntity Entity{ entityId = id, entityX = x, entityY = y} = setRenderPos x y image
where image = getRender id
createVoid :: Picture
createVoid = setRenderPos offX offY $ pictures voids
where voids = [setRenderPos x y void | x <- [0 .. width], y <- [0 .. height]]
void = getRender "void"
intZoom = round zoom :: Int
height = round $ 4320 / resolution / zoom
width = round $ 7680 / resolution / zoom
offX = negate (width `div` 2)
offY = negate (height `div` 2)