From 88ea640a369fdca56821df78cef6e649a33e9de0 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 5 Dec 2023 05:41:16 +0100 Subject: [PATCH] laying some foundations (mostly types) --- flake.nix | 6 ++- {app => src-client}/Main.hs | 0 src-lib/Library/Types.hs | 78 +++++++++++++++++++++++++++++++++++++ src-server/Main.hs | 4 ++ src-server/Server/Map.hs | 19 +++++++++ wizard-wipeout.cabal | 28 +++++++++++-- 6 files changed, 131 insertions(+), 4 deletions(-) rename {app => src-client}/Main.hs (100%) create mode 100644 src-lib/Library/Types.hs create mode 100644 src-server/Main.hs create mode 100644 src-server/Server/Map.hs diff --git a/flake.nix b/flake.nix index f821f51..7e9e911 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,11 @@ let pkgs = nixpkgs.legacyPackages.${system}; - haskellPackages = pkgs.haskellPackages; + haskellPackages = pkgs.haskellPackages.override { + overrides = final: prev: { + #vty-unix = jailbreakUnbreak (pkgs.haskell.lib.dontCheck prev.vty-unix); + }; + }; jailbreakUnbreak = pkg: pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; })); diff --git a/app/Main.hs b/src-client/Main.hs similarity index 100% rename from app/Main.hs rename to src-client/Main.hs diff --git a/src-lib/Library/Types.hs b/src-lib/Library/Types.hs new file mode 100644 index 0000000..91005a5 --- /dev/null +++ b/src-lib/Library/Types.hs @@ -0,0 +1,78 @@ +module Library.Types where + +import Data.Matrix +import Linear +import Graphics.Vty + +-- | Just a type synonym for any kind of position. Translates to a 2D vector +type Position = V2 Float + +-- | Data object for storing player state +data Wizard = Wizard + { wizardPos :: Position + -- ^ Player's position + , wizardRot :: Float + -- ^ Player's view direction + , wizardHealth :: Int + -- ^ Player's hit points + , wizardMana :: Int + -- ^ Player's Mana (magic fuel) + , wizardWands :: [Wand] + -- ^ Player's wands (read: weapons) + , wizardEffect :: [Effect] + -- ^ 'Effect's affecting the player + } + +-- | Data object for storing the client's state +data ClientState = ClientState + { clientVty :: Vty -- ^ Context object for graphics + , clientGameOver :: Bool -- ^ client game over (contestant died) + , clientStop :: Bool -- ^ client shutdown + } + +-- | Data object for storing the server's state +data ServerState = ServerState + { serverGameOver :: Bool -- ^ global game over state (only one contestant left) + , serverStop :: Bool -- ^ Server shutdown + } + +-- | Type synonym for the Map. Translates to a Matrix of 'Tile's +type Map = Matrix Tile + +data Tile + = Air -- ^ walkable area + | Wall -- ^ obstacle + +data ServerOptions = ServerOptions + { serOptMapWidth :: Int -- ^ Map width + , serOptMapHeight :: Int -- ^ Map height + } + +data Arena = Arena + { arenaMap :: Map + , arenaSpawners :: [Spawner] + } + +data Spawner = Spawner + { spawnerPowerup :: Wand -- ^ Which 'Powerup' is being spawned + , spawnerReloadTime :: Int -- ^ How long does it take for the 'Powerup' to reappear + , spawnerPosition :: Position -- ^ Position of the `Spawner` on the map + } + +-- List of all available Wands +data Wand + = HealthUp -- ^ Instant Health boost + | ManaUp -- ^ Instant Mana boost + | Shield -- ^ Magical sield protecting the player + | BigWand -- ^ Stronger Zap spell + | FireWand -- ^ Spell for causing fire damage + | IceWand -- ^ Spell for causing ice damage + +data Effect = Effect + { effectType :: Affliction -- ^ What is happening + , effectTTL :: Float -- ^ remaining time + } + +data Affliction + = Burning -- ^ Damage over time + | Frozen -- ^ Unable to perform any action diff --git a/src-server/Main.hs b/src-server/Main.hs new file mode 100644 index 0000000..65ae4a0 --- /dev/null +++ b/src-server/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/src-server/Server/Map.hs b/src-server/Server/Map.hs new file mode 100644 index 0000000..c7e3164 --- /dev/null +++ b/src-server/Server/Map.hs @@ -0,0 +1,19 @@ +module Server.Map where + +import Library.Types + +-- | This function procedurally generates the Arena for the game +generateArena + :: Int -- ^ Map's width + -> Int -- ^ Map's height + -> Float -- ^ Probability for a tile to be an item spawner + -> IO Arena -- ^ resulting Arena +generateArena arenaWidth arenaHeight spawnerChance = do + undefined + +generateMap + :: Int -- ^ Map's width + -> Int -- ^ Map's height + -> IO Map -- ^ resulting Map +generateMap mapWidth mapHeight = do + undefined diff --git a/wizard-wipeout.cabal b/wizard-wipeout.cabal index 87bc554..346606a 100644 --- a/wizard-wipeout.cabal +++ b/wizard-wipeout.cabal @@ -14,13 +14,35 @@ extra-doc-files: CHANGELOG.md -- extra-source-files: common warnings - ghc-options: -Wall + ghc-options: -Wall -threaded -executable wizard-wipeout +library + import: warnings + exposed-modules: Library.Types + build-depends: base ^>=4.17.2.1 + , linear + , matrix + -- , vty-crossplatform + , vty + hs-source-dirs: src-lib + default-language: GHC2021 + +executable wizard-wipeout-client import: warnings main-is: Main.hs -- other-modules: -- other-extensions: build-depends: base ^>=4.17.2.1 - hs-source-dirs: app + , wizard-wipeout + hs-source-dirs: src-client + default-language: GHC2021 + +executable wizard-wipeout-server + import: warnings + main-is: Main.hs + other-modules: Server.Map + -- other-extensions: + build-depends: base ^>=4.17.2.1 + , wizard-wipeout + hs-source-dirs: src-server default-language: GHC2021