Skip to content

Commit

Permalink
Merge pull request #30 from beergame/staging
Browse files Browse the repository at this point in the history
V1.3
  • Loading branch information
victorbalssa authored Jul 8, 2017
2 parents 96ff702 + d3d8539 commit a82cb04
Show file tree
Hide file tree
Showing 47 changed files with 385 additions and 213 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*.so
*.so.*
*.dylib

*.gif
*.xcf
# Executables
*.exe
*.out
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ all: $(NAME)

$(NAME): $(OBJS)
@echo "> Build BeerBomber"
@$(CC) $(OBJS) $(CFLAGS) -lpthread $(SDLFLAGS) -o $(NAME)
@$(CC) $(OBJS) $(CFLAGS) -lpthread -lm $(SDLFLAGS) -o $(NAME)
@echo "> Done."

clean:
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# BeerBomber [![Build Status](https://travis-ci.org/beergame/BeerBomber.svg?branch=staging)](https://travis-ci.org/beergame/BeerBomber)
# BeerBomber [![Build Status](https://travis-ci.org/beergame/BeerBomber.svg?branch=master)](https://travis-ci.org/beergame/BeerBomber)

Bomberman clone in C/SDL 360 controller ready
<img src="http://i.imgur.com/K4qCCiq.png" width="3%"/>
<br />
<br />
<br />
<img src="http://i.imgur.com/Lc3yNCj.gif" width="70%" />

<img src="http://i.imgur.com/CoZeX0U.gif" />

# Build BeerBomber

Expand Down Expand Up @@ -34,4 +33,4 @@ You will have an executable named `beerbomber` that you can run


# Contributor
[Aurelien Paranavithana](https://github.com/AurelienParana), [Roland Coulibaly](https://github.com/rolandcoulibaly), [Victor Balssa](https://github.com/Nandotk), [Simon Garreau-Férandin](https://github.com/garreas)
[Aurelien Paranavithana](https://github.com/AurelienParana), [Roland Coulibaly](https://github.com/rolandcoulibaly), [Victor Balssa](https://github.com/victorbalssa), [Simon Garreau-Férandin](https://github.com/garreas)
Binary file modified gfx/bomb/bomb_stand_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/bomb/tnt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/map/beer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/map/block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified gfx/map/fire_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/map/fire_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/map/fire_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gfx/scratch/bomb_set.wav
Binary file not shown.
Binary file added gfx/scratch/bomb_timer.wav
Binary file not shown.
Binary file added gfx/scratch/confirm.wav
Binary file not shown.
Binary file added gfx/scratch/explose.wav
Binary file not shown.
Binary file added gfx/scratch/music.wav
Binary file not shown.
Binary file added gfx/scratch/out.wav
Binary file not shown.
Binary file added gfx/scratch/pause.wav
Binary file not shown.
Binary file added gfx/scratch/select.wav
Binary file not shown.
Binary file added gfx/scratch/walk.wav
Binary file not shown.
23 changes: 14 additions & 9 deletions src/bomb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void fire_action_on_bush(t_env *e)
for (int j = 0; j < MAP_SIZE; ++j) {
if ((e->map[i][j].data[0] == '0' &&
e->map[i][j].data[1] == '1') &&
e->map[i][j].data[4] == '1') {
e->map[i][j].data[4] != '0') {
e->map[i][j].data[1] = '0';
}
}
Expand All @@ -19,7 +19,7 @@ void fire_action_on_player(t_env *e)

for (int i = 0; i < MAX_PLAYER; ++i) {
if (p[i]->connected == 1 &&
e->map[p[i]->x][p[i]->y].data[4] == '1') {
e->map[p[i]->x / PRES][p[i]->y / PRES].data[4] != '0') {
p[i]->life--;
if (p[i]->life == 0) {
p[i]->x = 0;
Expand All @@ -31,33 +31,34 @@ void fire_action_on_player(t_env *e)

void throw_fire(t_env *e, t_timer *t, char c)
{
for (int i = t->x; i < (t->x + 3); i++) {
e->map[t->x][t->y].data[4] = (c == '0') ? '0' : '1';
for (int i = t->x + 1; i < (t->x + 3); i++) {
if (e->map[i][t->y].data[0] == '1' &&
e->map[i][t->y].data[1] == '1') {
break ;
}
e->map[i][t->y].data[4] = c;
e->map[i][t->y].data[4] = (c == '0') ? '0' : '3';
}
for (int i = t->x - 1; i > (t->x - 3); i--) {
if (e->map[i][t->y].data[0] == '1' &&
e->map[i][t->y].data[1] == '1') {
break ;
}
e->map[i][t->y].data[4] = c;
e->map[i][t->y].data[4] = (c == '0') ? '0' : '3';
}
for (int i = t->y + 1; i < (t->y + 3); i++) {
if (e->map[t->x][i].data[0] == '1' &&
e->map[t->x][i].data[1] == '1') {
break ;
}
e->map[t->x][i].data[4] = c;
e->map[t->x][i].data[4] = (c == '0') ? '0' : '2';
}
for (int i = t->y - 1; i > (t->y - 3); i--) {
if (e->map[t->x][i].data[0] == '1' &&
e->map[t->x][i].data[1] == '1') {
break ;
}
e->map[t->x][i].data[4] = c;
e->map[t->x][i].data[4] = (c == '0') ? '0' : '2';
}
fire_action_on_bush(e);
fire_action_on_player(e);
Expand All @@ -68,15 +69,19 @@ void throw_fire(t_env *e, t_timer *t, char c)
void do_timing_entity(t_env *e)
{
int i = 0;

clock_t now = clock();

while (e->timer[i] != NULL) {
if (e->timer[i]->status == 1 &&
(now - e->timer[i]->start) > FIRE_LIFETIME) {
((now - e->timer[i]->start) * 1000 / CLOCKS_PER_SEC)
> FIRE_TIMER) {
throw_fire(e, e->timer[i], '0');
}
if (e->timer[i]->status == 0 &&
(now - e->timer[i]->start) > BOMB_LIFETIME) {
((now - e->timer[i]->start) * 1000 / CLOCKS_PER_SEC)
> BOMB_TIMER) {
e->info->throw_bomb = 2;
e->map[e->timer[i]->x][e->timer[i]->y].data[3] = '0';
throw_fire(e, e->timer[i], '1');
}
Expand Down
2 changes: 2 additions & 0 deletions src/bomb.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

# include "server.h"

int pres_co(int, int);

#endif /* __BOMB_H__ */
3 changes: 3 additions & 0 deletions src/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ void clean_client(t_game *g)
{
/* free sprites and map */
free_sprites();
free_sound(g);
free_map(g->map);

/* Close the font */
Expand All @@ -19,5 +20,7 @@ void clean_client(t_game *g)
/* Shut down SDL */
SDL_DestroyRenderer(g->renderer);
SDL_DestroyWindow(g->screen);
Mix_Quit();
IMG_Quit();
SDL_Quit();
}
2 changes: 2 additions & 0 deletions src/clean.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

void free_sprites();

void free_sound(t_game *g);

void free_map(t_map **);

void close_font(TTF_Font *);
Expand Down
25 changes: 16 additions & 9 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ void unserialize_response(char *buffer, t_game *g)
char **buff;
char **buff2;

response = my_str_to_wordtab(buffer, ' ');
buff = my_str_to_wordtab(response[0], ':');
if (!(response = my_str_to_wordtab(buffer, ' ')))
return ;
if (!(buff = my_str_to_wordtab(response[0], ':')))
return ;
g->info->status = atoi(buff[0]);
g->info->playermax = atoi(buff[1]);
g->info->max_player = atoi(buff[1]);
g->info->winner = atoi(buff[2]);
g->info->throw_bomb = atoi(buff[3]);
g->info->player_boost = atoi(buff[4]);

buff = my_str_to_wordtab(response[1], ';');
if (!(buff = my_str_to_wordtab(response[1], ';')))
return ;
for (int i = 0; i < MAX_PLAYER; i++) {
if ((buff2 = my_str_to_wordtab(buff[i], ':'))) {
if (g->player[i] != NULL) {
Expand All @@ -87,9 +92,11 @@ void unserialize_response(char *buffer, t_game *g)
}
}

buff = my_str_to_wordtab(response[2], ';');
if (!(buff = my_str_to_wordtab(response[2], ';')))
return ;
for (int i = 0; i < MAP_SIZE; ++i) {
buff2 = my_str_to_wordtab(buff[i], ':');
if (!(buff2 = my_str_to_wordtab(buff[i], ':')))
return ;
for (int j = 0; j < MAP_SIZE; ++j) {
g->map[i][j].data = buff2[j];
}
Expand Down Expand Up @@ -119,7 +126,7 @@ void all_players_connected(t_game *g)
a++;
}
}
if (g->info->playermax == a) {
if (g->info->max_player == a) {
g->info->status = IN_CONFIG_NEW_GAME;
}
}
Expand Down Expand Up @@ -151,6 +158,7 @@ void client_beer_bomber(t_game *game)

/* connect to server */
SDL_Delay(400);
draw_wait_for_player(game);
printf("Server beerbomber IP: ");
fgets(ip, sizeof(ip), stdin);
int server = client_connect(ip);
Expand All @@ -168,9 +176,8 @@ void client_beer_bomber(t_game *game)
send_request(server, game);
get_response(server, game);
draw(game);
if (one_left(game)) {
if (one_left(game))
go = 1;
}
} else if (game->info->status == WAIT_FOR_PLAYER) {
go = get_input(game);
send_request(server, game);
Expand Down
54 changes: 32 additions & 22 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@ void draw_nb_player(t_game *game, int i);

void is_new_game(t_game *game, int *c)
{
if (game->input->left) {
*c = *c - 1;
} else if (game->input->right) {
*c = *c + 1;
if (game->input->left && (*c == 3)) {
Mix_PlayChannel(-1, game->sounds[6].effect, 0);
(*c)--;
} else if (game->input->right && (*c == 2)) {
Mix_PlayChannel(-1, game->sounds[6].effect, 0);
(*c)++;
} else if (game->input->fire) {
Mix_PlayChannel(-1, game->sounds[3].effect, 0);
if (*c == 2) {
game->info->status = IN_CONFIG_NB_PLAYER;
} else {
game->info->status = WAIT_FOR_PLAYER;
}
}
(*c < 2) ? *c = 2: 0;
(*c > 3) ? *c = 3: 0;
draw_is_new_game(game, *c);
}

void choose_nb_player(t_game *game, int *nb)
{
if (game->input->left) {
if (game->input->left && (*nb != 2)) {
Mix_PlayChannel(-1, game->sounds[6].effect, 0);
*nb = 2;
} else if (game->input->up) {
} else if (game->input->up && (*nb != 3)) {
Mix_PlayChannel(-1, game->sounds[6].effect, 0);
*nb = 3;
} else if (game->input->right) {
} else if (game->input->right && (*nb != 4)) {
Mix_PlayChannel(-1, game->sounds[6].effect, 0);
*nb = 4;
} else if (game->input->fire) {
Mix_PlayChannel(-1, game->sounds[3].effect, 0);
game->info->status = WAIT_FOR_PLAYER;
}
draw_nb_player(game, *nb);
Expand All @@ -44,19 +49,19 @@ void draw_nb_player(t_game *game, int c)

switch (c) {
case 2:
drawBtn(game, 250, 380, BTN_2_PLAYER);
drawBtn(game, 550, 380, BTN_3_PLAYER_B);
drawBtn(game, 850, 380, BTN_4_PLAYER_B);
draw_btn(game, 250, 380, BTN_2_PLAYER);
draw_btn(game, 550, 380, BTN_3_PLAYER_B);
draw_btn(game, 850, 380, BTN_4_PLAYER_B);
break;
case 3:
drawBtn(game, 250, 380, BTN_2_PLAYER_B);
drawBtn(game, 550, 380, BTN_3_PLAYER);
drawBtn(game, 850, 380, BTN_4_PLAYER_B);
draw_btn(game, 250, 380, BTN_2_PLAYER_B);
draw_btn(game, 550, 380, BTN_3_PLAYER);
draw_btn(game, 850, 380, BTN_4_PLAYER_B);
break;
case 4:
drawBtn(game, 250, 380, BTN_2_PLAYER_B);
drawBtn(game, 550, 380, BTN_3_PLAYER_B);
drawBtn(game, 850, 380, BTN_4_PLAYER);
draw_btn(game, 250, 380, BTN_2_PLAYER_B);
draw_btn(game, 550, 380, BTN_3_PLAYER_B);
draw_btn(game, 850, 380, BTN_4_PLAYER);
break;
default:
break;
Expand All @@ -71,20 +76,25 @@ void draw_nb_player(t_game *game, int c)

void draw_is_new_game(t_game *game, int c)
{
char text[50];

/* Blank the screen */
SDL_RenderClear(game->renderer);

/* Draw background */
draw_background(game, MAP_BACK_ONE);

if (c == 2) {
drawBtn(game, 300, 380, BTN_NEWGAME);
drawBtn(game, 800, 380, BTN_JOINGAME_B);
draw_btn(game, 300, 380, BTN_NEWGAME);
draw_btn(game, 800, 380, BTN_JOINGAME_B);
} else {
drawBtn(game, 300, 380, BTN_NEWGAME_B);
drawBtn(game, 800, 380, BTN_JOINGAME);
draw_btn(game, 300, 380, BTN_NEWGAME_B);
draw_btn(game, 800, 380, BTN_JOINGAME);
}

sprintf(text, "BEER BOMBER THE GAME.");
draw_string(game, text, 50, 150, game->font, 1, 0);

/* Update the buffer */
SDL_RenderPresent(game->renderer);

Expand Down
4 changes: 2 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ void flush_inputs(void);

int get_single_input(void);

void drawString(t_game*, char *, int, int, TTF_Font *, int, int);
void draw_string(t_game*, char *, int, int, TTF_Font *, int, int);

void draw_background(t_game *, int);

void draw_is_new_game(t_game *, int);

void draw_nb_player(t_game *, int);

void drawBtn(t_game *, int, int, int);
void draw_btn(t_game *, int, int, int);

#endif /* __CONFIG_H__ */
Loading

0 comments on commit a82cb04

Please sign in to comment.