File tree 3 files changed +19
-17
lines changed
3 files changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -10,24 +10,23 @@ let update_state (state : G.state) =
10
10
let b = state.ball in
11
11
let new_x = b.x +. b.dx in
12
12
let new_y = b.y +. b.dy in
13
- let new_x =
14
- if new_x < 0. then 0.
15
- else if new_x > float state.width then float state.width
16
- else new_x
13
+ let x, dx =
14
+ if new_x -. b.radius < 0. then (b.radius, -. b.dx)
15
+ else if new_x +. b.radius > float state.width then
16
+ (float state.width -. b.radius, -. b.dx)
17
+ else (new_x, b.dx)
17
18
in
18
- let new_y =
19
- if new_y < 0. then 0.
20
- else if new_y > float state.height then float state.height
21
- else new_y
19
+ let y, dy =
20
+ if new_y -. b.radius < 0. then (b.radius, -. b.dy)
21
+ else if new_y +. b.radius > float state.height then
22
+ (float state.height -. b.radius, -. b.dy)
23
+ else (new_y, b.dy)
22
24
in
23
- {
24
- state with
25
- ball = { x = new_x; y = new_y; radius = b.radius; dx = b.dx; dy = b.dy };
26
- }
25
+ { state with ball = { x; y; radius = b.radius; dx; dy } }
27
26
28
27
let rec game_loop (state : G.state ) =
29
- let fps = 2 . in
30
- (* 2 frames per second *)
28
+ let fps = 60 . in
29
+ (* frames per second *)
31
30
Lwt_unix. sleep (1. /. fps) >> = fun () ->
32
31
let new_state = update_state state in
33
32
let sexp = G. sexp_of_server_message (Update new_state) in
Original file line number Diff line number Diff line change @@ -49,8 +49,11 @@ let animate ctx canvas =
49
49
(* Draw ball *)
50
50
ctx##beginPath ;
51
51
ctx##arc ! ball.x ! ball.y ! ball.radius 0. (2. *. Float. pi) Js. _false;
52
- ctx##.fillStyle := Js. string " green " ;
52
+ ctx##.fillStyle := Js. string " white " ;
53
53
ctx##fill ;
54
+ ctx##.lineWidth := Js. float 4. ;
55
+ ctx##.strokeStyle := Js. string " black" ;
56
+ ctx##stroke ;
54
57
ctx##closePath ;
55
58
56
59
(* Request next animation frame *)
Original file line number Diff line number Diff line change 59
59
canvas {
60
60
background-color : var (--basquiat-bg );
61
61
border : 3px solid var (--basquiat-black );
62
- padding : 10 px ;
62
+ padding : 0 px ;
63
63
box-shadow :
64
64
-4px -4px 0 var (--basquiat-red ),
65
65
4px 4px 0 var (--basquiat-green );
111
111
< body >
112
112
</ body >
113
113
114
- </ html >
114
+ </ html >
You can’t perform that action at this time.
0 commit comments