laying some foundations (mostly types)

This commit is contained in:
nek0 2023-12-05 05:41:16 +01:00
parent 7650fb306c
commit 88ea640a36
6 changed files with 131 additions and 4 deletions

View file

@ -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 = { }; }));

78
src-lib/Library/Types.hs Normal file
View file

@ -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

4
src-server/Main.hs Normal file
View file

@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, Haskell!"

19
src-server/Server/Map.hs Normal file
View file

@ -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

View file

@ -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