Skip to content

Instantly share code, notes, and snippets.

@funrep
Created July 29, 2013 16:09
Show Gist options
  • Save funrep/6105461 to your computer and use it in GitHub Desktop.
Save funrep/6105461 to your computer and use it in GitHub Desktop.
import Prelude hiding (Either(..))
import FRP.Helm
data Direction = Left | Right
data Mario =
Mario { mX :: Double, mY :: Double,
vX :: Double, vY :: Double,
dir :: Direction }
jump :: (Int, Int) -> Mario -> Mario
jump (_, y) m@(Mario mX1 mY1 vX1 vY1 dir1)
| y > 0 && mY1 == 0 = Mario { mX = mX1, mY = mY1, vX = vX1, vY = 5, dir = dir1 }
| otherwise = m
gravity :: Time -> Mario -> Mario
gravity t m@(Mario mX1 mY1 vX1 vY1 dir1)
| mY1 > 0 = Mario { mX = mX1, mY = mY1, vX = vX1, vY = vY1 - (t/4), dir = dir1 }
| otherwise = m
physics :: Time -> Mario -> Mario
physics t (Mario mX1 mY1 vX1 vY1 dir1)
= Mario { mX = mX1 + (t*vX1), mY = max 0 (mY1 + (t*vY1)), vX = vX1, vY = vY1, dir = dir1 }
walk :: (Int, Int) -> Mario -> Mario
walk (x, _) (Mario mX1 mY1 vX1 vY1 dir1) =
Mario { mX = mX1, mY = mY1, vX = x, vY = vY1, dir = whatDir x }
where
whatDir x
| x < 0 = Left
| x > 0 = Right
| otherwise = dir1
step :: (Time, (Int, Int)) -> Mario -> Mario
step (t, arrows) = physics t . walk arrows . gravity t . jump arrows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment