forked from mibi88/Builder
20220624 - Test du générateur de terrain.
This commit is contained in:
parent
8b523dc388
commit
eb76443587
|
@ -0,0 +1,54 @@
|
|||
# include <time.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
# 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 && y<genmax){
|
||||
y++;
|
||||
}else if(n==1 && y>genmin){
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue