#1 Rendering of level
BIN
assets/entities/door.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/environment/entrance.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/environment/exit.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/environment/tile.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/environment/void.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/environment/wall.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/items/dagger.png
Normal file
After Width: | Height: | Size: 734 B |
BIN
assets/items/key.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
|
@ -5,6 +5,7 @@ import GHC.IO (unsafePerformIO)
|
||||||
import Graphics.Gloss.Juicy (loadJuicyPNG)
|
import Graphics.Gloss.Juicy (loadJuicyPNG)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import Graphics.Gloss.Data.Picture (scale)
|
import Graphics.Gloss.Data.Picture (scale)
|
||||||
|
import Graphics.Gloss.Data.Bitmap (BitmapData(..))
|
||||||
|
|
||||||
----------------------------- Constants ------------------------------
|
----------------------------- Constants ------------------------------
|
||||||
|
|
||||||
|
@ -28,6 +29,15 @@ allEntities = [
|
||||||
("door", "door.png")
|
("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 :: [(String, FilePath)]
|
||||||
allItems = [
|
allItems = [
|
||||||
("dagger", "dagger.png"),
|
("dagger", "dagger.png"),
|
||||||
|
@ -39,7 +49,7 @@ library :: [(String, Picture)]
|
||||||
library = unknown:entities ++ environment ++ gui ++ items
|
library = unknown:entities ++ environment ++ gui ++ items
|
||||||
where unknown = ("unkown", renderPNG (assetsFolder ++ unknownImage))
|
where unknown = ("unkown", renderPNG (assetsFolder ++ unknownImage))
|
||||||
entities = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "entities/" ++ s))) allEntities
|
entities = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "entities/" ++ s))) allEntities
|
||||||
environment = []
|
environment = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "environment/" ++ s))) allEnvironment
|
||||||
gui = []
|
gui = []
|
||||||
items = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "items/" ++ s))) allItems
|
items = map (\(f, s) -> (f, renderPNG (assetsFolder ++ "items/" ++ s))) allItems
|
||||||
|
|
||||||
|
@ -57,6 +67,7 @@ getRender id = get filtered
|
||||||
get [] = snd $ head library
|
get [] = snd $ head library
|
||||||
get ((_, res):_) = res
|
get ((_, res):_) = res
|
||||||
|
|
||||||
|
-- Move a picture by game coordinates
|
||||||
setRenderPos :: Int -> Int -> Picture -> Picture
|
setRenderPos :: Int -> Int -> Picture -> Picture
|
||||||
setRenderPos x y = translate floatX floatY
|
setRenderPos x y = translate floatX floatY
|
||||||
where floatX = fromIntegral x * zoom * resolution
|
where floatX = fromIntegral x * zoom * resolution
|
||||||
|
|
|
@ -1,10 +1,53 @@
|
||||||
module RPGEngine.Render.Level
|
module RPGEngine.Render.Level
|
||||||
( renderLevel
|
( renderLevel
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Graphics.Gloss
|
import Graphics.Gloss
|
||||||
import RPGEngine.Data
|
import RPGEngine.Data
|
||||||
|
import RPGEngine.Render.Core (getRender, setRenderPos, zoom, resolution)
|
||||||
|
|
||||||
-- TODO
|
|
||||||
renderLevel :: Level -> Picture
|
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)
|