diff --git a/tests/gentest.c b/tests/gentest.c new file mode 100644 index 0000000..d4532c8 --- /dev/null +++ b/tests/gentest.c @@ -0,0 +1,54 @@ +# include +# include +# include + +# define WORLD_WIDTH 256 // World width. +# define WORLD_HEIGHT 128 // World height. + +void generateworld(unsigned short terrain[], int w, int h, int genstart, int genmin, int genmax, int someof, int type) { + int x = 0, y = genstart, n, i, a, t; + for(x=0;x!=w;x++){ + srand(clock()); + a = (int)rand() % 2; + if(a==0){ + for(i=y;i!=h;i++){ + srand(clock()); + t = (int)rand() % 2; + if(t==0){ + terrain[i*w+x] = type; + }else if(t==1){ + terrain[i*w+x] = someof; + } + } + }else if(a==1){ + for(i=y;i!=h;i++){ + terrain[i*w+x] = type; + } + } + srand(clock()); + n = (int)rand() % 2; + if(n==0 && ygenmin){ + y--; + } + } +} +int main() { + unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT]; + int i, x, y; + for(i=0;i!=WORLD_WIDTH*WORLD_HEIGHT;i++){ + terrain[i] = 0; + } + srand(clock()); + generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)rand() % 2, WORLD_HEIGHT - 20, WORLD_HEIGHT - 2, 0, 1); + srand(clock()); + generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)rand() % 2, WORLD_HEIGHT - 35, WORLD_HEIGHT - 16, 3, 2); + for(y=0;y!=WORLD_HEIGHT;y++){ + for(x=0;x!=WORLD_WIDTH;x++){ + printf("%d", terrain[y*WORLD_WIDTH+x]); + } + printf("\n"); + } + return 0; +} \ No newline at end of file