void map_display(t_map map, SDL_Surface *screen) { int i, j; assert(map != NULL); assert(screen != NULL); assert(map->height > 0 && map->width > 0); assert(map->img_bonus_bomb_nb_dec != NULL); assert(map->img_bonus_bomb_nb_inc != NULL); assert(map->img_bonus_bomb_range_dec != NULL); assert(map->img_bonus_bomb_range_inc != NULL); assert(map->img_closed_door != NULL); assert(map->img_door != NULL); assert(map->img_key != NULL); assert(map->img_stone != NULL); assert(map->img_box != NULL); assert(map->img_goal != NULL); assert(map->img_bomberwoman != NULL); for (i = 0; i < map->width; i++) { for (j = 0; j < map->height; j++) { SDL_Rect place; place.x = i * SIZE_BLOC; place.y = j * SIZE_BLOC; t_cell_type_ type = map->grid[CELL(i, j)]; switch (type & 15) { // type is encoded with 4 bits (the & 15 (1111)) is a mask to keep the four less significant bits) case CELL_GOAL: SDL_BlitSurface(map->img_goal, NULL, screen, &place); break; case CELL_SCENERY: display_scenery(map, screen, &place, type); break; case CELL_CASE: SDL_BlitSurface(map->img_box, NULL, screen, &place); break; case CELL_BONUS: display_bonus(map, screen, &place, type); break; case CELL_KEY: SDL_BlitSurface(map->img_key, NULL, screen, &place); break; case CELL_DOOR: SDL_BlitSurface(map->img_door, NULL, screen, &place); break; case CELL_CLOSED_DOOR: SDL_BlitSurface(map->img_closed_door, NULL, screen, &place); break; case CELL_BOMBERWOMAN: SDL_BlitSurface(map->img_bomberwoman, NULL, screen, &place); break; } } } }
void map_display(struct map* map) { assert(map != NULL); assert(map->height > 0 && map->width > 0); int x, y; for (int i = 0; i < map->width; i++) { for (int j = 0; j < map->height; j++) { x = i * SIZE_BLOC; y = j * SIZE_BLOC; unsigned char type = map->grid[CELL(i,j)]; switch (type & 15) { case CELL_SCENERY: display_scenery(map, x, y, type); break; case CELL_CASE: window_display_image(sprite_get_box(), x, y); break; case CELL_BONUS: display_bonus(map, x, y, type); break; case CELL_KEY: window_display_image(sprite_get_key(), x, y); break; case CELL_DOOR: window_display_image(sprite_get_door(), x, y); break; case CELL_CLOSED_DOOR: window_display_image(sprite_get_closed_door(), x, y); break; case CELL_GOAL: window_display_image(sprite_get_princess(), x, y); break; } } } }