Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #2

Open
wants to merge 1 commit into
base: Projet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added sources/bin/bombeirb
Binary file not shown.
23 changes: 20 additions & 3 deletions sources/include/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ enum cell_type {
CELL_EMPTY=0x00, // 0000 0000
CELL_SCENERY=0x10, // 0001 0000
CELL_BOX=0x20, // 0010 0000
CELL_DOOR=0x30, // 0011 0000
CELL_DOOR=0x30, // 0011 0000
CELL_KEY=0x40, // 0100 0000
CELL_BONUS=0x50, // 0101 0000
CELL_MONSTER=0x60, // 0110 0000
CELL_BOMB=0x70 // 0111 0000

};
enum door_type{
DOOR_CLOSED,
DOOR_OPENED
};

enum monster_type{
MONSTER_NORTH,
MONSTER_SOUTH,
MONSTER_WEST,
MONSTER_EAST
};
enum bonus_type {
BONUS_BOMB_RANGE_DEC=1,
BONUS_BOMB_RANGE_INC,
Expand All @@ -28,7 +38,7 @@ enum bonus_type {

enum scenery_type {
SCENERY_STONE, // 0000
SCENERY_TREE, // 0010
SCENERY_TREE, // 0001
SCENERY_PRINCESS // 0010
};

Expand All @@ -43,8 +53,15 @@ enum compose_type {
CELL_BOX_BOMBDEC = CELL_BOX | BONUS_BOMB_NB_INC,
CELL_BOX_LIFE = CELL_BOX | BONUS_MONSTER,
CELL_BOX_MONSTER = CELL_BOX | BONUS_LIFE,
};

CELL_CLOSED = CELL_DOOR | DOOR_CLOSED,
CELL_OPENED = CELL_DOOR | DOOR_OPENED,

CELL_MONSTER_N = CELL_MONSTER | MONSTER_NORTH,
CELL_MONSTER_S = CELL_MONSTER | MONSTER_SOUTH,
CELL_MONSTER_W = CELL_MONSTER | MONSTER_WEST,
CELL_MONSTER_E = CELL_MONSTER | MONSTER_EAST
};
struct map;

// Create a new empty map
Expand Down
2 changes: 2 additions & 0 deletions sources/include/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ SDL_Surface* sprite_get_key();
SDL_Surface* sprite_get_stone();
SDL_Surface* sprite_get_door_opened();
SDL_Surface* sprite_get_door_closed();
SDL_Surface* sprite_get_bomb();
SDL_Surface* sprite_get_monster(enum direction direction);

SDL_Surface* sprite_get_number(short number);
SDL_Surface* sprite_get_banner_life();
Expand Down
47 changes: 43 additions & 4 deletions sources/src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ void game_banner_display(struct game* game) {
for (int i = 0; i < map_get_width(map); i++)
window_display_image(sprite_get_banner_line(), i * SIZE_BLOC, y);

int white_bloc = ((map_get_width(map) * SIZE_BLOC) - 6 * SIZE_BLOC) / 4;
int white_bloc = ((map_get_width(map) * SIZE_BLOC) - 11 * SIZE_BLOC) / 4;
int x = white_bloc;
y = (map_get_height(map) * SIZE_BLOC) + LINE_HEIGHT;
window_display_image(sprite_get_banner_life(), x, y);

x = white_bloc + SIZE_BLOC;
window_display_image(sprite_get_number(2), x, y);
window_display_image(
sprite_get_number(player_get_nb_pv(game_get_player(game))), x, y);

x = 2 * white_bloc + 2 * SIZE_BLOC;
window_display_image(sprite_get_banner_bomb(), x, y);
Expand All @@ -82,6 +83,20 @@ void game_banner_display(struct game* game) {

x = 3 * white_bloc + 5 * SIZE_BLOC;
window_display_image(sprite_get_number(1), x, y);

x = 4 * white_bloc + 6 * SIZE_BLOC;
window_display_image(sprite_get_key(), x, y);

x = 4 * white_bloc + 7* SIZE_BLOC;
window_display_image(
sprite_get_number(player_get_nb_key(game_get_player(game))), x, y);

x = 5 * white_bloc + 8 * SIZE_BLOC;
window_display_image(sprite_get_door_closed(), x, y);

x = 5 * white_bloc + 9* SIZE_BLOC;
window_display_image(
sprite_get_number(game->current_level), x, y);
}

void game_display(struct game* game) {
Expand All @@ -92,10 +107,27 @@ void game_display(struct game* game) {
game_banner_display(game);
map_display(game_get_current_map(game));
player_display(game->player);

window_refresh();
}

void pause(){
SDL_Event event;
int continu=1;
while (continu){
SDL_WaitEvent(&event);
switch (event.type) {
case SDL_KEYDOWN :
switch (event.key.keysym.sym) {
case SDLK_p :
continu=0;
break;
default : break;
}
break;
default : break;
}
}
}
static short input_keyboard(struct game* game) {
SDL_Event event;
struct player* player = game_get_player(game);
Expand All @@ -108,6 +140,7 @@ static short input_keyboard(struct game* game) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
game_free(game);
return 1;
case SDLK_UP:
player_set_current_way(player, NORTH);
Expand All @@ -126,9 +159,15 @@ static short input_keyboard(struct game* game) {
player_move(player, map);
break;
case SDLK_SPACE:
if ((player_get_nb_bomb(player)>0) &&( map_get_cell_type(map , player_get_x(player) , player_get_y (player))==CELL_EMPTY)){
player_dec_nb_bomb(player);
map_set_cell_type(map,player_get_x(player),player_get_y(player),CELL_BOMB);
}
break;
default:
case SDLK_p :
pause();
break;
default : break;
}

break;
Expand Down
52 changes: 43 additions & 9 deletions sources/src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct map* map_new(int width, int height)
int map_is_inside(struct map* map, int x, int y)
{
assert(map);
if ((x<0)||(y<0)||(x>map_get_width(map)-1)||(y>map_get_height(map)-1))
return 0;
return 1;
}

Expand All @@ -75,7 +77,7 @@ int map_get_height(struct map* map)

enum cell_type map_get_cell_type(struct map* map, int x, int y)
{
assert(map && map_is_inside(map, x, y));
//assert(map && map_is_inside(map, x, y));
return map->grid[CELL(x,y)] & 0xf0;
}

Expand Down Expand Up @@ -119,13 +121,40 @@ void display_scenery(struct map* map, int x, int y, unsigned char type)
break;
}
}

void display_door(struct map* map, int x, int y, unsigned char type)
{
switch (type & 0x0f) { // sub-types are encoded with the 4 less significant bits
case DOOR_CLOSED:
window_display_image(sprite_get_door_closed(), x, y);
break;

case DOOR_OPENED:
window_display_image(sprite_get_door_opened(), x, y);
break;
}
}
void display_monster(struct map* map, int x, int y, unsigned char type){
switch (type & 0x0f) { // sub-types are encoded with the 4 less significant bits
case MONSTER_NORTH:
window_display_image(sprite_get_monster(NORTH), x, y);
break;
case MONSTER_SOUTH:
window_display_image(sprite_get_monster(SOUTH), x, y);
break;
case MONSTER_WEST:
window_display_image(sprite_get_monster(WEST), x, y);
break;
case MONSTER_EAST:
window_display_image(sprite_get_monster(EAST), x, y);
break;
}
}
void map_display(struct map* map)
{
assert(map != NULL);
assert(map->height > 0 && map->width > 0);

int x, y;
int x, y ;
for (int i = 0; i < map->width; i++) {
for (int j = 0; j < map->height; j++) {
x = i * SIZE_BLOC;
Expand All @@ -147,9 +176,14 @@ void map_display(struct map* map)
window_display_image(sprite_get_key(), x, y);
break;
case CELL_DOOR:
// pas de gestion du type de porte
window_display_image(sprite_get_door_opened(), x, y);
display_door(map,x,y,type);
break;
case CELL_BOMB:
window_display_image(sprite_get_bomb(),x,y);
break;
case CELL_MONSTER:
display_monster(map,x,y,type);
break;
}
}
}
Expand All @@ -160,18 +194,18 @@ struct map* map_get_static(void)
struct map* map = map_new(STATIC_MAP_WIDTH, STATIC_MAP_HEIGHT);

unsigned char themap[STATIC_MAP_WIDTH * STATIC_MAP_HEIGHT] = {
CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_KEY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
CELL_STONE, CELL_STONE, CELL_STONE, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_BOX, CELL_STONE, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_BOX, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_BOX, CELL_STONE, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_BOX, CELL_STONE, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_STONE, CELL_STONE, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_CLOSED, CELL_EMPTY, CELL_STONE, CELL_STONE, CELL_STONE, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY , CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_TREE, CELL_BOX, CELL_TREE, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_TREE, CELL_BOX, CELL_TREE, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_MONSTER_E, CELL_EMPTY,
CELL_EMPTY, CELL_TREE, CELL_TREE, CELL_TREE, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_STONE, CELL_EMPTY, CELL_EMPTY,
CELL_BOX, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_STONE, CELL_BOX_LIFE, CELL_EMPTY,
CELL_BOX, CELL_EMPTY, CELL_DOOR, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
CELL_BOX, CELL_EMPTY, CELL_CLOSED, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY, CELL_EMPTY,
};

for (int i = 0; i < STATIC_MAP_WIDTH * STATIC_MAP_HEIGHT; i++)
Expand Down
Loading