on master help sign in
Make little cosmetic changes.
53b2e70evancz
Examples/elm-js/Pong/Pong.elm+9−9
@@ -216,8 +216,8 @@ defaultGame = GameState BetweenRounds
216
216
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
222 }
222 }
223
223
@@ -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.
234
234
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+
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) =
248 }
249 }
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 )
252− )
253
253
254
254
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
Examples/elm-js/Pong/README.md+4−5
@@ -1,15 +1,14 @@
1
1
2−Use the arrow keys to move the square around.
3−
4
2
5To compile this example yourself use:
3To compile this example yourself use:
6
4
7− elm --import-js="FrameRateHelp.js" FrameRate.elm
5+ elm --import-js="FrameRateHelp.js" Pong.elm
8
6
9This compiles the Elm file and includes the necessary JavaScript code.
7This compiles the Elm file and includes the necessary JavaScript code.
10−It produces a self-contained HTML file.
8+It produces a self-contained HTML file called Pong.html.
11
9
12
10
13Note: Not all browsers like reading the elm-runtime-x.y.z.js file from
11Note: Not all browsers like reading the elm-runtime-x.y.z.js file from
14an absolute path, so you may have to specify a relative path with
12an absolute path, so you may have to specify a relative path with
13+the --runtime flag (e.g. adding the following to your compile command:
15−the --runtime flag (e.g. --runtime="../../../elm/elm-runtime-0.3.5.js").
14+`--runtime="../../../elm/elm-runtime-0.3.6.js"`).