imported music + calibrating gravity
This commit is contained in:
parent
2f6fa9cd87
commit
70ca29b311
28
main.ml
28
main.ml
|
@ -75,7 +75,7 @@ let default_sphere = {
|
|||
score = 0 ;
|
||||
} ;;
|
||||
|
||||
let univ_g = 800.0 ;;
|
||||
let univ_g = 750.0 ;;
|
||||
let pi = 3.14159265358979343 ;;
|
||||
|
||||
let winBL = {
|
||||
|
@ -110,7 +110,7 @@ let playbeep id =
|
|||
while true do
|
||||
if beep_boop.(id) then begin
|
||||
beep_boop.(id) <- false ;
|
||||
ignore (Unix.system "./sound 1sec.wav") ;
|
||||
ignore (Unix.system "./sound wah/scored_hit.wav") ;
|
||||
end;
|
||||
Unix.sleepf 0.005 ;
|
||||
done;;
|
||||
|
@ -121,7 +121,9 @@ let beep_list = Array.init n_threads (fun k -> Thread.create playbeep k) ;;
|
|||
|
||||
let play_music () =
|
||||
while true do
|
||||
ignore (Unix.system "./sound 1sec.wav") ;
|
||||
ignore (Unix.system "./sound wah/wah_metal.wav") ;
|
||||
ignore (Unix.system "./sound wah/wah_eurobeat.wav") ;
|
||||
ignore (Unix.system "./sound wah/wah_hardcore.wav") ;
|
||||
done;;
|
||||
|
||||
let theme_thr = Thread.create play_music () ;;
|
||||
|
@ -339,6 +341,10 @@ let is_collision_p (b : ball) (poly : polygon) (dt : float) =
|
|||
| ReturnInt b -> b
|
||||
end ;;
|
||||
|
||||
let playbeep () =
|
||||
beep_boop.(!beep_id) <- true ;
|
||||
beep_id := (!beep_id+1) mod n_threads ;;
|
||||
|
||||
let is_collision_s (b : ball) (s : sphere) (dt : float) =
|
||||
if not (is_in_bounding_box_s b s) then
|
||||
false
|
||||
|
@ -354,6 +360,9 @@ let update_ball_data (b : ball) (polys : polygon array) (spheres : sphere array)
|
|||
if hit <> -1 then begin
|
||||
score := !score + polys.(p).score ;
|
||||
|
||||
if polys.(p).score > 0 then
|
||||
playbeep () ;
|
||||
|
||||
(* 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
|
||||
|
@ -376,8 +385,8 @@ let update_ball_data (b : ball) (polys : polygon array) (spheres : sphere array)
|
|||
if is_collision_s b spheres.(s) dt then begin
|
||||
score := !score + spheres.(s).score ;
|
||||
|
||||
beep_boop.(!beep_id) <- true ;
|
||||
beep_id := (!beep_id+1) mod n_threads ;
|
||||
if spheres.(s).score > 0 then
|
||||
playbeep () ;
|
||||
|
||||
(* apply normal reaction force *)
|
||||
let proj_n = vect_normalize_2D (vect_diff_2D b.xy spheres.(s).center) in
|
||||
|
@ -645,10 +654,6 @@ let simulate (data : polygon dynamic) (dats : sphere dynamic) =
|
|||
auto_synchronize false ;
|
||||
clear_graph () ;
|
||||
|
||||
set_color black ;
|
||||
set_line_width 4 ;
|
||||
draw_integer 600 770 !score 50 ;
|
||||
|
||||
set_line_width 1 ;
|
||||
for d = 0 to data.len -1 do
|
||||
draw_polygon data.tab.(d)
|
||||
|
@ -661,6 +666,10 @@ let simulate (data : polygon dynamic) (dats : sphere dynamic) =
|
|||
set_color (rgb 128 128 32) ;
|
||||
draw_float 25 770 (round (!ctime -. stime) 3) 25 ;
|
||||
|
||||
set_color black ;
|
||||
set_line_width 4 ;
|
||||
draw_integer 600 770 !score 50 ;
|
||||
|
||||
auto_synchronize true ;
|
||||
Unix.sleepf 0.005 ;
|
||||
|
||||
|
@ -678,6 +687,7 @@ dyn_add polygons (create_polygon [|(1150, 0); (1200, 0); (1200, 775); (1150, 775
|
|||
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) ;;
|
||||
|
|
|
@ -14,7 +14,7 @@ int main(int argc, char** argv) {
|
|||
SDL_AudioDeviceID deviceId = SDL_OpenAudioDevice(NULL, 0, &wavSpec, NULL, 0);
|
||||
int success = SDL_QueueAudio(deviceId, wavBuffer, wavLength);
|
||||
SDL_PauseAudioDevice(deviceId, 0);
|
||||
usleep((int)((wavLength)/88200.0*100000.0)) ;
|
||||
usleep((int)((wavLength)/88200.0*100000.0));
|
||||
SDL_CloseAudioDevice(deviceId);
|
||||
SDL_FreeWAV(wavBuffer);
|
||||
SDL_Quit();
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue