Skip to content

Instantly share code, notes, and snippets.

@jeffreybaird
Created April 15, 2016 19:33
Show Gist options
  • Save jeffreybaird/18df3b1b410dc1a5b25ff7ead3b1e378 to your computer and use it in GitHub Desktop.
Save jeffreybaird/18df3b1b410dc1a5b25ff7ead3b1e378 to your computer and use it in GitHub Desktop.
Pertinent functions to breakout
type alias Game =
{
state : State
, player : Player
}
type State = Play | Pause
type alias Player =
Object {score : Int}
type alias Object a =
{ a |
x : Float
, y : Float
, vx : Float
, vy : Float
}
stepGame : Input -> Game -> Game
stepGame input game =
let
{paddle,delta} = input
{state,player} = game
player' = stepPlayer delta player
in
{game | player = player'}
stepPlayer : Time.Time -> Player -> Player
stepPlayer(time, player) =
let player' = stepObj time { player | vx = toFloat 300 }
x' = clamp (22-halfHeight) (halfHeight-22) player'.x
score' = player.score + 1
in
{ player' | x = x', score = score' }
gameState : Signal Game
gameState =
Signal.foldp stepGame defaultGame input
main : Signal Graphics.Element.Element
main =
Signal.map2 display Window.dimensions gameState
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment