Created
November 9, 2013 00:07
-
-
Save funrep/7379644 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 RankNTypes #-} | |
import Reactive.Banana | |
import Reactive.Banana.Frameworks | |
import qualified Graphics.UI.SDL as SDL | |
import qualified Graphics.UI.SDL.Image as Image | |
main = do | |
SDL.init [SDL.InitEverything] | |
SDL.rawSetCaption (Just "foobar") Nothing | |
SDL.setVideoMode 640 480 32 [] | |
img <- Image.load "foo.png" | |
let gameLoop :: IO () | |
gameLoop = do | |
(mouseHandler, fire) <- newAddHandler | |
let | |
processMouse = (SDL.getMouseState >>= \(x, y, _) -> return (x, y)) >>= fire | |
go = processMouse >> go | |
network <- compile $ do | |
eMouse <- fromAddHandler mouseHandler | |
reactimate $ fmap (render img) eMouse | |
actuate network | |
go | |
gameLoop | |
render :: SDL.Surface -> (Int, Int) -> IO () | |
render img (x, y) = do | |
surf <- SDL.getVideoSurface | |
SDL.blitSurface img (Just (SDL.Rect (x-25) (y-25) 50 50)) surf Nothing | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment