diff --git a/main.cmi b/main.cmi index 9db80ab..1e16ca6 100644 Binary files a/main.cmi and b/main.cmi differ diff --git a/main.cmx b/main.cmx index c3e5123..98296f6 100644 Binary files a/main.cmx and b/main.cmx differ diff --git a/main.ml b/main.ml index 6ff4702..1ddfa34 100644 --- a/main.ml +++ b/main.ml @@ -10,7 +10,14 @@ Random.self_init () ;; exception ReturnBool of bool ;; exception ReturnInt of int ;; -exception HasEnded ;; +exception ReturnIntArr of int array ;; + +let __width__ = 1200 +and __height__ = 800 ;; + +let __istr__ = " 1200x800" ;; + +let univ_dt = 0.003 ;; type pt_2d = { mutable x : float ; @@ -41,6 +48,7 @@ type sphere = { } ;; type ball = { + mutable active : bool ; radius : float ; mass : float ; rgb : int ; @@ -96,6 +104,7 @@ let winball = { let gforce = {x = 0. ; y = -. univ_g} ;; let score = ref 0 ;; +let epsilon = ref (1. /. 131072.) ;; (* ------------------------------------------------------------------------------------- *) (* ------------------------------------------------------------------------------------- *) @@ -107,12 +116,12 @@ let beep_boop = Array.make n_threads false ;; let beep_id = ref 0 ;; let playbeep id = - while true do + while false do if beep_boop.(id) then begin - beep_boop.(id) <- false ; ignore (Unix.system "./sound wah/scored_hit.wav") ; + beep_boop.(id) <- false ; end; - Unix.sleepf 0.005 ; + Unix.sleepf univ_dt ; done;; let beep_list = Array.init n_threads (fun k -> Thread.create playbeep k) ;; @@ -120,7 +129,7 @@ let beep_list = Array.init n_threads (fun k -> Thread.create playbeep k) ;; (**) let play_music () = - while true do + while false do ignore (Unix.system "./sound wah/wah_metal.wav") ; ignore (Unix.system "./sound wah/wah_eurobeat.wav") ; ignore (Unix.system "./sound wah/wah_hardcore.wav") ; @@ -362,15 +371,19 @@ let update_ball_data (b : ball) (polys : polygon array) (spheres : sphere array) if polys.(p).score > 0 then playbeep () ; + if polys.(p).restitution = 0. then + b.active <- false ; (* apply normal reaction force *) let hit2 = (hit +1) mod (Array.length polys.(p).vertexes) in let proj = return_proj_of_point b.xy polys.(p).vertexes.(hit) polys.(p).vertexes.(hit2) in let proj_n = vect_normalize_2D (vect_diff_2D b.xy proj) in - let reaction_force_2 = vect_mult_2D proj_n (univ_g *. b.mass *. (vect_dot_product_2D (vect_normalize_2D gforce) proj_n)) in - - b.fres.x <- b.fres.x +. reaction_force_2.x *. polys.(p).restitution ; - b.fres.y <- b.fres.y +. reaction_force_2.y *. polys.(p).restitution ; + let scal = (vect_dot_product_2D (vect_normalize_2D gforce) proj_n) in + if scal > 0. then begin + let reaction_force_2 = vect_mult_2D proj_n (univ_g *. b.mass *. scal) in + b.fres.x <- b.fres.x +. reaction_force_2.x *. polys.(p).restitution ; + b.fres.y <- b.fres.y +. reaction_force_2.y *. polys.(p).restitution ; + end; (* change velocity according to angle *) let director = vect_diff_2D polys.(p).vertexes.(hit2) polys.(p).vertexes.(hit) in @@ -387,13 +400,17 @@ let update_ball_data (b : ball) (polys : polygon array) (spheres : sphere array) if spheres.(s).score > 0 then playbeep () ; + if spheres.(s).restitution = 0. then + b.active <- false ; (* apply normal reaction force *) let proj_n = vect_normalize_2D (vect_diff_2D b.xy spheres.(s).center) in - let reaction_force_2 = vect_mult_2D proj_n (univ_g *. b.mass *. (vect_dot_product_2D (vect_normalize_2D gforce) proj_n)) in - - b.fres.x <- b.fres.x +. reaction_force_2.x *. spheres.(s).restitution ; - b.fres.y <- b.fres.y +. reaction_force_2.y *. spheres.(s).restitution ; + let scal = (vect_dot_product_2D (vect_normalize_2D gforce) proj_n) in + if scal > 0. then begin + let reaction_force_2 = vect_mult_2D proj_n (univ_g *. b.mass *. scal) in + b.fres.x <- b.fres.x +. reaction_force_2.x *. spheres.(s).restitution *. 1.1 ; + b.fres.y <- b.fres.y +. reaction_force_2.y *. spheres.(s).restitution *. 1.1 ; + end; (* change velocity according to angle *) let theta = b.radius /. (vect_norm_2D (vect_diff_2D b.xy spheres.(s).center)) in @@ -421,7 +438,8 @@ let update_ball_data (b : ball) (polys : polygon array) (spheres : sphere array) let update_balls (bl : ball array) (polys : polygon array) (spheres : sphere array) (dt : float) = for b = 0 to Array.length bl -1 do - update_ball_data bl.(b) polys spheres dt + if bl.(b).active then + update_ball_data bl.(b) polys spheres dt done ;; (* ------------------------------------------------------------------------------------- *) @@ -525,7 +543,8 @@ let draw_ball (b : ball) = let draw_all_balls (bs : ball array) = for k = 0 to Array.length bs -1 do - draw_ball bs.(k) + if bs.(k).active then + draw_ball bs.(k) done ;; (* ------------------------------------------------------------------------------------- *) @@ -540,6 +559,7 @@ let get1char_plus () = let create_ball (r : float) (x0 : int) (y0 : int) (m : float) (red : int) (green : int) (blue : int) = { + active = true ; radius = r ; rgb = red + 256 * green + 256 * 256 * blue ; mass = m; @@ -583,7 +603,7 @@ let generate_pinballs (count : int) (r : float) (x0 : int) (y0 : int) (m : float (* WALUIGI_TIME Edition functions *) let customize lvl_name = - open_graph " 1200x800" ; + open_graph __istr__ ; set_window_title "WAH" ; let (res : polygon dynamic) = dyn_create default_polygon in @@ -593,7 +613,7 @@ let customize lvl_name = let (cpoly : pt_2d dynamic) = dyn_create {x = 0. ; y = 0.} in while not !stopped do - Unix.sleepf 0.005 ; + Unix.sleepf univ_dt ; if !refresh then begin auto_synchronize false ; @@ -642,10 +662,10 @@ let customize lvl_name = (* WALUIGI_TIME Main *) let simulate (data : polygon dynamic) (dats : sphere dynamic) = - open_graph " 1200x800" ; + open_graph __istr__ ; set_window_title "WAH" ; - let pinballs = generate_pinballs 3 20.0 600 700 0.15 255 255 0 in + let pinballs = generate_pinballs 100 10.0 600 800 0.15 255 255 0 in let stime = Unix.gettimeofday () in let ctime = ref (Unix.gettimeofday ()) in @@ -671,7 +691,7 @@ let simulate (data : polygon dynamic) (dats : sphere dynamic) = draw_integer 600 770 !score 50 ; auto_synchronize true ; - Unix.sleepf 0.005 ; + Unix.sleepf univ_dt ; let __end = Unix.gettimeofday () in ctime := !ctime +. (__end -. __start) ; @@ -680,25 +700,27 @@ let simulate (data : polygon dynamic) (dats : sphere dynamic) = close_graph () ;; -(*let polygons = customize () ;;*) let polygons = dyn_create default_polygon ;; -dyn_add polygons (create_polygon [|(0, 0); (50, 0); (50, 775); (0, 775)|] 1.0 0 32 32 255) ;; -dyn_add polygons (create_polygon [|(1150, 0); (1200, 0); (1200, 775); (1150, 775)|] 1.0 0 32 32 255) ;; -dyn_add polygons (create_polygon [|(50, 0); (50, 200); (500, 25); (500, 0)|] 1.0 0 32 32 255) ;; -dyn_add polygons (create_polygon [|(1150, 0); (1150, 200); (700, 25); (700, 0)|] 1.0 0 32 32 255) ;; -dyn_add polygons (create_polygon [|(500, 0); (700, 0); (700, 25); (500, 25)|] 1.0 (-10) 192 64 64) ;; -dyn_add polygons (create_polygon [|(0, 750); (1200, 750); (1200, 800); (0, 800)|] 1.0 25 64 192 64) ;; - let spheres = dyn_create default_sphere ;; -dyn_add spheres (create_sphere 200 400 20. 1. 5 220 32 220) ;; -dyn_add spheres (create_sphere 300 200 20. 1. 3 192 0 192) ;; -dyn_add spheres (create_sphere 400 450 20. 1. 3 192 0 192) ;; -dyn_add spheres (create_sphere 600 350 20. 1. 10 255 64 255) ;; -dyn_add spheres (create_sphere 800 450 20. 1. 3 192 0 192) ;; -dyn_add spheres (create_sphere 900 200 20. 1. 3 192 0 192) ;; -dyn_add spheres (create_sphere 1000 400 20. 1. 5 220 32 220) ;; -dyn_add spheres (create_sphere 50 200 15. 1. 20 255 255 32) ;; -dyn_add spheres (create_sphere 1150 200 15. 1. 20 255 255 32) ;; + +(* kill platform *) +dyn_add polygons (create_polygon [|(700, -20); (500, -20); (500, 1); (700, 1)|] 0. 0 255 32 32) ;; + +(* outer walls *) +dyn_add polygons (create_polygon [|(0, 0); (500, 0); (500, 20); (0, 20)|] 1. 0 32 32 32) ;; +dyn_add polygons (create_polygon [|(700, 0); (1200, 0); (1200, 20); (700, 20)|] 1. 0 32 32 32) ;; +dyn_add polygons (create_polygon [|(0, 800); (500, 800); (500, 780); (0, 780)|] 1. 0 32 32 32) ;; +dyn_add polygons (create_polygon [|(700, 800); (1200, 800); (1200, 780); (700, 780)|] 1. 0 32 32 32) ;; +dyn_add polygons (create_polygon [|(1180, 0); (1200, 0); (1200, 800); (1180, 800)|] 1. 0 32 32 32) ;; +dyn_add polygons (create_polygon [|(0, 0); (20, 0); (20, 800); (0, 800)|] 1. 0 32 32 32) ;; + +(* side ramps *) +dyn_add polygons (create_polygon [|(20, 20); (20, 300); (500, 150); (500, 20)|] 1. 0 32 32 32) ;; +dyn_add polygons (create_polygon [|(1200, 20); (1200, 300); (700, 150); (700, 20)|] 1. 0 32 32 32) ;; + +(* starting platform *) +dyn_add polygons (create_polygon [|(600, 700); (400, 550); (800, 550)|] 1. 0 32 32 32) ;; + simulate polygons spheres ;; (* diff --git a/main.o b/main.o index 5ea016e..baf145d 100644 Binary files a/main.o and b/main.o differ diff --git a/pinball b/pinball index 86d07d2..3e219b7 100755 Binary files a/pinball and b/pinball differ