Skip to content

Instantly share code, notes, and snippets.

@tarquin-the-brave
Created May 12, 2020 13:23
Show Gist options
  • Select an option

  • Save tarquin-the-brave/f05a70ca102ace1c436e7ccd726e99c0 to your computer and use it in GitHub Desktop.

Select an option

Save tarquin-the-brave/f05a70ca102ace1c436e7ccd726e99c0 to your computer and use it in GitHub Desktop.
data LiveData = LiveData {
-- x-coordinate of the ball - xb
xb::Int,
-- x-coordinate of the paddle - xp
xp::Int,
-- Game score - sc
sc::Int
} deriving(Show)
stepGame' :: [Int] -> Game -> (LiveData, Game)
stepGame :: [Int] -> State Game LiveData
stepGame = state . stepGame'
playGame :: [Int] -> State Game Int
playGame inp = do
liveData <- stepGame inp
game <- get
case IC.progState (gameProg game) of
IC.AwaitInput -> playGame [joystick (xb liveData) (xp liveData)]
_ -> return $ sc liveData
joystick :: Int -> Int -> Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment