void display() { #ifdef MOD_TEST test_display(); #else benc_display(); robk_display(); vinh_display(); game_display(); #endif }
int main(int argc, char *argv[]) { struct game* game = game_new(); window_create(SIZE_BLOC * MAP_WIDTH, SIZE_BLOC * MAP_HEIGHT + BANNER_HEIGHT + LINE_HEIGHT); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // to obtain the DEFAULT_GAME_FPS, we have to reach a loop duration of (1000 / DEFAULT_GAME_FPS) ms int ideal_speed = 1000 / DEFAULT_GAME_FPS; int timer, execution_speed; // game loop // fixed time rate implementation int done = menu_display(game); while (!done) { timer = SDL_GetTicks(); done = game_update(game); game_display(game); if ( player_get_dead(game_get_player(game))) { // Reset the game if the player is dead game_free(game); game=game_new(); } if(game_get_win(game) == 1) done=1; execution_speed = SDL_GetTicks() - timer; if (execution_speed < ideal_speed) SDL_Delay(ideal_speed - execution_speed); // we are ahead of ideal time. let's wait. } window_free(); game_free(game); SDL_Quit(); return EXIT_SUCCESS; }
void multi_display(struct game* game) { assert(game); struct map* map = NULL; int w, h; int* scores; switch(game_get_state(game)) { case PLAYING: case PAUSED: game_display(game); if(player_get_nb_player_alive(game) == 1) multi_change_state(game, SCORE); break; case CHOOSE_MAP: map = level_get_curr_map(game_get_curr_level(game)); w = 10 + 15 + sprite_get_max_width() + 50 + SIZE_BLOC * map_get_width(map); h = max(30 * (sprite_get_nb_map_multi() + 1), SIZE_BLOC * map_get_height(map)); window_resize( w, h); window_clear(); for(int i = 0; i < sprite_get_nb_map_multi(); i++) { window_display_image( sprite_get_map_multi(i), 10 + 15, 15 + 30 * i); } window_display_image(sprite_get_menu(M_S_SELECT_BLACK), 10, 15 + 30 * game_get_pos(game)); map_display( map, 10 + 15 + sprite_get_max_width() + 50, (h-(SIZE_BLOC * map_get_height(map))) / 2); window_refresh(); break; case SCORE: window_clear(); level_display(game_get_curr_level(game)); bomb_display(game, level_get_curr_map(game_get_curr_level(game))); for(int i = 0; i < game_get_nb_player(game); i++) player_display(game_get_player(game, i+1)); int map_w = map_get_width(level_get_curr_map(game_get_curr_level(game))); int map_h = map_get_height(level_get_curr_map(game_get_curr_level(game))); int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2; int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2; window_display_image( sprite_get_menu(M_BG_GREY), mid_w - 240, mid_h - 262); window_display_image( sprite_get_score(player_get_id_player_alive(game)), mid_w - 200, mid_h - 222); scores = game_get_scores(game); for(int i = 0; i < game_get_nb_player(game); i++) { window_display_sprite( sprite_get_players(i+1), sprite_get_rect_player_anim(0, i+1, SOUTH), mid_w - 200, mid_h - 222 + 80 + 80 * i); window_display_image( sprite_get_number_white(scores[i]), mid_w - 140, mid_h - 222 + 100 + 80 * i); } window_refresh(); break; } }