successful read of map layer
This commit is contained in:
parent
4ea4de78f6
commit
31a58280ae
|
@ -21,6 +21,7 @@ executable pituicat
|
||||||
, Types.Application
|
, Types.Application
|
||||||
, Types.Subsystems
|
, Types.Subsystems
|
||||||
, Types.GameMap
|
, Types.GameMap
|
||||||
|
, Map
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends: base ^>=4.13.0.0
|
build-depends: base ^>=4.13.0.0
|
||||||
, affection
|
, affection
|
||||||
|
@ -29,6 +30,8 @@ executable pituicat
|
||||||
, containers
|
, containers
|
||||||
, linear
|
, linear
|
||||||
, text
|
, text
|
||||||
, elerea
|
, aeson
|
||||||
|
, vector
|
||||||
|
, JuicyPixels
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
|
@ -24,16 +24,16 @@ let
|
||||||
license = stdenv.lib.licenses.lgpl3;
|
license = stdenv.lib.licenses.lgpl3;
|
||||||
}) {};
|
}) {};
|
||||||
|
|
||||||
f = { mkDerivation, base, containers, elerea, linear, stdenv, sdl2, stm
|
f = { mkDerivation, aeson, base, containers, JuicyPixels, linear, stdenv
|
||||||
, text}:
|
, sdl2, stm, text, vector}:
|
||||||
mkDerivation {
|
mkDerivation {
|
||||||
pname = "pituicat";
|
pname = "pituicat";
|
||||||
version = "0.0.0.0";
|
version = "0.0.0.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
isLibrary = false;
|
isLibrary = false;
|
||||||
isExecutable = true;
|
isExecutable = true;
|
||||||
executableHaskellDepends = [ affection base elerea linear containers
|
executableHaskellDepends = [ aeson affection base linear containers
|
||||||
sdl2 stm text];
|
JuicyPixels sdl2 stm text vector];
|
||||||
license = stdenv.lib.licenses.gpl3;
|
license = stdenv.lib.licenses.gpl3;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ main = do
|
||||||
init :: IO GameData
|
init :: IO GameData
|
||||||
init = GameData
|
init = GameData
|
||||||
<$> newTVarIO Loading
|
<$> newTVarIO Loading
|
||||||
|
<*> newTVarIO EmptyData
|
||||||
<*> (Subsystems
|
<*> (Subsystems
|
||||||
<$> (SubWindow <$> newTVarIO [])
|
<$> (SubWindow <$> newTVarIO [])
|
||||||
<*> (SubMouse <$> newTVarIO [])
|
<*> (SubMouse <$> newTVarIO [])
|
||||||
|
|
34
src/Map.hs
34
src/Map.hs
|
@ -1,9 +1,43 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module Map where
|
module Map where
|
||||||
|
|
||||||
import Linear
|
import Linear
|
||||||
|
|
||||||
|
import Codec.Picture
|
||||||
|
|
||||||
|
import qualified Data.Vector as V
|
||||||
|
|
||||||
-- internal imports
|
-- internal imports
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
|
testLevelDesc :: LevelDescriptor
|
||||||
|
testLevelDesc = LevelDescriptor
|
||||||
|
[ (0, "res/maps/00_test/00_test.bmp")
|
||||||
|
]
|
||||||
|
0
|
||||||
|
"res/tiles/00_test/00_test.png"
|
||||||
|
(3, 3)
|
||||||
|
|
||||||
|
-- constructMap :: LevelDescriptor -> IO LevelMap
|
||||||
|
-- cosntructMap desc = do
|
||||||
|
|
||||||
|
readLayer
|
||||||
|
:: (Word, FilePath) -- | index and path of the layer descriptor image
|
||||||
|
-> IO (MapLayer, V2 Int)
|
||||||
|
readLayer (idx, path) = do
|
||||||
|
img <- either error convertRGBA8 <$> readImage path
|
||||||
|
let width = imageWidth img
|
||||||
|
height = imageHeight img
|
||||||
|
layer = V.map
|
||||||
|
(\(py, px) -> case (pixelAt img px py) of
|
||||||
|
(PixelRGBA8 r g b _) -> Tile
|
||||||
|
(V2 (255 - fromIntegral g) (255 - fromIntegral b))
|
||||||
|
(case r of
|
||||||
|
255 -> Solid
|
||||||
|
254 -> Platform
|
||||||
|
_ -> Decoration
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(V.fromList ((,) <$> [0 .. height - 1] <*> [0 .. width - 1]))
|
||||||
|
return (MapLayer layer, V2 width height)
|
||||||
|
|
|
@ -11,11 +11,11 @@ import qualified Data.Map.Strict as M
|
||||||
-- internal imports
|
-- internal imports
|
||||||
|
|
||||||
import Types.Subsystems
|
import Types.Subsystems
|
||||||
import Types.LevelMap
|
import Types.GameMap
|
||||||
|
|
||||||
data GameData = GameData
|
data GameData = GameData
|
||||||
{ gameState :: TVar State
|
{ gameState :: TVar State
|
||||||
, gameStateData :: StateData
|
, gameStateData :: TVar StateData
|
||||||
, gameSubsystems :: Subsystems
|
, gameSubsystems :: Subsystems
|
||||||
, gameActionTranslation :: TVar ActionTranslation
|
, gameActionTranslation :: TVar ActionTranslation
|
||||||
, gameRunning :: TVar Bool
|
, gameRunning :: TVar Bool
|
||||||
|
@ -63,7 +63,8 @@ data Level
|
||||||
|
|
||||||
type ActionTranslation = M.Map SDL.Keycode Action
|
type ActionTranslation = M.Map SDL.Keycode Action
|
||||||
|
|
||||||
data GameStateData
|
data StateData
|
||||||
= TestData
|
= EmptyData
|
||||||
|
| TestData
|
||||||
{ testMap :: LevelMap
|
{ testMap :: LevelMap
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module Types.LevelMap where
|
module Types.GameMap where
|
||||||
|
|
||||||
import Data.Vector
|
import Data.Vector
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ newtype MapLayer = MapLayer
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
data Tile = Tile
|
data Tile = Tile
|
||||||
{ tileOffset :: V2 Float -- | Offset of this tile on the tile map
|
{ tileOffset :: V2 Word -- | Offset of this tile on the tile map
|
||||||
, tileType :: TileType -- | Type of tile
|
, tileType :: TileType -- | Type of tile
|
||||||
}
|
}
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
data TileType
|
data TileType
|
||||||
= Wall
|
= Solid
|
||||||
| Platform
|
| Platform
|
||||||
| Decoration
|
| Decoration
|
||||||
deriving (Enum, Ord, Eq, Show)
|
deriving (Enum, Ord, Eq, Show)
|
||||||
|
@ -35,12 +35,13 @@ data TileMap = TileMap
|
||||||
, tileMapPath :: FilePath -- | Filepath to image
|
, tileMapPath :: FilePath -- | Filepath to image
|
||||||
, tileMapIndex :: Word -- | Index on GPU
|
, tileMapIndex :: Word -- | Index on GPU
|
||||||
}
|
}
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
data LevelDescriptor = LevelDescriptor
|
data LevelDescriptor = LevelDescriptor
|
||||||
{ levelLayerPath :: [(Word, FilePath)] -- | Indexed paths aths to the layers
|
{ levelLayerPath :: [(Word, FilePath)] -- | Indexed paths to the layers
|
||||||
, levelWalkLayer :: Word -- | Index of walk layer
|
, levelWalkLayer :: Word -- | Index of walk layer
|
||||||
, levelTileMap :: FilePath -- | Filepath to tile map
|
, levelTileMap :: FilePath -- | Filepath to tile map
|
||||||
, levelStartPos .. (Word, Word) -- | Player start position
|
, levelStartPos :: (Word, Word) -- | Player start position
|
||||||
-- , levelCollectibles :: [(V2 Word, ())] -- | TODO; Collectibles and their tile coords
|
-- , levelCollectibles :: [(V2 Word, ())] -- | TODO; Collectibles and their tile coords
|
||||||
-- , levelEnemies :: [(V2 Word, ())] -- | TODO: Enemies and their tile coords
|
-- , levelEnemies :: [(V2 Word, ())] -- | TODO: Enemies and their tile coords
|
||||||
-- , levelInteractables :: [(V2 Word, ())] -- | TODO: Interactables and their coords
|
-- , levelInteractables :: [(V2 Word, ())] -- | TODO: Interactables and their coords
|
||||||
|
|
Loading…
Reference in New Issue