Skip to content

Instantly share code, notes, and snippets.

@funrep
Created August 11, 2013 11:46
Show Gist options
  • Save funrep/6204507 to your computer and use it in GitHub Desktop.
Save funrep/6204507 to your computer and use it in GitHub Desktop.
I'm writing a pong game, I need some help with the game logic. My problem is that is that I got problems to detect if the ball is out of the map or not, this causes that the ball just gets out-of-bounds and no score is counted. Currently it works like this:
stepScore :: State -> State
stepScore s
| s^.ball.pos.x <= 15 = resetGame $ score.right +~ 1 $ s
| s^.ball.pos.x >= 585 = resetGame $ score.left +~ 1 $ s
| otherwise = s
and resetGame works as such:
resetGame :: State -> State
resetGame s = ball.pos.y .~ 200 $ ball.pos.x .~ 300 $ state .~ Pause $ s
But somehow this doesn't work for some reason. The ball still gets out of the map and the game is basically broken. Full source code is here http://lpaste.net/91745, where the above code is defined at line 107 to 114, and used at line 118.
I would appreciate help, thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment