Skip to content

Instantly share code, notes, and snippets.

@funrep
Created November 9, 2013 00:07
Show Gist options
  • Save funrep/7379644 to your computer and use it in GitHub Desktop.
Save funrep/7379644 to your computer and use it in GitHub Desktop.
{-# 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