Paweł Wieczorek avatar Paweł Wieczorek committed 3eb3b5c Draft

resources

Comments (0)

Files changed (4)

 
 
 (**************************************************************************
- * 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
- *)
 
  * 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
 
  *)
 
 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)

template/File.mli

+(**************************************************************************
+ * PixLand
+ *   Copyrights 2012 by Pawel Wieczorek <wieczyk gmail com>
+ *)
+
+open ;;
+
+(**************************************************************************
+ * Types
+ *)
+
+
+(**************************************************************************
+ * 
+ *)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.