fix bug spawn in generator.c
This commit is contained in:
parent
6822bb8cbb
commit
c6174a62db
25
generator.c
25
generator.c
@ -28,7 +28,7 @@ typedef struct{
|
||||
} t_biome;
|
||||
|
||||
// variables
|
||||
int spx[2], spy[2];
|
||||
int sp_x[2], sp_y[2];
|
||||
t_biome* l_biomes;
|
||||
int size_biomes;
|
||||
int cpt_biome = 0;
|
||||
@ -85,6 +85,10 @@ void create_map(int w, int h){
|
||||
for(j=0;j<height;j++){
|
||||
if (i == 0 || j == 0 || i == w-1 || j == h-1){
|
||||
map[i][j].type = BEDROCK;
|
||||
}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));
|
||||
}else{
|
||||
type=generate(i,j);
|
||||
map[i][j].type = type;
|
||||
@ -104,19 +108,16 @@ void set_spawns(t_pixel** map, t_team* teams){
|
||||
tier_w = width/6;
|
||||
tier_h = height/3;
|
||||
|
||||
spx[0] = (rand()%tier_w)+tier_w;
|
||||
spy[0] = (rand()%tier_h)+tier_h;
|
||||
sp_x[0] = (rand()%tier_w)+tier_w;
|
||||
sp_y[0] = (rand()%tier_h)+tier_h;
|
||||
|
||||
spx[1] = width-spx[0];
|
||||
spy[1] = height-spy[0];
|
||||
sp_x[1] = width-sp_x[0];
|
||||
sp_y[1] = height-sp_y[0];
|
||||
|
||||
for(i=0;i<2;i++){
|
||||
map[spx[i]][spy[i]].type=SPAWN;
|
||||
map[spx[i]][spy[i]].data=malloc(sizeof(int));
|
||||
memset(map[spx[i]][spy[i]].data,ORANGE,sizeof(int));
|
||||
create_biome(spx[i],spy[i],VILLAGE);
|
||||
teams[i].spawn.x = spx[i];
|
||||
teams[i].spawn.y = spy[i];
|
||||
create_biome(sp_x[i],sp_y[i],VILLAGE);
|
||||
teams[i].spawn.x = sp_x[i];
|
||||
teams[i].spawn.y = sp_y[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +166,7 @@ int check_nears_biomes(int x, int y){
|
||||
int check_nears_spawn(int x, int y){
|
||||
int i,c = 0;
|
||||
for(i=0;i<2;i++)
|
||||
if (distance_manhattan(x,y,spx[i],spy[i]) < 100) c++;
|
||||
if (distance_manhattan(x,y,sp_x[i],sp_y[i]) < 100) c++;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user