I'm writing a pong game, I need some help with the game logic. My problem is that is that I got trouble when detecting 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
The reason for the constants is that the game dimensions is 600x400 and the ball is 15 pixels wide and the position is in its core. 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.
So, my question is as follows; how can I write this so it works, basically, so the game resets and score is given to each player as intended when the ball is out-of-bounds? 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.
EDIT: I tried different constants in stepScore, and stepScore IS the problem, it doesn't work for some reason. :(
Code blidness... I forgot to put stepScore in the 'Play'-state.