void play(SDL_Surface* screen) { int x; int y; x = 10; while (g_playloop == 1) { y = 23; SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 5, 5, 5)); fontmap_printf(x, y, screen, "304-PACMAN <PAYET-S> + 1UP: 0 + " "SCORE: %03d + TIME: %d", g_score, g_time); y += FONTMAP_SIZE * 2; fontmap_print(x, y, screen, g_prompt.c_str()); y += FONTMAP_SIZE * 2; handle_event(screen, y); y += FONTMAP_SIZE * 2; for (auto line : g_map) { fontmap_print(x, y, screen, line.c_str()); y += FONTMAP_SIZE; } if (g_choose_file == 1) g_prompt = "$> Choose a map."; else if (g_count <= (g_score / 10)) g_prompt = "$> Congratulation!"; else if (g_pause == 0) { g_prompt = "$> GO!"; g_time += 1; if ((g_time % 100) == 0) { move_player(); move_ghost(); } } else if (g_pause == 1) { g_prompt = "$> Game is paused."; } SDL_Flip(screen); } }
int fontmap_printf(int x,int y, SDL_Surface* destination, const char *format, ...) { va_list list; va_start(list,format); char text[BUFSIZ]; vsprintf(text,format,list); fontmap_print(x, y, destination, text); va_end(list); return strlen(text); }
int fontmap_printf(fontmap *p_fontmap, int x,int y, SDL_Renderer *renderer, const char *format, ...) { va_list list; va_start(list,format); char text[BUFSIZ]; vsprintf(text,format,list); fontmap_print(p_fontmap, x, y, renderer, text); va_end(list); return strlen(text); }
void shape_draw(shape* p_shape, fontmap *p_fontmap, SDL_Renderer *renderer) { for (int i=0;i<p_shape->len;i++){ for (int j=0;j<p_shape->len;j++){ if(p_shape->layout[j][i] == 1){ fontmap_print(p_fontmap, p_shape->x * TILE_SIZE + i * TILE_SIZE, p_shape->y * TILE_SIZE + j * TILE_SIZE, renderer, "A"); } } } }