@@ -216,8 +216,8 @@ defaultGame = GameState BetweenRounds
216216
217217stepPaddle delta dir (Paddle y) =
218218 case dir of
219− { Up -> Paddle . clamp 20 (gameHeight-20) $ y - 200 * delta
220− ; Down -> Paddle . clamp 20 (gameHeight-20) $ y + 200 * delta
219+ { Up -> Paddle $ clamp 20 (gameHeight-20) (y - 200 * delta)
220+ ; Down -> Paddle $ clamp 20 (gameHeight-20) (y + 200 * delta)
221221 ; Neutral -> Paddle y
222222 }
223223
@@ -232,13 +232,14 @@ stepPaddle delta dir (Paddle y) =
232232-- who receives the point. Thus, its output is a new Ball and points
233233-- to be added to each player.
234234
235+makePositive n = if n > 0 then n else 0-n
236+makeNegative n = if n > 0 then 0-n else n
237+within epsilon n x = x > n - epsilon && x < n + epsilon
238+
235239stepBall delta (Ball (x,y) (vx,vy)) (Paddle y1) (Paddle y2) =
236− let { makePositive n = if n > 0 then n else 0-n
237− ; makeNegative n = if n > 0 then 0-n else n
238− ; near epsilon n x = x > n - epsilon && x < n + epsilon
239− ; vx' = if near 20 y1 y && near 8 25 x
240+ let { vx' = if within 20 y1 y && within 8 25 x
240241 then makePositive vx else
241− if near 20 y2 y && near 8 (gameWidth - 25) x
242+ if within 20 y2 y && within 8 (gameWidth - 25) x
242243 then makeNegative vx else vx
243244 ; vy' = if y < 7 then makePositive vy else
244245 if y > gameHeight - 7 then makeNegative vy else vy
@@ -248,8 +249,7 @@ stepBall delta (Ball (x,y) (vx,vy)) (Paddle y1) (Paddle y2) =
248249 }
249250 in ( Ball (x',y') (vx',vy')
250251 , if x > gameWidth then 1 else 0
251− , if x < 0 then 1 else 0
252− )
252+ , if x < 0 then 1 else 0 )
253253
254254
255255-- Finally, we define a step function for the entire game. This steps from state to