static void go_render() { SDL_Rect rc = { 25, 100, 640-50, 480-200 }; SDL_BlitSurface( gbg, 0, front, 0); SDL_FillRect( front, &rc, 0); { static char sbuf[256]; sprintf(sbuf, "Player %d Wins with Score of %d!!", winner->player_num, winner->score ); SDL_PrintText(front, font, rc.x+25, rc.y+25, SDL_MapRGB(front->format, 255, 255, 255), sbuf); sprintf(sbuf, "Player %d Press Button 1 to Continue", winner->player_num); } { int i; for( i = 0; i < 12; i++) { if(SDL_JoystickGetButton(winner->stick, i)) { scr = ID_START; init_game(); } } } }
void mxSurfacePainter::printText(int x, int y, Color col,std::string text) { if(font == 0) throw mxException<string>(" No found font set on printtext [:" + text + ":]"); SDL_PrintText(surface->getSurface(), font, x,y, SDL_MapRGB(surface->getSurface()->format, col.color.colors[0], col.color.colors[1], col.color.colors[2]), text.c_str()); }
static void g_render() { static char sbuf[256]; // SDL_FillRect(front, &game[0].cords, SDL_MapRGB(front->format, 255, 255, 255)); // SDL_FillRect(front, &game[1].cords, SDL_MapRGB(front->format, 255, 0, 0)); SDL_BlitSurface( gbg, 0, front, 0); { SDL_Rect rc = { 20, 50, 640/2-40, 480-50 }; SDL_Rect rc2 = { 640/2+20, 50, 640/2-40, 480-50 }; SDL_FillRect(front, &rc, 0x0); SDL_FillRect(front, &rc2, 0x0); render_grid(&game[0], rc.x+5, rc.y+3); render_grid(&game[1], rc2.x+5, rc2.y+3); sprintf(sbuf, "P1 Score: %d Lines: %d", game[0].score, game[0].lines); SDL_PrintText(front, font, 25, 65, SDL_MapRGB(front->format, 255, 0, 0), sbuf); sprintf(sbuf, "P2 Score: %d Lines: %d", game[1].score, game[1].lines); SDL_PrintText(front, font, 640/2+25, 65, SDL_MapRGB(front->format, 255, 255, 255), sbuf); } game_logic(); }
int get_gb_file(char *file_name) { struct directory_browser b; SDL_Event e; int active = 1; SDL_Surface *bg = 0; if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) return -1; if(!(front = SDL_SetVideoMode(640,480,0,0))) return -1; stick = SDL_JoystickOpen(0); SDL_JoystickEventState(SDL_ENABLE); the_font = SDL_InitFont("Resources/arial.mxf"); SDL_FillRect(front, 0, 0); SDL_PrintText(front, the_font, 0,0,SDL_MapRGB(front->format, 255, 0, 0), "Loading..."); SDL_UpdateRect(front, 0,0,640,480); //bg = SDL_LoadBMP("background.bmp"); fprintf(stderr, "starting to browse\n"); b.head = ls2link("./",&b.length); b.x = 10; b.y = 10; b.w = 620; b.h = 420; b.cur_i = 0; b.max_col = 10; int file_selected = 0; int dmg = 0; // DMG mode activated while(active == 1) { char str[255]; SDL_FillRect(front, 0,0); SDL_BlitSurface(bg, 0, front, 0); draw_browser(front, &b, the_font); sprintf(str, "Index: %d Total: %d", b.cur_i+1, b.length); SDL_PrintText(front, the_font, 420,10, SDL_MapRGB(front->format, 255, 255, 255), str); if(SDL_PollEvent(&e)) { dmg = (e.type == 1); switch(e.type) { case SDL_QUIT: active = 0; break; case SDL_JOYBUTTONDOWN: { switch(e.jbutton.button) { case 8: // move up if(b.cur_i > 0) b.cur_i--; break; case 6:// move down if(b.cur_i+1 < b.length) b.cur_i++; break; case 7:// move left if(b.cur_i+1-b.max_col > 0) b.cur_i -= b.max_col; break; case 9://move right if(b.cur_i+b.max_col < b.length) b.cur_i += b.max_col; break; case 10: active = 0; break; case 0: case 1: case 2: case 3: { struct file_node *pnode = skip_nodes(b.head->next, b.cur_i); if(pnode != 0 && pnode->is_dir == 1) { char buf[1000]; sprintf(buf,"./%s/", pnode->name); struct file_node *new_nodes = ls2link(buf, &b.length); free_nodes(b.head); b.cur_i = 0; b.head = new_nodes; } else if(pnode != 0 && pnode->is_dir == 0) { // its a file strncpy(file_name, pnode->name, 0xFF); file_selected = 1; active = 0; } } break; } } break; } } SDL_UpdateRect(front, 0,0,640,480); } free_nodes(b.head); SDL_FreeSurface(bg); SDL_FreeFont(the_font); SDL_FreeSurface(front); SDL_JoystickClose(stick); SDL_Quit(); return dmg; }