added alternative map generator, for testing purposes, type 'make anselme' to use it
This commit is contained in:
parent
85cdeaf4d3
commit
957f41517f
3
Makefile
3
Makefile
@ -27,6 +27,9 @@ main : main.o generator.o
|
||||
$(BINARY) : orange.o purple.o main.o generator.o
|
||||
$(CC) main.o generator.o orange.o purple.o -o $(BINARY) $(LIB)
|
||||
|
||||
anselme : orange.o purple.o main.o generator_anselme.o
|
||||
$(CC) main.o generator_anselme.o orange.o purple.o -o $(BINARY) $(LIB)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -o $@ -c $< $(FLAGS)
|
||||
|
||||
|
65
generator_anselme.c
Normal file
65
generator_anselme.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include "main.h"
|
||||
|
||||
// functions
|
||||
int distance_manhattan(int x1,int y1, int x2, int y2);
|
||||
|
||||
int absolute(int val);
|
||||
|
||||
int min(int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
int max(int a, int b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
void create_map(t_pixel** map, t_team* teams, int w, int h){
|
||||
int i,j, k;
|
||||
int r = (w/NB_TEAMS < h ? w/NB_TEAMS : h)/2;
|
||||
|
||||
for(i=0; i<NB_TEAMS; i++){
|
||||
teams[i].spawn.x = (w/(NB_TEAMS*2))*(1+i*2);
|
||||
teams[i].spawn.y = h/2;
|
||||
}
|
||||
|
||||
//génération de la carte
|
||||
for (i=0;i<w;i++){
|
||||
for(j=0;j<h;j++){
|
||||
map[i][j].data = NULL;
|
||||
if (i == 0 || j == 0 || i == w-1 || j == h-1){
|
||||
map[i][j].type = BEDROCK;
|
||||
}else{
|
||||
int d = max(w, h);
|
||||
for(k=0; k<NB_TEAMS; k++){
|
||||
d = min(d, distance_manhattan(teams[k].spawn.x, teams[k].spawn.y, i, j));
|
||||
if(!d) break;
|
||||
}
|
||||
if(d == 0){
|
||||
map[i][j].type = SPAWN;
|
||||
map[i][j].data = malloc(sizeof(int));
|
||||
*(int*)(map[i][j].data) = k;
|
||||
}else{
|
||||
int l = (d-20)+(rand()%40);
|
||||
if(l > r+15){
|
||||
map[i][j].type = rand()%8 ? ROCK : IRON_ORE;
|
||||
}else if(l < r-15){
|
||||
map[i][j].type = rand()%15 ? GRASS : BERRIES;
|
||||
}else{
|
||||
l = rand()%10;
|
||||
map[i][j].type = l > 5 ? TREE : l ? GRASS : BERRIES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int distance_manhattan(int x1,int y1, int x2, int y2){
|
||||
return absolute(x1-x2) + absolute(y1-y2);
|
||||
}
|
||||
|
||||
int absolute(int val){
|
||||
return val > 0 ? val : -val;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user