gross 0.0.0.0 → 0.1.0.0
raw patch · 4 files changed
+59/−8 lines, 4 filesdep +grossdep +lensnew-component:exe:example
Dependencies added: gross, lens
Files
- Graphics/Gross.hs +6/−5
- LICENSE +1/−1
- example/Example.hs +40/−0
- gross.cabal +12/−2
Graphics/Gross.hs view
@@ -12,14 +12,14 @@ updateWindow screen $ do (nrows, ncols) <- windowSize void $ sequence $ do- x <- [0 .. nrows - 2]- y <- [0 .. ncols - 1]+ x <- [1 .. nrows - 2]+ y <- [1 .. ncols - 2] pure $ do moveCursor x y drawString [f x y] roguelike :: (world -> Integer -> Integer -> Char)- -> (world -> Event -> world)+ -> (world -> Event -> Update world) -> world -> Integer -> Curses ()@@ -31,5 +31,6 @@ me <- getEvent s (Just n) case me of Nothing -> roguelike f e w n- Just event -> roguelike f e (e w event) n-+ Just event -> do+ x <- updateWindow s (e w event)+ roguelike f e x n
LICENSE view
@@ -1,4 +1,4 @@-Copyright <YEAR> <COPYRIGHT HOLDER>+Copyright 2017 Samuel Schlesinger Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ example/Example.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE TemplateHaskell, RecordWildCards, LambdaCase #-}++import Graphics.Gross+import UI.NCurses+import Control.Monad.Trans+import Control.Lens++data Config = Config { _width :: Integer, _height :: Integer }+makeLenses ''Config++data Player = Player { _playerX :: Integer, _playerY :: Integer }+makeLenses ''Player++data World = World { _config :: Config, _player :: Player, _stones :: Integer -> Integer -> Bool }+makeLenses ''World++consistent :: World -> Bool+consistent world = let + Config w h = world^.config+ Player x y = world^.player in (world^.stones) x y && x <= w && x >= 1 && y <= h && y >= 1++displayWorld :: World -> Integer -> Integer -> Char+displayWorld world y x + | world^.player.playerX == x && world^.player.playerY == y = '&'+ | (world^.stones) x y = 'O'+ | otherwise = ' '++eventWorld :: World -> Event -> Update World+eventWorld world = \case+ EventSpecialKey k -> case k of+ KeyUpArrow -> pure $ snd ((player.playerY <-~ 1) world) + KeyDownArrow -> pure $ snd ((player.playerY <+~ 1) world)+ KeyLeftArrow -> pure $ snd ((player.playerX <-~ 1) world)+ KeyRightArrow -> pure $ snd ((player.playerX <+~ 1) world) ++main = runCurses $ do+ s <- defaultWindow+ (w, h) <- updateWindow s windowSize+ let init = World (Config (w - 2) (h - 2)) (Player (w `div` 2) (h `div` 2)) (\x y -> if x `mod` 4 == 0 && y `mod` 3 == 2 then True else False)+ roguelike displayWorld eventWorld init 300
gross.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: gross-version: 0.0.0.0+version: 0.1.0.0 synopsis: A spoof on gloss for terminal animation description: An easy way to make terminal interfaces license: MIT@@ -13,7 +13,17 @@ build-type: Simple cabal-version: >=1.10 +source-repository head+ type: git+ location: https://github.com/SamuelSchlesinger/gross++executable example+ main-is: Example.hs+ build-depends: gross, base >=4.8 && <4.10, ncurses >= 0.2 && < 0.3, mtl, lens+ hs-source-dirs: example+ default-language: Haskell2010+ library exposed-modules: Graphics.Gross- build-depends: base >=4.0 && <4.10, ncurses >= 0.2 && < 0.3, mtl+ build-depends: base >=4.8 && <4.10, ncurses >= 0.2 && < 0.3, mtl default-language: Haskell2010