Commits

Anonymous committed 53539e3

memory images & static layout

Comments (0)

Files changed (14)

data/memory/0.png

Added
New image

data/memory/1.png

Added
New image

data/memory/10.png

Added
New image

data/memory/11.png

Added
New image

data/memory/2.png

Added
New image

data/memory/3.png

Added
New image

data/memory/4.png

Added
New image

data/memory/5.png

Added
New image

data/memory/6.png

Added
New image

data/memory/7.png

Added
New image

data/memory/8.png

Added
New image

data/memory/9.png

Added
New image

data/memory/background.png

Added
New image
+
+module Image = struct
+  open Sdlvideo
+  open Sdlloader
+  
+  let imgsize = 115
+  
+  let images = Array.make 12 None
+  let background = ref None
+  
+  let load () =
+    background := Some (load_image "data/memory/background.png");
+    for i = 0 to (Array.length images -1) do
+      images.(i) <- Some (load_image ("data/memory/" ^ string_of_int i ^ ".png"))
+    done
+    
+  let blit dst dst_rect img = match img with
+    | None -> failwith "image not initialized"
+    | Some image ->
+        Sdlvideo.blit_surface ~dst_rect: dst_rect ~src: image ~dst: dst ()
+   
+  let draw_img screen x y img =
+    let open Sdlvideo in
+    let fullrect = rect x y imgsize imgsize in
+    blit screen fullrect img;
+    update_rect ~rect: fullrect screen  
+end
+
+let select_video_mode () =
+  let open Sdlvideo in 
+  let flags = [`FULLSCREEN;`HWSURFACE] in
+  let bpp = 32 in
+  let rec first_available = function
+    | [] -> failwith "no available mode"
+    | (w,h)::list -> 
+      let bpp' = video_mode_ok w h bpp flags in
+      if bpp' = bpp then (w, h, bpp)
+      else first_available list
+  in  
+  first_available [(1440,900);(1024,768)]
+
+              
+
+let _ =
+  Sdl.init [`VIDEO; `AUDIO];
+  at_exit Sdl.quit;
+  Sdlmixer.open_audio ();
+  at_exit Sdlmixer.close_audio;
+  
+  Sdlkey.enable_key_repeat ();
+  Sdlwm.set_caption "maze minigame" "";
+  let w, h, bpp = select_video_mode () in
+  Printf.printf "mode: %d %d %d\n%!" w h bpp;
+  let screen = Sdlvideo.set_video_mode ~w:w ~h:h ~bpp:bpp [`FULLSCREEN;`HWSURFACE] in
+  let playground = Sdlvideo.create_RGB_surface_format screen [`HWSURFACE] 1024 768 in
+  let screenrect = Sdlvideo.rect ((w-1024)/2) ((h-768)/2) 1024 768 in
+  let white = Sdlvideo.map_RGB playground Sdlvideo.white in
+  
+  Image.load ();
+  
+  Sdlvideo.fill_rect playground white;
+  for i = 0 to 7 do
+    for j = 0 to 3 do
+      Image.draw_img playground (50 + i*160) (80 + j*160) Image.images.((j*6 + i) mod 12);
+  (*    Image.draw_img playground (50 + i*160) (80 + j*160) !Image.background *)
+    done
+  done;
+
+  Sdlvideo.blit_surface ~src:playground ~dst:screen ~dst_rect:screenrect ();
+  Sdlvideo.flip screen;
+  Sdltimer.delay 5000