Created
June 13, 2012 09:54
-
-
Save scan/2923143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Arrows #-} | |
module Tile where | |
import Control.Arrow | |
import Control.Monad (void) | |
import FRP.Yampa | |
import Graphics.UI.SDL (Rect(..), blitSurface, Surface) | |
data Tile = Tile !Rect Bool | |
| AnimatedTile ![Rect] Bool | |
parallel f = proc xs -> do{ case xs of [] -> returnA -< [] ; (h:ts) -> arr (uncurry (:)) <<< f *** parallel f -< (h, ts) } | |
curRects :: SF [Tile] [Rect] | |
curRects = proc ts -> do | |
rec | |
i <- delay 0.2 0 -< i + 1 | |
returnA -< map (rects i) ts | |
where | |
rects _ (Tile r _) = r | |
rects i (AnimatedTile rs _) = cycle rs !! i | |
walkable :: Tile -> Bool | |
walkable (Tile _ w) = w | |
walkable (AnimatedTile _ w) = w | |
drawTiles :: SF [Tile] (Surface -> Surface -> [(Int, Int)] -> IO ()) | |
drawTiles = proc t -> do | |
rs <- curRects -< t | |
returnA -< \src dst -> sequence_ . zipWith ($) (map (drawTile' src dst) rs) | |
where drawTile' sSrc sDst (Rect sx sy w h) (x,y) = void $ blitSurface sSrc (Just $ Rect sx sy w h) sDst (Just $ Rect x y w h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment