2020-12-14 07:00:06 +00:00
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
2020-12-14 02:27:21 +00:00
|
|
|
module Types.Map where
|
2020-10-06 02:19:07 +00:00
|
|
|
|
2020-12-14 07:00:06 +00:00
|
|
|
import qualified Data.Vector as V
|
2020-10-06 02:19:07 +00:00
|
|
|
|
|
|
|
import Linear
|
|
|
|
|
2020-10-12 04:08:33 +00:00
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types.Texture
|
2020-12-14 07:00:06 +00:00
|
|
|
import Types.Graphics.VertexBuffer
|
|
|
|
import Classes.Graphics.Drawable
|
2020-10-12 04:08:33 +00:00
|
|
|
|
2020-10-06 02:19:07 +00:00
|
|
|
data LevelMap = LevelMap
|
2020-12-16 17:57:37 +00:00
|
|
|
{ mapLayers :: V.Vector Layer -- ^ Layer stack
|
|
|
|
, mapWalkLayer :: Word -- ^ Collision layer index in stack
|
|
|
|
, mapDimensions :: V2 Word -- ^ Dimension of map in tiles
|
|
|
|
, mapTileMap :: TileMap -- ^ The tile map
|
|
|
|
, mapStartPos :: V2 Word -- ^ Player start position
|
2020-10-06 02:19:07 +00:00
|
|
|
}
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2020-12-16 17:57:37 +00:00
|
|
|
type Layer = V.Vector Tile
|
2020-12-14 07:00:06 +00:00
|
|
|
|
2020-12-16 17:57:37 +00:00
|
|
|
instance Drawable Layer where
|
|
|
|
|
|
|
|
-- type VertexList Layer = V.Vector
|
2020-12-14 07:00:06 +00:00
|
|
|
|
|
|
|
toVertices vt = V.foldl
|
|
|
|
(\(acci, accv) (mult, a) ->
|
|
|
|
let (ris, vs) = toVertices a
|
|
|
|
is = V.map (mult * 4 +) ris
|
|
|
|
in (acci V.++ is, accv V.++ vs)
|
|
|
|
)
|
|
|
|
(V.empty, V.empty)
|
|
|
|
(V.zip (V.fromList [0 ..]) vt)
|
2020-10-06 02:19:07 +00:00
|
|
|
|
|
|
|
data Tile = Tile
|
2020-12-14 07:00:06 +00:00
|
|
|
{ tilePosition :: V2 Word -- ^
|
|
|
|
, tileOffset :: (V2 Float, V2 Float) -- ^ Graphics offset on 'TileMap'
|
|
|
|
, tileType :: TileType -- ^ Type of tile
|
2020-10-06 02:19:07 +00:00
|
|
|
}
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2020-12-14 07:00:06 +00:00
|
|
|
instance Drawable Tile where
|
|
|
|
|
2020-12-16 17:57:37 +00:00
|
|
|
-- type VertexList Tile = V.Vector
|
2020-12-14 07:00:06 +00:00
|
|
|
|
|
|
|
toVertices (Tile (V2 x y) (V2 u1 v1, V2 u2 v2) _) =
|
|
|
|
( V.fromList [ 0, 1, 2, 2, 3, 0 ]
|
|
|
|
, V.fromList
|
|
|
|
[ newVertex
|
|
|
|
(V3 (fromIntegral x * 32) (fromIntegral y * 32) 0)
|
|
|
|
(V4 0 0 0 1)
|
|
|
|
(V2 u1 v1)
|
2020-12-23 06:47:20 +00:00
|
|
|
0
|
2020-12-14 07:00:06 +00:00
|
|
|
, newVertex
|
|
|
|
(V3 (fromIntegral (x + 1) * 32) (fromIntegral y * 32) 0)
|
|
|
|
(V4 0 0 0 1)
|
|
|
|
(V2 u2 v1)
|
2020-12-23 06:47:20 +00:00
|
|
|
0
|
2020-12-14 07:00:06 +00:00
|
|
|
, newVertex
|
|
|
|
(V3 (fromIntegral (x + 1) * 32) (fromIntegral (y + 1) * 32) 0)
|
|
|
|
(V4 0 0 0 1)
|
|
|
|
(V2 u2 v2)
|
2020-12-23 06:47:20 +00:00
|
|
|
0
|
2020-12-14 07:00:06 +00:00
|
|
|
, newVertex
|
|
|
|
(V3 (fromIntegral x * 32) (fromIntegral (y + 1) * 32) 0)
|
|
|
|
(V4 0 0 0 1)
|
|
|
|
(V2 u1 v2)
|
2020-12-23 06:47:20 +00:00
|
|
|
0
|
2020-12-14 07:00:06 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-10-06 02:19:07 +00:00
|
|
|
data TileType
|
2020-10-09 23:00:33 +00:00
|
|
|
= Solid
|
2020-10-06 02:19:07 +00:00
|
|
|
| Platform
|
|
|
|
| Decoration
|
|
|
|
deriving (Enum, Ord, Eq, Show)
|
|
|
|
|
|
|
|
data TileMap = TileMap
|
2020-12-14 07:00:06 +00:00
|
|
|
{ tileMapDimensions :: V2 Word -- ^ Dimensions of tile map image in pixels
|
|
|
|
, tileMapTexture :: Texture -- ^ Texture object on GPU
|
2020-10-06 02:19:07 +00:00
|
|
|
}
|
2020-10-09 23:00:33 +00:00
|
|
|
deriving (Eq, Show)
|
2020-10-09 03:51:00 +00:00
|
|
|
|
|
|
|
data LevelDescriptor = LevelDescriptor
|
2020-12-14 07:00:06 +00:00
|
|
|
{ levelLayerPath :: [(Word, FilePath)] -- ^ Indexed paths to the layers
|
|
|
|
, levelWalkLayer :: Word -- ^ Index of walk layer
|
|
|
|
, levelTileMap :: FilePath -- ^ Filepath to tile map
|
|
|
|
, levelStartPos :: (Word, Word) -- ^ Player start position
|
|
|
|
-- , levelCollectibles :: [(V2 Word, ())] -- ^ TODO; Collectibles and their tile coords
|
|
|
|
-- , levelEnemies :: [(V2 Word, ())] -- ^ TODO: Enemies and their tile coords
|
|
|
|
-- , levelInteractables :: [(V2 Word, ())] -- ^ TODO: Interactables and their coords
|
2020-10-09 03:51:00 +00:00
|
|
|
}
|
|
|
|
deriving (Eq, Show)
|