Merge branch 'master' of https://git.tagachop.fr/epicsparrow/PixelWars
This commit is contained in:
commit
839eebe5d4
2
Makefile
2
Makefile
@ -12,7 +12,7 @@ else
|
|||||||
FixPath=$1
|
FixPath=$1
|
||||||
BINARY=PixelWars
|
BINARY=PixelWars
|
||||||
LIB=-lSDL -lm
|
LIB=-lSDL -lm
|
||||||
FLAGS=-Wall
|
FLAGS=-g -Wall
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
81
generator.c
81
generator.c
@ -1,6 +1,8 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
#define MAX_POWER 10
|
#define MAX_POWER 10
|
||||||
|
#define MAX_EPICENTER_BY_TYPE 10
|
||||||
|
#define MAX_RADIUS 75
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int x;
|
int x;
|
||||||
@ -18,50 +20,44 @@ int width, height;
|
|||||||
|
|
||||||
// functions
|
// functions
|
||||||
int distance_manhattan(int x1,int y1, int x2, int y2);
|
int distance_manhattan(int x1,int y1, int x2, int y2);
|
||||||
|
|
||||||
int absolute(int val);
|
int absolute(int val);
|
||||||
|
void set_spawns(t_pixel** map, t_team* teams);
|
||||||
void create_epicenter(int type);
|
void create_epicenter(int x, int y, int type);
|
||||||
|
void create_epicenter_random(int type);
|
||||||
int generate(int x, int y);
|
int generate(int x, int y);
|
||||||
|
|
||||||
void create_map(t_pixel** map, t_team* teams, int w, int h){
|
void create_map(t_pixel** map, t_team* teams, int w, int h){
|
||||||
int i,j,k,l;
|
int i,j;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
//epicenter variable
|
//epicenter variable
|
||||||
int nb_rock, nb_tree, nb_berries;
|
int nb_rock, nb_tree, nb_berries;
|
||||||
|
|
||||||
//spawn variable
|
|
||||||
int x_rand, y_rand;
|
|
||||||
|
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
|
|
||||||
//Epicenters generation
|
//Epicenters generation
|
||||||
|
|
||||||
// random choice for numbers of epicenters
|
// random choice for numbers of epicenters
|
||||||
nb_rock = rand()%5;
|
nb_rock = rand()%MAX_EPICENTER_BY_TYPE;
|
||||||
nb_tree = rand()%5;
|
nb_tree = rand()%MAX_EPICENTER_BY_TYPE;
|
||||||
nb_berries = rand()%5;
|
nb_berries = rand()%MAX_EPICENTER_BY_TYPE;
|
||||||
|
|
||||||
size_epicenters = nb_rock + nb_tree + nb_berries + NB_TEAMS;
|
size_epicenters = nb_rock + nb_tree + nb_berries + NB_TEAMS;
|
||||||
|
|
||||||
l_epicenters = malloc(sizeof(t_epicenter)*size_epicenters);
|
l_epicenters = malloc(sizeof(t_epicenter)*size_epicenters);
|
||||||
|
|
||||||
//plains generation for each player => after spawn
|
// Spawn generations
|
||||||
for(i=0;i<NB_TEAMS;i++)
|
set_spawns(map,teams);
|
||||||
create_epicenter(GRASS);
|
|
||||||
|
|
||||||
for(i=0;i<nb_rock;i++)
|
for(i=0;i<nb_rock;i++)
|
||||||
create_epicenter(ROCK);
|
create_epicenter_random(ROCK);
|
||||||
|
|
||||||
for(i=0;i<nb_tree;i++)
|
for(i=0;i<nb_tree;i++)
|
||||||
create_epicenter(TREE);
|
create_epicenter_random(TREE);
|
||||||
|
|
||||||
for(i=0;i<nb_berries;i++)
|
for(i=0;i<nb_berries;i++)
|
||||||
create_epicenter(BERRIES);
|
create_epicenter_random(BERRIES);
|
||||||
|
// */
|
||||||
//génération de la carte
|
//génération de la carte
|
||||||
for (i=0;i<width;i++){
|
for (i=0;i<width;i++){
|
||||||
for(j=0;j<height;j++){
|
for(j=0;j<height;j++){
|
||||||
@ -73,8 +69,12 @@ void create_map(t_pixel** map, t_team* teams, int w, int h){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_spawns(t_pixel** map, t_team* teams){
|
||||||
|
int k,l;
|
||||||
|
int x_rand,y_rand;
|
||||||
|
|
||||||
//génération spawns
|
|
||||||
for(k=0;k<NB_TEAMS;k++){
|
for(k=0;k<NB_TEAMS;k++){
|
||||||
x_rand= rand()%width;
|
x_rand= rand()%width;
|
||||||
y_rand= rand()%height;
|
y_rand= rand()%height;
|
||||||
@ -88,34 +88,47 @@ void create_map(t_pixel** map, t_team* teams, int w, int h){
|
|||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
map[x_rand][y_rand].type=SPAWN;
|
||||||
|
map[x_rand][y_rand].data=malloc(sizeof(int));
|
||||||
|
memset(map[x_rand][y_rand].data,ORANGE,sizeof(int));
|
||||||
|
create_epicenter(x_rand,y_rand,GRASS);
|
||||||
teams[k].spawn.x = x_rand;
|
teams[k].spawn.x = x_rand;
|
||||||
teams[k].spawn.y = y_rand;
|
teams[k].spawn.y = y_rand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_epicenter(int type){
|
void create_epicenter(int x, int y, int type){
|
||||||
t_epicenter epicenter;
|
t_epicenter *epicenter = malloc(sizeof(t_epicenter));
|
||||||
|
|
||||||
epicenter.x=rand()%width;
|
epicenter->x=x;
|
||||||
epicenter.y=rand()%height;
|
epicenter->y=y;
|
||||||
epicenter.type = type;
|
epicenter->type = type;
|
||||||
epicenter.power = rand()%MAX_POWER;
|
epicenter->power = (rand()%MAX_POWER)+1;
|
||||||
epicenter.radius = rand()%(width*height/4);
|
epicenter->radius = (rand()%100)+1;
|
||||||
|
|
||||||
l_epicenters[cpt_epicenter++]=epicenter;
|
l_epicenters[cpt_epicenter++]=*epicenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_epicenter_random(int type){
|
||||||
|
create_epicenter(rand()%width,rand()%height,type);
|
||||||
}
|
}
|
||||||
|
|
||||||
int generate(int x, int y){
|
int generate(int x, int y){
|
||||||
int i, ratio, dist_to_epi, sum, val, type;
|
int i, ratio, dist_to_epi, sum, val;
|
||||||
int proba[5];
|
int proba[5];
|
||||||
t_epicenter epi;
|
t_epicenter epi;
|
||||||
|
|
||||||
|
for(i=0;i<5;i++){
|
||||||
|
proba[i]=0;
|
||||||
|
}
|
||||||
|
|
||||||
for(i=0;i<size_epicenters;i++){
|
for(i=0;i<size_epicenters;i++){
|
||||||
epi = l_epicenters[i];
|
epi = l_epicenters[i];
|
||||||
dist_to_epi = distance_manhattan(x,y,epi.x, epi.y);
|
dist_to_epi = distance_manhattan(x,y,epi.x, epi.y);
|
||||||
if (dist_to_epi < epi.radius){
|
if (dist_to_epi < epi.radius){
|
||||||
ratio = (int) ((epi.radius - dist_to_epi) * 100) / epi.radius;
|
ratio = (int) (epi.radius - dist_to_epi * 100) / epi.radius;
|
||||||
proba[epi.type-1]=epi.power * ratio;
|
proba[epi.type-1] = proba[epi.type-1] + epi.power * ratio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,13 +136,15 @@ int generate(int x, int y){
|
|||||||
for (i=0;i<5;i++){
|
for (i=0;i<5;i++){
|
||||||
sum += proba[i];
|
sum += proba[i];
|
||||||
}
|
}
|
||||||
val = rand()%sum;
|
|
||||||
|
|
||||||
|
if (sum!=0){
|
||||||
|
val = rand()%sum;
|
||||||
int seuil = 0;
|
int seuil = 0;
|
||||||
for (i=0;i<5;i++){
|
for (i=0;i<5;i++){
|
||||||
seuil += proba[i];
|
seuil += proba[i];
|
||||||
if(val < seuil)
|
if(val < seuil)
|
||||||
return i+1;
|
return i+2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return GRASS;
|
return GRASS;
|
||||||
}
|
}
|
||||||
|
2
main.c
2
main.c
@ -272,7 +272,7 @@ void initSDL()
|
|||||||
SDL_FillRect(img, NULL, SDL_MapRGB(img->format, 255, 255, 255));
|
SDL_FillRect(img, NULL, SDL_MapRGB(img->format, 255, 255, 255));
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Erreur d'initialisation de la SDL");
|
fprintf(stderr, "Erreur d'initialisation de la SDL");// and you don't want my french comment :p
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user