Commits

Anonymous committed ccfc8df

sound

  • Participants
  • Parent commits 746f53f

Comments (0)

Files changed (5)

File data/mills/capture.wav

Binary file added.

File data/mills/lose.wav

Binary file added.

File data/mills/move.wav

Binary file added.

File data/mills/win.wav

Binary file added.

File mills/sdlmills.ml

     | Some surface -> Sdlvideo.update_rect surface
 end
 
+module Sfx = struct
+  open Sdlmixer
+  
+  let move = ref None
+  let capture = ref None
+  let win = ref None
+  let lose = ref None
+  
+  let load () =
+    move := Some (loadWAV "data/mills/move.wav");
+    capture := Some (loadWAV "data/mills/capture.wav");
+    win := Some (loadWAV "data/mills/win.wav");
+    lose := Some (loadWAV "data/mills/lose.wav")
+  
+  let play sfxref = match !sfxref with
+    | None -> failwith "sound not initialized"
+    | Some sound -> Sdlmixer.play_channel ~channel:0 sound
+end
+
 module Human = struct
   open Sdlvideo
   open Sdlevent
       let state' = Mill.copy !s in
       begin
         let goal = do_turn state' !p in
+        Sfx.play Sfx.move;
         Image.draw_state state';
-        Image.draw_marker goal;
+        Image.draw_marker goal;        
         if Mill.in_mill state' goal then begin
           let capture = (!p#capture state') in
+          Sfx.play Sfx.capture;
           Mill.capture state' capture;
           Image.draw_state state';
           Image.draw_marker goal;
         p := next !p
       end;
     done;
+    if !p = Human.player then Sfx.play Sfx.lose
+    else Sfx.play Sfx.win
   in
   let state = Mill.make () in
   Image.draw_state state;
 
 let _ =
   Random.self_init ();
-  let screen = init_sdl () in
+  let screen = init_sdl () in  
   Image.load screen;
+  Sfx.load ();
   try
     mainloop Human.player Ai_alphabeta.player;
     Sdltimer.delay 1500;