Commits

Paweł Wieczorek  committed 3eb3b5c Draft

resources

  • Participants
  • Parent commits 01734cf

Comments (0)

Files changed (4)

File src/Resource.ml

 
 
 (**************************************************************************
- * Globals 
+ * Helpers
  *)
 
 let fresh_id_int = ref 0
 
+let prepare_image name =
+  { id = MkImageId (-1) ; name = name ; image = None }
 
 (**************************************************************************
  * Predefined resources
  *)
 
-let prepare_image name =
-  Image { id = MkImageId (-1) ; name = name ; image = None }
-
-
-module RESPAK0 = struct
+module PAK0 = struct
 
   let img_grass = prepare_image "grass-32x32"
   let img_water = prepare_image "water-32x32"
   let img_rock  = prepare_image "rock-32x32"
 
   let resources =
-    [ img_grass
-    ; img_water
-    ; img_rock
+    [ Image img_grass
+    ; Image img_water
+    ; Image img_rock
     ]
 
 end
 
+(**************************************************************************
+ * Loaders
+ *)
 
 let load_resource = function
   | Image i ->
       fresh_id_int := succ !fresh_id_int
 
 let rec load_resources = function
-  | nil   -> ()
-  | x::xs -> load_resource x; load_resources xs
+  | []    -> ()
+  | x::xs ->
+      load_resource x;
+      load_resources xs
+
+
+(**************************************************************************
+ * Init
+ *)
 
 let init_resources () =
-  load_resources RESPAK0.resources
+  load_resources PAK0.resources;
 
-(**************************************************************************
- * Resource
- *)
 

File src/Resource.mli

  * PAK0
  *)
 
-module RESPAK0 :
+module PAK0 :
   sig
-    val img_grass : resource
-    val img_water : resource
-    val img_rock : resource
+    val img_grass : resourceImage
+    val img_water : resourceImage
+    val img_rock : resourceImage
   end
 

File src/World.ml

  *)
 
 open Array;;
+open Resource;;
 
 (**************************************************************************
  * Types
     }
 
   let draw window surface = 
-    let img_grass = Video.load_image "grass-32x32" in
-
     for y = 0 to window.height do
       for x = 0 to window.width do
         let surf_x  = x * unit_width 
         and arena_y = y + window.offset_top in
         
         let field   = Arena.get window.arena arena_x arena_y in
+        let put     = function
+          | None     -> raise Exit
+          | Some img -> Video.put_image img surface (surf_x, surf_y)
+        in
         begin match field.terrain with
           | Grass -> 
-              Video.put_image img_grass surface (surf_x, surf_y)
+              put PAK0.img_grass.image
           | Water ->
               let img = Video.load_image "water-32x32" in
               Video.put_image img surface (surf_x, surf_y)

File template/File.mli

+(**************************************************************************
+ * PixLand
+ *   Copyrights 2012 by Pawel Wieczorek <wieczyk gmail com>
+ *)
+
+open ;;
+
+(**************************************************************************
+ * Types
+ *)
+
+
+(**************************************************************************
+ * 
+ *)
+