diff --git a/pituicat.cabal b/pituicat.cabal index 3a91887..0dfef9a 100644 --- a/pituicat.cabal +++ b/pituicat.cabal @@ -21,6 +21,7 @@ executable pituicat , Types.Application , Types.Subsystems , Types.GameMap + , Map -- other-extensions: build-depends: base ^>=4.13.0.0 , affection @@ -29,6 +30,8 @@ executable pituicat , containers , linear , text - , elerea + , aeson + , vector + , JuicyPixels hs-source-dirs: src default-language: Haskell2010 diff --git a/shell.nix b/shell.nix index 4d6e217..1234c68 100644 --- a/shell.nix +++ b/shell.nix @@ -24,16 +24,16 @@ let license = stdenv.lib.licenses.lgpl3; }) {}; - f = { mkDerivation, base, containers, elerea, linear, stdenv, sdl2, stm - , text}: + f = { mkDerivation, aeson, base, containers, JuicyPixels, linear, stdenv + , sdl2, stm, text, vector}: mkDerivation { pname = "pituicat"; version = "0.0.0.0"; src = ./.; isLibrary = false; isExecutable = true; - executableHaskellDepends = [ affection base elerea linear containers - sdl2 stm text]; + executableHaskellDepends = [ aeson affection base linear containers + JuicyPixels sdl2 stm text vector]; license = stdenv.lib.licenses.gpl3; }; diff --git a/src/Main.hs b/src/Main.hs index f09e900..eb537ef 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -49,6 +49,7 @@ main = do init :: IO GameData init = GameData <$> newTVarIO Loading + <*> newTVarIO EmptyData <*> (Subsystems <$> (SubWindow <$> newTVarIO []) <*> (SubMouse <$> newTVarIO []) diff --git a/src/Map.hs b/src/Map.hs index 4adff66..21fcd60 100644 --- a/src/Map.hs +++ b/src/Map.hs @@ -1,9 +1,43 @@ +{-# LANGUAGE OverloadedStrings #-} module Map where import Linear +import Codec.Picture + +import qualified Data.Vector as V + -- internal imports 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) diff --git a/src/Types/Application.hs b/src/Types/Application.hs index 1b29ab0..6bfeb95 100644 --- a/src/Types/Application.hs +++ b/src/Types/Application.hs @@ -11,11 +11,11 @@ import qualified Data.Map.Strict as M -- internal imports import Types.Subsystems -import Types.LevelMap +import Types.GameMap data GameData = GameData { gameState :: TVar State - , gameStateData :: StateData + , gameStateData :: TVar StateData , gameSubsystems :: Subsystems , gameActionTranslation :: TVar ActionTranslation , gameRunning :: TVar Bool @@ -63,7 +63,8 @@ data Level type ActionTranslation = M.Map SDL.Keycode Action -data GameStateData - = TestData +data StateData + = EmptyData + | TestData { testMap :: LevelMap } diff --git a/src/Types/GameMap.hs b/src/Types/GameMap.hs index 7a4cd96..47a6699 100644 --- a/src/Types/GameMap.hs +++ b/src/Types/GameMap.hs @@ -1,4 +1,4 @@ -module Types.LevelMap where +module Types.GameMap where import Data.Vector @@ -19,13 +19,13 @@ newtype MapLayer = MapLayer deriving (Eq, Show) 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 } deriving (Eq, Show) data TileType - = Wall + = Solid | Platform | Decoration deriving (Enum, Ord, Eq, Show) @@ -35,12 +35,13 @@ data TileMap = TileMap , tileMapPath :: FilePath -- | Filepath to image , tileMapIndex :: Word -- | Index on GPU } + deriving (Eq, Show) 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 , 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 -- , levelEnemies :: [(V2 Word, ())] -- | TODO: Enemies and their tile coords -- , levelInteractables :: [(V2 Word, ())] -- | TODO: Interactables and their coords