on master help sign in
Make little cosmetic changes.
commit53b2e70afa3dbdc2458f3d0a10bfe75e2698383f authorevancz <info@elm-lang.org> dateTue 21 Aug 2012, 15:24 (14 years ago) parentb5b87f2
2 files changed+13−14
Examples/elm-js/Pong/Pong.elm+9−9 Examples/elm-js/Pong/README.md+4−5
Examples/elm-js/Pong/Pong.elm+9−9
@@ -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
Examples/elm-js/Pong/README.md+4−5
@@ -1,15 +1,14 @@
11
2−Use the arrow keys to move the square around.
3−
42
53To compile this example yourself use:
64
7− elm --import-js="FrameRateHelp.js" FrameRate.elm
5+ elm --import-js="FrameRateHelp.js" Pong.elm
86
97This 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.
119
1210
1311Note: Not all browsers like reading the elm-runtime-x.y.z.js file from
1412an absolute path, so you may have to specify a relative path with
15−the --runtime flag (e.g. --runtime="../../../elm/elm-runtime-0.3.5.js").
13+the --runtime flag (e.g. adding the following to your compile command:
14+`--runtime="../../../elm/elm-runtime-0.3.6.js"`).