fix erreur color spawn in generator
This commit is contained in:
parent
cb02ca1330
commit
c69877bab4
@ -53,6 +53,8 @@ void create_map(int w, int h){
|
||||
//biome variable
|
||||
int nb_plains, nb_forests, nb_mountains;
|
||||
|
||||
int spawn_color = 0;
|
||||
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
@ -81,6 +83,7 @@ void create_map(int w, int h){
|
||||
create_biome_random(MOUNTAINS);
|
||||
// */
|
||||
//génération de la carte
|
||||
|
||||
for (i=0;i<width;i++){
|
||||
for(j=0;j<height;j++){
|
||||
if (i == 0 || j == 0 || i == w-1 || j == h-1){
|
||||
@ -88,7 +91,7 @@ void create_map(int w, int h){
|
||||
}else if((i == sp_x[0] && j == sp_y[0]) || (i == sp_x[1] && j == sp_y[1])){
|
||||
map[i][j].type = SPAWN;
|
||||
map[i][j].data=malloc(sizeof(int));
|
||||
memset(map[i][j].data,ORANGE,sizeof(int));
|
||||
memset(map[i][j].data,spawn_color++,sizeof(int));
|
||||
}else{
|
||||
map[i][j].type = generate(i,j);
|
||||
}
|
||||
|
@ -10,11 +10,6 @@
|
||||
int width, height, size;
|
||||
float corner_value[4];
|
||||
|
||||
|
||||
//temporaire, a virer
|
||||
int offset_x,offset_y,previous_offset;
|
||||
int cpt;
|
||||
|
||||
//functions
|
||||
int closest_pow_2(int);
|
||||
void init_height_map(float**);
|
||||
@ -44,7 +39,11 @@ void create_map(int w, int h){
|
||||
printf("generate height map...\n");
|
||||
//generate height map
|
||||
start_diamond_square(height_map);
|
||||
free(height_map);
|
||||
|
||||
printf("erosion\n");
|
||||
|
||||
|
||||
|
||||
printf("finished generation! \n");
|
||||
|
||||
}
|
||||
@ -58,7 +57,6 @@ void init_height_map(float** h_map){
|
||||
h_map[size][0]=0.3;
|
||||
h_map[size][size]=0.9;
|
||||
h_map[0][size]=0.8;
|
||||
previous_offset=size;
|
||||
}
|
||||
|
||||
void start_diamond_square(float ** h_map){
|
||||
@ -71,8 +69,6 @@ void dummy(int x1, int y1, int x2, int y2, int avg_x,int avg_y){
|
||||
void diamond_square(float** h_map,int x1,int x2,int y1, int y2){
|
||||
int avg_x, avg_y;
|
||||
float avg_value;
|
||||
|
||||
cpt++;
|
||||
|
||||
//get value of corner from h_map
|
||||
corner_value[0] = h_map[x1][y1]; //up_left
|
||||
@ -84,7 +80,7 @@ void diamond_square(float** h_map,int x1,int x2,int y1, int y2){
|
||||
avg_x = average(x1,x2);
|
||||
avg_y = average(y1,y2);
|
||||
|
||||
dummy(x1,y1,x2,y2,avg_x,avg_y);
|
||||
//dummy(x1,y1,x2,y2,avg_x,avg_y);
|
||||
//Diamond Step
|
||||
//process average value of the corner
|
||||
avg_value = average_t(corner_value,4);
|
||||
@ -101,15 +97,9 @@ void diamond_square(float** h_map,int x1,int x2,int y1, int y2){
|
||||
h_map[x1][avg_y] = average_noisy(corner_value[3], corner_value[0]); // left
|
||||
|
||||
//recursive call to diamond_square
|
||||
offset_x = x2-x1;
|
||||
offset_y = y2-y1;
|
||||
if (offset_x < previous_offset){
|
||||
printf("%d\n",offset_x);
|
||||
printf("%d\n",offset_y);
|
||||
previous_offset = offset_x;
|
||||
}
|
||||
int offset = x2-x1;
|
||||
|
||||
if (offset_x > 2){
|
||||
if (offset > 2){
|
||||
diamond_square(h_map, x1, avg_x, y1, avg_y); //up_left square
|
||||
diamond_square(h_map, avg_x, x2, y1, avg_y); // up_right square
|
||||
diamond_square(h_map, avg_x, x2, avg_y, y2); // down_right square
|
||||
|
Loading…
x
Reference in New Issue
Block a user