diff --git a/main.cmi b/main.cmi index 77c23a9..6a4fadd 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmx b/main.cmx index e533716..d8ba04a 100644 Binary files a/main.cmx and b/main.cmx differ diff --git a/main.ml b/main.ml index b904d4e..a62c593 100644 --- a/main.ml +++ b/main.ml @@ -34,6 +34,7 @@ type polygon = { mutable restitution : float ; score : int ; mutable max_hp : int ; + mutable shScore : bool ; mutable hp : int ; } ;; @@ -46,6 +47,7 @@ type sphere = { ymin : float ; ymax : float ; mutable restitution : float ; + mutable shScore : bool ; score : int ; } ;; @@ -85,6 +87,7 @@ let default_polygon = { restitution = 0. ; score = 0 ; max_hp = 1; + shScore = true ; hp = 1 ; } ;; @@ -97,6 +100,7 @@ let default_sphere = { ymin = 1. ; ymax = -. 1. ; restitution = 0. ; + shScore = true ; score = 0 ; } ;; @@ -761,13 +765,29 @@ let draw_float x y n0 r = fill_circle (x + (ln10 ent) * r * 11/7 + 3*r/2) (y - r) 3 ; draw_integer_alignedleft (x + 3*r/5 + (ln10 ent + 1)*r*11/7) y ((100 * frac) / (pw 10 (1+ ln10 frac))) r ;; +let average (arr : pt_2d array) = + let n = Array.length arr in + let (avx, avy) = (Array.fold_left (fun (accx, accy) (elt : pt_2d) -> (accx +. elt.x, accy +. elt.y)) (0., 0.) arr) in + (avx /. float_of_int n, avy /. float_of_int n) ;; + let draw_polygon (poly : polygon) = set_color (rgb (poly.rgb mod 256) ((poly.rgb / 256) mod 256) ((poly.rgb / (256*256)) mod 256)) ; - fill_poly (Array.init (Array.length poly.vertexes) (fun i -> (int_of_float poly.vertexes.(i).x, int_of_float poly.vertexes.(i).y))) ;; + fill_poly (Array.init (Array.length poly.vertexes) (fun i -> (int_of_float poly.vertexes.(i).x, int_of_float poly.vertexes.(i).y))) ; + if poly.score <> 0 && poly.shScore then begin + set_line_width 4 ; + let (cx, cy) = average poly.vertexes in + set_color (rgb (255 - (poly.rgb mod 256)) (255 - ((poly.rgb / 256) mod 256)) (255 - ((poly.rgb / (256*256)) mod 256))) ; + draw_integer (int_of_float cx) (int_of_float cy) poly.score 40 ; + end ;; let draw_sphere (s : sphere) = set_color (rgb (s.rgb mod 256) ((s.rgb / 256) mod 256) ((s.rgb / (256*256)) mod 256)) ; - fill_circle (int_of_float s.center.x) (int_of_float s.center.y) (int_of_float s.radius) ;; + fill_circle (int_of_float s.center.x) (int_of_float s.center.y) (int_of_float s.radius) ; + if s.score <> 0 && s.shScore then begin + set_line_width 4 ; + set_color (rgb (255 - (s.rgb mod 256)) (255 - ((s.rgb / 256) mod 256)) (255 - ((s.rgb / (256*256)) mod 256))) ; + draw_integer (int_of_float s.center.x) (int_of_float s.center.y) s.score (int_of_float (1.8 *. s.radius)) ; + end ;; let draw_flipper (f : flipper) = set_color (rgb 64 64 64) ; @@ -822,7 +842,7 @@ let create_ball (r : float) (x0 : int) (y0 : int) (m : float) (red : int) (green fres = {x = 0. ; y = 0.} ; } ;; -let create_polygon (arr : (int * int) array) (rest : float) (pts : int) (red : int) (green : int) (blue : int) = +let create_polygon ?showScore:(shsc=true) (arr : (int * int) array) (rest : float) (pts : int) (red : int) (green : int) (blue : int) = { vertexes = Array.init (Array.length arr) (fun k -> {x = float_of_int (fst arr.(k)); y = float_of_int (snd arr.(k))}) ; rgb = red + 256 * green + 256 * 256 * blue ; @@ -833,10 +853,11 @@ let create_polygon (arr : (int * int) array) (rest : float) (pts : int) (red : i restitution = rest ; score = pts ; max_hp = 1; + shScore = shsc ; hp = 1 } ;; -let create_destructible (arr : (int * int) array) (rest : float) (pts : int) (hitp : int) (red : int) (green : int) (blue : int) = +let create_destructible ?showScore:(shsc=true) (arr : (int * int) array) (rest : float) (pts : int) (hitp : int) (red : int) (green : int) (blue : int) = { vertexes = Array.init (Array.length arr) (fun k -> {x = float_of_int (fst arr.(k)); y = float_of_int (snd arr.(k))}) ; rgb = red + 256 * green + 256 * 256 * blue ; @@ -847,10 +868,11 @@ let create_destructible (arr : (int * int) array) (rest : float) (pts : int) (hi restitution = rest ; score = pts ; max_hp = hitp; + shScore = shsc ; hp = hitp } ;; -let create_sphere (x00 : int) (y00 : int) (rd : float) (rest : float) (pts : int) (red : int) (green : int) (blue : int) = +let create_sphere ?showScore:(shsc=true) (x00 : int) (y00 : int) (rd : float) (rest : float) (pts : int) (red : int) (green : int) (blue : int) = let x0 = float_of_int x00 and y0 = float_of_int y00 in { center = {x = x0 ; y = y0}; @@ -861,6 +883,7 @@ let create_sphere (x00 : int) (y00 : int) (rd : float) (rest : float) (pts : int ymin = y0 -. rd ; ymax = y0 +. rd ; restitution = rest ; + shScore = shsc ; score = pts ; } ;; @@ -927,6 +950,7 @@ let customize lvl_name = restitution = 1. ; score = 0 ; max_hp = 1; + shScore = false ; hp = 1; } ; cpoly.len <- 0 ; diff --git a/main.o b/main.o index 6a205ef..31eb83c 100644 Binary files a/main.o and b/main.o differ diff --git a/pinball b/pinball index c0ccf10..e44457f 100755 Binary files a/pinball and b/pinball differ