From cb5cd406d4d1cc55b03ed72d1f7c1564210414ed Mon Sep 17 00:00:00 2001 From: mibi88 Date: Tue, 28 Jun 2022 21:52:04 +0200 Subject: [PATCH] =?UTF-8?q?20220628=20-=20Scrolling=20en=20cours=20de=20d?= =?UTF-8?q?=C3=A9veloppement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/mapdisplaytest.c | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/mapdisplaytest.c diff --git a/tests/mapdisplaytest.c b/tests/mapdisplaytest.c new file mode 100644 index 0000000..71e8acc --- /dev/null +++ b/tests/mapdisplaytest.c @@ -0,0 +1,77 @@ +# include +# include +# include + +# define WORLD_WIDTH 256 // 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; + for(cy = 0;cy != ty;cy++){ + for(cx = 0;cx != tx;cx++){ + type = terrain[cy*tx+px]; + printf("%d, %d, %d, %d\n", type, (cy*tx+px), cx, cy); + if(type == 1){ + printf("soil : %d, %d\n", px, py); + }else if(type == 2){ + printf("stone : %d, %d\n", px, py); + }else if(type == 3){ + printf("coal : %d, %d\n", px, py); + }else{ + printf("other : %d, %d\n", px, py); + } + 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 = 403; + 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); + mappartdisplaying(x, y, terrain); + return 0; +} \ No newline at end of file