liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

mapclip.c (1799B)


      1 #include <stdio.h>
      2 #include <string.h>
      3 #include <stdlib.h>
      4 #include <math.h>
      5 #include <unistd.h>
      6 #include <time.h>
      7 
      8 #include "liblashgame/lash_game_map.h"
      9 #include "liblashgame/lash_game_standard.h"
     10 
     11 #include "common.h"
     12 
     13 #define LASH_X_WIDTH 100
     14 #define LASH_X_HEIGHT 100
     15 
     16 enum lash_game_map_clip_alignment {
     17 	LASH_GAME_MAP_CLIP_CENTER,
     18 	LASH_GAME_MAP_CLIP_TOPLEFT,
     19 	LASH_GAME_MAP_CLIP_BOTTOMLEFT,
     20 	LASH_GAME_MAP_CLIP_BOTTOMRIGHT,
     21 	LASH_GAME_MAP_CLIP_TOPRIGHT
     22 };
     23 
     24 
     25 
     26 
     27 int main(int argc, char **argv) {
     28 	
     29 	unsigned int w = 0;
     30 	unsigned int h = 0;
     31 	char arg;
     32 	
     33 	time_t t;
     34 	
     35 	lash_game_map_index_t idx = 0;
     36 	
     37 	lash_map_simple_t map;
     38 	lash_map_simple_t clip;
     39 	
     40 	unsigned int clip_x_radius;
     41 	unsigned int clip_y_radius;
     42 	
     43 	// options
     44 	while ((arg = getopt(argc, argv, "w:h:x:y:i:")) != -1) {
     45 		switch(arg) {
     46 			case 'w':
     47 				w = atoi(optarg);
     48 				break;
     49 			case 'h':
     50 				h = atoi(optarg);
     51 				break;
     52 			case 'x':
     53 				clip_x_radius = atoi(optarg);
     54 				break;
     55 			case 'y':
     56 				clip_y_radius = atoi(optarg);
     57 				break;
     58 			case 'i':
     59 				idx = atoi(optarg);
     60 				break;
     61 		}
     62 	}
     63 	
     64 	w = w > 0 ? w : LASH_X_WIDTH;
     65 	h = h > 0 ? h : LASH_X_HEIGHT;
     66 	
     67 	// if clip is only one-dimensional, or same size as map
     68 	if (clip_x_radius == 0 || clip_y_radius == 0 || (clip_x_radius >= w && clip_y_radius >= h))
     69 		return 1;
     70 	
     71 	//map = (lash_map_simple_t*)malloc(sizeof(lash_map_simple_t));
     72 	//if (map == NULL)
     73 	//	return 1;
     74 		
     75 	if (lash_mapSimpleInit(&map, &w, &h) == NULL)
     76 		return 1;
     77 	
     78 	srand((unsigned) time(&t));
     79 	
     80 	fillMapRandom(&map, 64);
     81 	
     82 	if (lash_mapSimpleClip(&clip, &map, clip_x_radius, clip_y_radius, idx, LASH_GAME_MAP_OFFSET_CENTER, 1) == NULL)
     83 		return 1;
     84 	
     85 	dumpMapPathLayer(&clip, 1, -1, -1, -1);	
     86 	dumpMapPathLayer(&map, 1, -1, -1, -1);	
     87 	
     88 	lash_mapSimpleFree(&map);
     89 	lash_mapSimpleFree(&clip);
     90 	
     91 	return 0;
     92 }