@@ -216,8 +216,8 @@ defaultGame = GameState BetweenRounds
217stepPaddle delta dir (Paddle y) =
217stepPaddle delta dir (Paddle y) =
218 case dir of
218 case dir of
219− { Up -> 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
220+ ; Down -> Paddle $ clamp 20 (gameHeight-20) (y + 200 * delta)
221 ; Neutral -> Paddle y
221 ; Neutral -> Paddle y
@@ -232,13 +232,14 @@ stepPaddle delta dir (Paddle y) =
232-- who receives the point. Thus, its output is a new Ball and points
232-- who receives the point. Thus, its output is a new Ball and points
233-- to be added to each player.
233-- to be added to each player.
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
235stepBall delta (Ball (x,y) (vx,vy)) (Paddle y1) (Paddle y2) =
239stepBall 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
240 then makePositive vx else
241 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
242 then makeNegative vx else vx
243 then makeNegative vx else vx
243 ; vy' = if y < 7 then makePositive vy else
244 ; vy' = if y < 7 then makePositive vy else
244 if y > gameHeight - 7 then makeNegative vy else vy
245 if y > gameHeight - 7 then makeNegative vy else vy
@@ -248,8 +249,7 @@ stepBall delta (Ball (x,y) (vx,vy)) (Paddle y1) (Paddle y2) =
249 in ( Ball (x',y') (vx',vy')
250 in ( Ball (x',y') (vx',vy')
250 , if x > gameWidth then 1 else 0
251 , if x > gameWidth then 1 else 0
251− , if x < 0 then 1 else 0
252+ , if x < 0 then 1 else 0 )
255-- Finally, we define a step function for the entire game. This steps from state to
255-- Finally, we define a step function for the entire game. This steps from state to