liblashgame

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

cartesianindex.c (1017B)


      1 // test of index to cartesian and back
      2 
      3 #include <stdio.h>
      4 #include "../lash_game_standard.h"
      5 #include <stdlib.h>
      6 
      7 int main(int argc, char **argv) {
      8 	lash_game_coords_t testcoords;
      9 	unsigned int unitsize = 1;
     10 	unsigned int w = 0;
     11 	unsigned int h = 0;
     12 	unsigned long int idx = 0;
     13 	unsigned int i = 0;
     14 	
     15 	if (argc < 5) {
     16 		printf("Usage: %s w h [x y|index] unitsize\n", *argv);
     17 		return 1;
     18 	}
     19 	
     20 	testcoords.x = 0;
     21 	testcoords.y = 0;
     22 	
     23 	w = atoi(*(argv+1));
     24 	h = atoi(*(argv+2));
     25 	
     26 	if (argc == 5) {
     27 		idx = atoi(*(argv+3));
     28 		
     29 	} else if (argc == 6) {
     30 		testcoords.x = atoi(*(argv+3));
     31 		testcoords.y = atoi(*(argv+4));
     32 		i = 1;
     33 	}
     34 	
     35 	unitsize = atoi(*(argv+4+i));
     36 	
     37 	if (i == 0) {
     38 		lash_indexToCartesian(&testcoords, &w, &h, &unitsize, &idx);
     39 		printf("Index %lu of w %u * h %u is x %u, y %u\n", idx, w, h, testcoords.x, testcoords.y);
     40 	} else {
     41 		lash_cartesianToIndex(&idx, &w, &h, &unitsize, &testcoords);
     42 		printf("x %u y %u of w %u * h %u is index %lu\n", testcoords.x, testcoords.y, w, h, idx);
     43 	}
     44 	return 0;
     45 }