Skip to content

Instantly share code, notes, and snippets.

@cesardeazevedo
Created October 21, 2014 17:22
Show Gist options
  • Save cesardeazevedo/c42cad6a163190ace18d to your computer and use it in GitHub Desktop.
Save cesardeazevedo/c42cad6a163190ace18d to your computer and use it in GitHub Desktop.
Helm Translate
{-
- Haskell experiment with functional reactive programming game engine Helm.
- just a basic square with x position and speed property, translating on the x axis.
-
- run:
- ghc translate.hs
- ./translate
-}
module Main where
import FRP.Helm
import qualified FRP.Helm.Time as Time
import qualified FRP.Helm.Window as Window
data Box = Box { x :: Double, speed :: Double }
update :: Time -> Double -> Double
update dt n = n + Time.inSeconds dt
translate :: Double -> Box -> Box
translate _x _box = _box { x = ( speed _box * _x ) }
render :: Double -> (Int, Int) -> Element
render delta (w, h) = collage w h [ move ( x $ translate delta initialBox, 225 ) $ rotate ( angle ) $ filled red $ square 64 ]
where
angle = delta * 12
initialBox = Box { x = 0, speed = 50 * delta }
main :: IO()
main = do
engine <- startup config
run engine $ render <~ stepper ~~ Window.dimensions engine
where
config = defaultConfig { windowTitle = "Translate",
windowDimensions = (650, 450),
windowIsFullscreen = False,
windowIsResizable = True
}
stepper = foldp update 0 $ Time.delay $ Time.fps $ 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment