20220626 - Générateur de terrain amélioré.

This commit is contained in:
mibi88 2022-06-26 12:01:03 +02:00
parent eb76443587
commit fa42f7e550
1 changed files with 7 additions and 6 deletions

View File

@ -3,7 +3,7 @@
# include <stdlib.h>
# define WORLD_WIDTH 256 // World width.
# define WORLD_HEIGHT 128 // World height.
# define WORLD_HEIGHT 64 // 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;
@ -13,11 +13,11 @@ void generateworld(unsigned short terrain[], int w, int h, int genstart, int gen
if(a==0){
for(i=y;i!=h;i++){
srand(clock());
t = (int)rand() % 2;
t = (int)rand() % 11;
if(t==0){
terrain[i*w+x] = type;
}else if(t==1){
terrain[i*w+x] = someof;
}else{
terrain[i*w+x] = type;
}
}
}else if(a==1){
@ -41,9 +41,10 @@ int main() {
terrain[i] = 0;
}
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)rand() % 2, WORLD_HEIGHT - 20, WORLD_HEIGHT - 2, 0, 1);
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() % 2, WORLD_HEIGHT - 35, WORLD_HEIGHT - 16, 3, 2);
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);
printf("! XPM2\n%d %d 4 1\n0 c #4dc4be\n1 c #6b4528\n2 c #787878\n3 c #000000\n", WORLD_WIDTH, WORLD_HEIGHT);
for(y=0;y!=WORLD_HEIGHT;y++){
for(x=0;x!=WORLD_WIDTH;x++){
printf("%d", terrain[y*WORLD_WIDTH+x]);