# include # include # include # define WORLD_WIDTH 64 // World width. # define WORLD_HEIGHT 64 // World height. # define SCREEN_WIDTH 128 // Screen width. # define SCREEN_HEIGHT 64 // Screen height. void mappartdisplaying(int x, int y, unsigned short int * terrain) { int firsttile_x = x>>3, firsttile_y = y>>3; int base_x = firsttile_x*8, base_y = firsttile_y*8; int sx = base_x - x, sy = base_y - y, tx = (SCREEN_WIDTH>>3) + 1, ty = (SCREEN_HEIGHT>>3) + 1; int cx, cy, px = sx, py = sy; unsigned short type; printf("values : %d, %d\n", tx, ty); for(cy = 0;cy != ty;cy++){ for(cx = 0;cx != tx;cx++){ type = terrain[(firsttile_y+cy)*WORLD_WIDTH+(firsttile_x+cx)]; printf("type pos : %d, %d, %d, %d\n", cy, cx, tx, (cy*tx+cx)); switch(type){ case 1: printf("soil : %d, %d, %d\n", px, py, type); break; case 2: printf("stone : %d, %d, %d\n", px, py, type); break; case 3: printf("coal : %d, %d, %d\n", px, py, type); break; default: printf("other : %d, %d, %d\n", px, py, type); break; } px += 8; } py += 8; px = sx; } } 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() % 11; if(t==0){ terrain[i*w+x] = someof; }else{ terrain[i*w+x] = type; } } }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 = 403, y; for(i=0;i!=WORLD_WIDTH*WORLD_HEIGHT;i++){ terrain[i] = 0; } srand(clock()); generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 60) + 1)) + WORLD_HEIGHT - 60), WORLD_HEIGHT - 60, WORLD_HEIGHT - 40, 0, 1); srand(clock()); generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 25) - (WORLD_HEIGHT - 40) + 1)) + WORLD_HEIGHT - 40), WORLD_HEIGHT - 40, WORLD_HEIGHT - 25, 3, 2); for(i=0;i!=WORLD_HEIGHT;i++){ if(terrain[i*WORLD_WIDTH+(x>>3)] != 0){ y = i * 8; break; } } y+=200; mappartdisplaying(x, y, terrain); return 0; }