Merge branch 'master' of https://git.tagachop.fr/epicsparrow/PixelWars
This commit is contained in:
commit
79bc7066b0
230
main.c
230
main.c
@ -15,11 +15,13 @@ typedef struct{
|
|||||||
} t_fight;
|
} t_fight;
|
||||||
|
|
||||||
// temp code
|
// temp code
|
||||||
t_action purple_update(void* my_info, void* com_data, int my_id);
|
t_action purple_update(void* my_info, void* com_data, int my_id, int success);
|
||||||
t_action orange_update(void* my_info, void* com_data, int my_id);
|
t_action orange_update(void* my_info, void* com_data, int my_id, int success);
|
||||||
int get_purple_size();
|
int get_purple_size();
|
||||||
int get_orange_size();
|
int get_orange_size();
|
||||||
|
|
||||||
|
t_dude* current_dude;
|
||||||
|
|
||||||
void initWorld(int width, int height){
|
void initWorld(int width, int height){
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -66,7 +68,8 @@ void updateTeam(t_team team){
|
|||||||
int i;
|
int i;
|
||||||
t_action action;
|
t_action action;
|
||||||
for(i=0; i<team.nb_dudes; i++){
|
for(i=0; i<team.nb_dudes; i++){
|
||||||
action = team.update((void*)(team.dudes[i].custom_data), (void*)(team.dudes[i].com_data), i);
|
current_dude = team.dudes + i;
|
||||||
|
action = team.update((void*)(team.dudes[i].custom_data), (void*)(team.dudes[i].com_data), i, team.dudes[i].success);
|
||||||
handleAction(action, team.dudes+i);
|
handleAction(action, team.dudes+i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,6 +92,11 @@ t_coord getPos(t_coord coord, int dir){
|
|||||||
return coord;
|
return coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getNear(int dir){
|
||||||
|
t_coord coord = getPos(current_dude->pos, dir);
|
||||||
|
return map[coord.x][coord.y].type;
|
||||||
|
}
|
||||||
|
|
||||||
void spawnDudes(){
|
void spawnDudes(){
|
||||||
int i;
|
int i;
|
||||||
t_dude new_dude;
|
t_dude new_dude;
|
||||||
@ -102,6 +110,7 @@ void spawnDudes(){
|
|||||||
new_dude.pos = teams[i].spawn;
|
new_dude.pos = teams[i].spawn;
|
||||||
new_dude.team = teams[i].team;
|
new_dude.team = teams[i].team;
|
||||||
new_dude.inventory = -1;
|
new_dude.inventory = -1;
|
||||||
|
new_dude.success = 1;
|
||||||
new_dude.ground = map[teams[i].spawn.x][teams[i].spawn.y];
|
new_dude.ground = map[teams[i].spawn.x][teams[i].spawn.y];
|
||||||
new_dude.custom_data = malloc(teams[i].dude_size);
|
new_dude.custom_data = malloc(teams[i].dude_size);
|
||||||
memset(new_dude.custom_data, 0, teams[i].dude_size);
|
memset(new_dude.custom_data, 0, teams[i].dude_size);
|
||||||
@ -115,8 +124,10 @@ void spawnDudes(){
|
|||||||
void handleAction(t_action action, t_dude* dude){
|
void handleAction(t_action action, t_dude* dude){
|
||||||
t_coord target_pos = getPos(dude->pos, action.dir);
|
t_coord target_pos = getPos(dude->pos, action.dir);
|
||||||
t_pixel target = map[target_pos.x][target_pos.y];
|
t_pixel target = map[target_pos.x][target_pos.y];
|
||||||
|
int* nb_res;
|
||||||
switch(action.type){
|
switch(action.type){
|
||||||
case MOVE :
|
case MOVE :
|
||||||
|
dude->success = 0;
|
||||||
if( target.type != WALL
|
if( target.type != WALL
|
||||||
&& target.type != ROCK
|
&& target.type != ROCK
|
||||||
&& target.type != BEDROCK
|
&& target.type != BEDROCK
|
||||||
@ -127,45 +138,114 @@ void handleAction(t_action action, t_dude* dude){
|
|||||||
add_move(dude, target_pos);
|
add_move(dude, target_pos);
|
||||||
break;
|
break;
|
||||||
case ATTACK :
|
case ATTACK :
|
||||||
printf("forbidden action\n");
|
printf("forbidden action\n"); // TODO : implement that
|
||||||
//if(target.type == DUDE)
|
//if(target.type == DUDE)
|
||||||
// addFight(dude, *((t_dude*)(target.data)));
|
// addFight(dude, *((t_dude*)(target.data)));
|
||||||
break;
|
break;
|
||||||
case PICK :
|
case PICK :
|
||||||
printf("forbidden action\n");
|
nb_res = target.data;
|
||||||
// if target is resource :
|
if(target.type >= FOOD && target.type <= SWORD && dude->inventory == -1){
|
||||||
// put target in inventory
|
dude->inventory = target.type;
|
||||||
// put grass on target
|
(*nb_res)--;
|
||||||
|
if(*nb_res < 1){
|
||||||
|
free(nb_res);
|
||||||
|
map[target_pos.x][target_pos.y].type = GRASS;
|
||||||
|
map[target_pos.x][target_pos.y].data = NULL;
|
||||||
|
}
|
||||||
|
putpixel(img, target_pos.x, target_pos.y, getColor(map[target_pos.x][target_pos.y]));
|
||||||
|
}else
|
||||||
|
dude->success = 0;
|
||||||
break;
|
break;
|
||||||
case PUT :
|
case PUT :
|
||||||
printf("forbidden action\n");
|
if(dude->inventory != -1 && (target.type == GRASS || target.type == dude->inventory)){
|
||||||
// if target is grass or road or corpse
|
if(target.type == GRASS || target.type == MARK){
|
||||||
// target = inventory
|
map[target_pos.x][target_pos.y].type = dude->inventory;
|
||||||
// inventory = NULL
|
nb_res = malloc(sizeof(int));
|
||||||
// else if target is spawn and inventory is food
|
*nb_res = 1;
|
||||||
// spawn.food ++
|
map[target_pos.x][target_pos.y].data = nb_res;
|
||||||
|
}else{
|
||||||
|
nb_res = target.data;
|
||||||
|
(*nb_res)++;
|
||||||
|
}
|
||||||
|
dude->inventory = -1;
|
||||||
|
putpixel(img, target_pos.x, target_pos.y, getColor(map[target_pos.x][target_pos.y]));
|
||||||
|
}else
|
||||||
|
dude->success = 0;
|
||||||
break;
|
break;
|
||||||
case WORK :
|
case WORK :
|
||||||
printf("forbidden action\n");
|
dude->success = 1;
|
||||||
// switch target
|
switch(target.type){
|
||||||
// case rock -> stone
|
case ROCK :
|
||||||
// case berries -> food
|
map[target_pos.x][target_pos.y].type = STONE;
|
||||||
// case tree -> wood
|
nb_res = malloc(sizeof(int));
|
||||||
// case grass -> road
|
*nb_res = 1;
|
||||||
// case road -> grass
|
map[target_pos.x][target_pos.y].data = nb_res;
|
||||||
// case stone -> wall
|
break;
|
||||||
// case wood -> sign
|
case BERRIES :
|
||||||
// case sign -> wood
|
map[target_pos.x][target_pos.y].type = FOOD;
|
||||||
// case iron_ore -> iron
|
nb_res = malloc(sizeof(int));
|
||||||
// case iron -> sword
|
*nb_res = 1;
|
||||||
// case corpse -> grass
|
map[target_pos.x][target_pos.y].data = nb_res;
|
||||||
|
break;
|
||||||
|
case TREE :
|
||||||
|
map[target_pos.x][target_pos.y].type = WOOD;
|
||||||
|
nb_res = malloc(sizeof(int));
|
||||||
|
*nb_res = 1;
|
||||||
|
map[target_pos.x][target_pos.y].data = nb_res;
|
||||||
|
break;
|
||||||
|
case IRON_ORE :
|
||||||
|
map[target_pos.x][target_pos.y].type = IRON;
|
||||||
|
nb_res = malloc(sizeof(int));
|
||||||
|
*nb_res = 1;
|
||||||
|
map[target_pos.x][target_pos.y].data = nb_res;
|
||||||
|
break;
|
||||||
|
case GRASS :
|
||||||
|
map[target_pos.x][target_pos.y].type = MARK;
|
||||||
|
map[target_pos.x][target_pos.y].data = NULL;
|
||||||
|
break;
|
||||||
|
case MARK :
|
||||||
|
map[target_pos.x][target_pos.y].type = GRASS;
|
||||||
|
map[target_pos.x][target_pos.y].data = NULL;
|
||||||
|
break;
|
||||||
|
case WOOD :
|
||||||
|
nb_res = target.data;
|
||||||
|
if(*nb_res != 1)
|
||||||
|
dude->success = 0;
|
||||||
|
else{
|
||||||
|
free(target.data);
|
||||||
|
map[target_pos.x][target_pos.y].type = WALL;
|
||||||
|
map[target_pos.x][target_pos.y].data = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STONE :
|
||||||
|
nb_res = target.data;
|
||||||
|
if(*nb_res != 1)
|
||||||
|
dude->success = 0;
|
||||||
|
else{
|
||||||
|
free(target.data);
|
||||||
|
map[target_pos.x][target_pos.y].type = ROAD;
|
||||||
|
map[target_pos.x][target_pos.y].data = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IRON :
|
||||||
|
nb_res = target.data;
|
||||||
|
if(*nb_res != 1)
|
||||||
|
dude->success = 0;
|
||||||
|
else
|
||||||
|
map[target_pos.x][target_pos.y].type = SWORD;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
dude->success = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(dude->success)
|
||||||
|
putpixel(img, target_pos.x, target_pos.y, getColor(map[target_pos.x][target_pos.y]));
|
||||||
break;
|
break;
|
||||||
case WAIT :
|
case WAIT :
|
||||||
printf("forbidden action\n");
|
dude->success = 1;
|
||||||
// ...
|
|
||||||
break;
|
break;
|
||||||
case COMMUNICATE :
|
case COMMUNICATE :
|
||||||
printf("forbidden action\n");
|
printf("forbidden action\n"); // TODO : implement that
|
||||||
// if target is sign -> set sign message
|
// if target is sign -> set sign message
|
||||||
// if target is dude -> sent message to dude
|
// if target is dude -> sent message to dude
|
||||||
break;
|
break;
|
||||||
@ -173,6 +253,7 @@ void handleAction(t_action action, t_dude* dude){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void generateImg(int width, int height){
|
void generateImg(int width, int height){
|
||||||
|
img = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
|
||||||
int i, j;
|
int i, j;
|
||||||
for(i=0; i<width; i++){
|
for(i=0; i<width; i++){
|
||||||
for(j=0; j<height; j++){
|
for(j=0; j<height; j++){
|
||||||
@ -181,28 +262,51 @@ void generateImg(int width, int height){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initSDL(int width, int height, int fullscreen)
|
SDL_Surface* initSDL(int width, int height, int fullscreen)
|
||||||
{
|
{
|
||||||
|
SDL_Surface* screen;
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
if(fullscreen)
|
if(fullscreen)
|
||||||
img = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
|
screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
|
||||||
else
|
else
|
||||||
img = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
||||||
SDL_WM_SetCaption("Pixel Wars", NULL);
|
SDL_WM_SetCaption("Pixel Wars", NULL);
|
||||||
SDL_FillRect(img, NULL, SDL_MapRGB(img->format, 255, 255, 255));
|
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->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");// and you don't want my french comment :p
|
fprintf(stderr, "Erreur d'initialisation de la SDL");// and you don't want my french comment :p
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
return screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render(SDL_Surface* screen, int x_offset, int y_offset, int zoom_level){
|
||||||
|
int i, j, x, y;
|
||||||
|
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||||
|
for(i=0; i<screen->w; i++){
|
||||||
|
for(j=0; j<screen->h; j++){
|
||||||
|
x = (i - img->w/2)/zoom_level + x_offset;
|
||||||
|
y = (j - img->h/2)/zoom_level + y_offset;
|
||||||
|
if(x >= 0 && x < img->w && y >= 0 && y < img->h)
|
||||||
|
putpixel(screen, i, j, getpixel(img, x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MAIN
|
int MAIN
|
||||||
{
|
{
|
||||||
|
SDL_Surface* screen;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int i;
|
int i;
|
||||||
|
int paused = 0;
|
||||||
|
int x_offset = 0;
|
||||||
|
int y_offset = 0;
|
||||||
|
int zoom_level = 1;
|
||||||
int over = 0;
|
int over = 0;
|
||||||
|
int time = 0;
|
||||||
int wait_time = 100;
|
int wait_time = 100;
|
||||||
|
int new_time = 0;
|
||||||
|
int remaining_time = -1;
|
||||||
int fullscreen = 0;
|
int fullscreen = 0;
|
||||||
int width = DEFAULT_WIDTH;
|
int width = DEFAULT_WIDTH;
|
||||||
int height = DEFAULT_HEIGHT;
|
int height = DEFAULT_HEIGHT;
|
||||||
@ -215,9 +319,6 @@ int MAIN
|
|||||||
case 'f' :
|
case 'f' :
|
||||||
fullscreen = 1;
|
fullscreen = 1;
|
||||||
break;
|
break;
|
||||||
case 't' :
|
|
||||||
wait_time = atoi(argv[0]+2);
|
|
||||||
break;
|
|
||||||
case 'w' :
|
case 'w' :
|
||||||
width = atoi(argv[0]+2);
|
width = atoi(argv[0]+2);
|
||||||
break;
|
break;
|
||||||
@ -228,15 +329,19 @@ int MAIN
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
argv++;
|
argv++;
|
||||||
|
argc--;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
initSDL(width, height, fullscreen);
|
screen = initSDL(width, height, fullscreen);
|
||||||
initWorld(width, height);
|
initWorld(width, height);
|
||||||
SDL_Flip(img);
|
SDL_Flip(img);
|
||||||
|
|
||||||
|
x_offset = width/2;
|
||||||
|
y_offset = height/2;
|
||||||
printf("Launching simulation...\n");
|
printf("Launching simulation...\n");
|
||||||
|
|
||||||
|
time = SDL_GetTicks();
|
||||||
while (!over){
|
while (!over){
|
||||||
while(SDL_PollEvent(&event)){
|
while(SDL_PollEvent(&event)){
|
||||||
switch (event.type){
|
switch (event.type){
|
||||||
@ -245,10 +350,44 @@ int MAIN
|
|||||||
case SDLK_ESCAPE :
|
case SDLK_ESCAPE :
|
||||||
over = 1;
|
over = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_w :
|
||||||
|
y_offset -= 5;
|
||||||
|
break;
|
||||||
|
case SDLK_s :
|
||||||
|
y_offset += 5;
|
||||||
|
break;
|
||||||
|
case SDLK_a :
|
||||||
|
x_offset -= 5;
|
||||||
|
break;
|
||||||
|
case SDLK_d :
|
||||||
|
x_offset += 5;
|
||||||
|
break;
|
||||||
|
case SDLK_UP :
|
||||||
|
wait_time *= 2;
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN :
|
||||||
|
if(wait_time > 2)
|
||||||
|
wait_time /= 2;
|
||||||
|
break;
|
||||||
|
case SDLK_LEFT :
|
||||||
|
zoom_level++;
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT :
|
||||||
|
zoom_level--;
|
||||||
|
if(zoom_level < 1)
|
||||||
|
zoom_level = 1;
|
||||||
|
break;
|
||||||
|
case SDLK_SPACE :
|
||||||
|
paused = !paused;
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
x_offset += event.motion.xrel;
|
||||||
|
y_offset += event.motion.yrel;
|
||||||
|
break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
over = 1;
|
over = 1;
|
||||||
break;
|
break;
|
||||||
@ -257,15 +396,24 @@ int MAIN
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_time = SDL_GetTicks();
|
||||||
|
remaining_time -= new_time - time;
|
||||||
|
time = new_time;
|
||||||
|
if(remaining_time < 0 && !paused){
|
||||||
spawnDudes();
|
spawnDudes();
|
||||||
for(i=0; i<NB_TEAMS; i++)
|
for(i=0; i<NB_TEAMS; i++)
|
||||||
updateTeam(teams[i]);
|
updateTeam(teams[i]);
|
||||||
resolve_moves();
|
resolve_moves();
|
||||||
|
|
||||||
SDL_Delay(wait_time);
|
remaining_time = wait_time;
|
||||||
SDL_Flip(img);
|
|
||||||
}
|
}
|
||||||
SDL_FreeSurface(img);
|
|
||||||
|
render(screen, x_offset, y_offset, zoom_level);
|
||||||
|
|
||||||
|
SDL_Delay(30);
|
||||||
|
SDL_Flip(screen);
|
||||||
|
}
|
||||||
|
SDL_FreeSurface(screen);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
4
main.h
4
main.h
@ -12,6 +12,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAX_DUDES 50
|
#define MAX_DUDES 50
|
||||||
|
#define STACK_SIZE 5
|
||||||
#define DEFAULT_WIDTH 400
|
#define DEFAULT_WIDTH 400
|
||||||
#define DEFAULT_HEIGHT 250
|
#define DEFAULT_HEIGHT 250
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ typedef struct{
|
|||||||
t_coord pos;
|
t_coord pos;
|
||||||
int team;
|
int team;
|
||||||
int inventory;
|
int inventory;
|
||||||
|
int success;
|
||||||
t_pixel ground;
|
t_pixel ground;
|
||||||
void* custom_data;
|
void* custom_data;
|
||||||
void* com_data;
|
void* com_data;
|
||||||
@ -37,7 +39,7 @@ typedef struct{
|
|||||||
typedef struct{
|
typedef struct{
|
||||||
int team;
|
int team;
|
||||||
int dude_size;
|
int dude_size;
|
||||||
t_action (*update)(void*, void*, int);
|
t_action (*update)(void*, void*, int, int);
|
||||||
int nb_dudes;
|
int nb_dudes;
|
||||||
t_dude* dudes;
|
t_dude* dudes;
|
||||||
t_coord spawn;
|
t_coord spawn;
|
||||||
|
2
orange.c
2
orange.c
@ -11,7 +11,7 @@ int get_orange_size(){
|
|||||||
return sizeof(t_data);
|
return sizeof(t_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_action orange_update(void* my_info, void* com_data, int my_id){
|
t_action orange_update(void* my_info, void* com_data, int my_id, int success){
|
||||||
t_data* data = (t_data*)my_info;
|
t_data* data = (t_data*)my_info;
|
||||||
t_action action;
|
t_action action;
|
||||||
|
|
||||||
|
54
purple.c
54
purple.c
@ -4,20 +4,68 @@
|
|||||||
// Hello World
|
// Hello World
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int plop; // custom info
|
t_coord pos;
|
||||||
|
int try;
|
||||||
|
int brings_food;
|
||||||
} t_data;
|
} t_data;
|
||||||
|
|
||||||
int get_purple_size(){
|
int get_purple_size(){
|
||||||
return sizeof(t_data);
|
return sizeof(t_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_action purple_update(void* my_info, void* com_data, int my_id){
|
t_coord getPos(t_coord coord, int dir);
|
||||||
|
|
||||||
|
t_action purple_update(void* my_info, void* com_data, int my_id, int success){
|
||||||
t_data* data = (t_data*)my_info;
|
t_data* data = (t_data*)my_info;
|
||||||
t_action action;
|
t_action action;
|
||||||
|
int i, type;
|
||||||
|
|
||||||
|
if(data->try && success)
|
||||||
|
data->brings_food = 1;
|
||||||
|
data->try = 0;
|
||||||
|
|
||||||
|
if(data->brings_food){
|
||||||
|
if(data->pos.x == 0)
|
||||||
|
action.dir = WEST;
|
||||||
|
else{
|
||||||
|
if(data->pos.y == 0){
|
||||||
|
if(data->pos.x > 0)
|
||||||
|
action.dir = EAST;
|
||||||
|
else
|
||||||
|
action.dir = WEST;
|
||||||
|
if(data->pos.x == -1 || data->pos.x == 1){
|
||||||
|
data->brings_food = 0;
|
||||||
|
action.type = PUT;
|
||||||
|
action.data = NULL;
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
action.dir = data->pos.y > 0 ? SOUTH : NORTH;
|
||||||
|
}
|
||||||
|
action.type = MOVE;
|
||||||
|
action.data = NULL;
|
||||||
|
data->pos = getPos(data->pos, action.dir);
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<4; i++){
|
||||||
|
type = getNear(i);
|
||||||
|
if(type == BERRIES || type == TREE || type == IRON_ORE || type == ROCK){
|
||||||
|
action.type = WORK;
|
||||||
|
action.dir = i;
|
||||||
|
action.data = NULL;
|
||||||
|
return action;
|
||||||
|
}else if(type == FOOD){
|
||||||
|
action.type = PICK;
|
||||||
|
action.dir = i;
|
||||||
|
action.data = NULL;
|
||||||
|
data->try = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
action.type = MOVE;
|
action.type = MOVE;
|
||||||
action.dir = rand()%4;
|
action.dir = rand()%4;
|
||||||
action.data = NULL;
|
action.data = NULL;
|
||||||
|
data->pos = getPos(data->pos, action.dir);
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
6
team.h
6
team.h
@ -9,9 +9,9 @@ enum{
|
|||||||
// Tile types
|
// Tile types
|
||||||
enum{
|
enum{
|
||||||
BEDROCK, GRASS, TREE, BERRIES, ROCK, IRON_ORE, // nature
|
BEDROCK, GRASS, TREE, BERRIES, ROCK, IRON_ORE, // nature
|
||||||
FOOD, WOOD, STONE, IRON, // resources
|
FOOD, WOOD, STONE, IRON, SWORD, // resources
|
||||||
CORPSE, DUDE, // humans
|
DUDE, // humans
|
||||||
SPAWN, WALL, ROAD, SWORD, SIGN // buildings
|
SPAWN, WALL, ROAD, MARK, SIGN // buildings
|
||||||
};
|
};
|
||||||
|
|
||||||
// Action types
|
// Action types
|
||||||
|
3
tools.c
3
tools.c
@ -32,6 +32,8 @@ void applyMove(t_move* move){
|
|||||||
putpixel(img, move->dude->pos.x, move->dude->pos.y, getColor(map[move->dude->pos.x][move->dude->pos.y]));
|
putpixel(img, move->dude->pos.x, move->dude->pos.y, getColor(map[move->dude->pos.x][move->dude->pos.y]));
|
||||||
move->dude->pos.x = move->dst.x;
|
move->dude->pos.x = move->dst.x;
|
||||||
move->dude->pos.y = move->dst.y;
|
move->dude->pos.y = move->dst.y;
|
||||||
|
move->dude->success = 1;
|
||||||
|
free(move);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resolve_moves(){
|
void resolve_moves(){
|
||||||
@ -74,7 +76,6 @@ Uint32 getColor(t_pixel pixel){
|
|||||||
case WOOD : return 0x634A22;
|
case WOOD : return 0x634A22;
|
||||||
case STONE : return 0x454545;
|
case STONE : return 0x454545;
|
||||||
case IRON : return 0x4A4036;
|
case IRON : return 0x4A4036;
|
||||||
case CORPSE : return 0xFF0000;
|
|
||||||
case DUDE :
|
case DUDE :
|
||||||
dudeData = pixel.data;
|
dudeData = pixel.data;
|
||||||
return dudeData->team == ORANGE ? 0x7A4100 : 0x9900FF;
|
return dudeData->team == ORANGE ? 0x7A4100 : 0x9900FF;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user