HTicTacToe 0.1 → 0.2
raw patch · 2 files changed
+14/−7 lines, 2 files
Files
- HTicTacToe.cabal +2/−2
- Surface.hs +12/−5
HTicTacToe.cabal view
@@ -7,10 +7,10 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.1+Version: 0.2 -- A short (one-line) description of the package.-Synopsis: A tic-tac-toe game.+Synopsis: An SDL tic-tac-toe game. -- A longer description of the package. Description: Another tic-tac-toe game in Haskell using the SDL bindings.
Surface.hs view
@@ -70,21 +70,28 @@ pokeElemOff (castPtr ps :: Ptr Word32) offset pixel where offset = y * (fromIntegral $ surfaceGetPitch s `div` 4) + x +withLock :: MonadIO m => Surface -> m () -> m ()+withLock s act = do+ liftIO $ lockSurface s+ act+ liftIO $ unlockSurface s+ type Point2 = (Int,Int)- data LineDir = Vertical | Horizontal drawLine :: Surface -> Point2 -> Int -> Int -> LineDir -> Pixel -> IO () drawLine dst (x,y) len thickness Horizontal colour =- forM_ [(r,c) | c <- [yStart..yEnd], r <- [x..(x + len)]] $ \(r,c) ->- setPixel32 dst r c colour+ withLock dst $+ forM_ [(r,c) | c <- [yStart..yEnd], r <- [x..(x + len)]] $ \(r,c) ->+ setPixel32 dst r c colour where halfLen = thickness `div` 2 yStart = max (y - halfLen) 0 yEnd = min (yStart + thickness) $ surfaceGetHeight dst drawLine dst (x,y) len thickness Vertical colour =- forM_ [(r,c) | r <- [xStart..xEnd], c <- [y..(y + len)]] $ \(r,c) ->- setPixel32 dst r c colour+ withLock dst $+ forM_ [(r,c) | r <- [xStart..xEnd], c <- [y..(y + len)]] $ \(r,c) ->+ setPixel32 dst r c colour where halfLen = thickness `div` 2 xStart = max (x - halfLen) 0 xEnd = min (xStart + thickness) $ surfaceGetWidth dst