void tileset_set_image(tileset_t* tileset, int tile_index, image_t* image) { // CAUTION: the new tile image is assumed to be the same same size as the tile it // replaces. if it's not, the engine won't crash, but it may cause graphical // glitches. rect_t xy; xy = atlas_xy(tileset->atlas, tile_index); blit_image(image, tileset->texture, xy.x1, xy.y1); }
int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_EVERYTHING); for (int i = 0 ; i < 256 ; i++) { colors[i].r = i; colors[i].g = i; colors[i].b = i; } screen = SDL_SetVideoMode(1400, 600, 32, SDL_SWSURFACE); SDL_WM_SetCaption("Image test", NULL); GreyCamera left_cam("/dev/video0", HEIGHT, WIDTH); left_cam.start(); JpegCamera right_cam("/dev/video1", HEIGHT, WIDTH); right_cam.start(); SDL_Event event; CameraImage left_img, right_img; for (;;) { SDL_PollEvent(&event); if (event.type == SDL_QUIT) { break; } if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) { break; } left_cam.capture(&left_img); right_cam.capture(&right_img); blit_image(&left_img, 0, 0); blit_image(&right_img, 650, 0); //save_image(&left_img); } left_cam.stop(); right_cam.stop(); SDL_Quit(); return 0; }
int main(int argc, char *argv[]) { int width=0; int height=0; pixel_format pf=PF_ERROR; char *filename=NULL; u8 *image_data=NULL; FILE *image_file=NULL; int i=0, c=0, image_bytes=0; SDL_Event e; int quit=0; if(parse_args(argc, argv, &width, &height, &pf, &filename)) { display_help(); goto end; } image_bytes=width*height*get_pixel_format_bits(pf)/8; image_data=(u8 *)malloc(image_bytes); image_file=fopen(filename, "rb"); if(!image_file) { printf("File %s does not exist\n", filename); goto end; } for(i=0;(c=fgetc(image_file))!=EOF&&i<image_bytes;i++) image_data[i]=(u8)c; fclose(image_file); init_graphics(width, height); blit_image(width, height, pf, image_data); while(!quit) { SDL_Delay(1.0/15.0f); while(SDL_PollEvent(&e)) { if(e.type==SDL_QUIT) quit=1; } } destroy_graphics(width, height); end: if(image_data) free(image_data); if(filename) free(filename); return 0; }
void Display::blit_map(Map& w, int tw, int th){ SDL_Rect p; int i=0; int j=0; int k; int m; k=0; m=0; for(i=mcam.getX()-25; i<mcam.getX()+25;i++){ k++; for(j=mcam.getY()-24; j<mcam.getY()+25;j++){ p.x =(k-1)*tw; if (m<48){ m++; }else{ m=0; } p.y =(m-1)*th; if (w.carte[j][i].getT()==1){ blit_image("watter.bmp", p, 0); } if(w.carte[j][i].getT()==2){ blit_image("sand.bmp",p,0); } if (w.carte[j][i].getT()==3){ blit_image("grass.bmp", p, 0); } if (w.carte[j][i].getT()==4){ blit_image("mountain.bmp", p, 0); } if (w.carte[j][i].getT()==5){ blit_image("rock.bmp", p, 0); } if (w.carte[j][i].getT()==6){ blit_image("tree.bmp", p, 0); } if (w.carte[j][i].getT()==0){ blit_image("error.bmp", p, 0); } } } }
void gui_display (int shortcut){ void* stor = display ? malloc(display->h * display->pitch) : 0; if (stor) memcpy(stor, display->pixels, display->h * display->pitch); if (tmpSDLScreen == NULL) { tmpSDLScreen = SDL_DisplayFormat(display); if (tmpSDLScreen == NULL) { write_log ("SDLUI: Failed to create temp screen\n"); abort(); } else { write_log ("SDLUI: Created temp screen %dx%dx%d\n", display->w, display->h, display->format->BitsPerPixel); } } SDL_Event event; int menu_exitcode = -1; int mainloopdone = 0; int mouse_x = 30; int mouse_y = 40; int kup = 0; int kdown = 0; int kleft = 0; int kright = 0; int ksel = 0; int iconpos_x = 0; int iconpos_y = 0; if (getcwd (launchDir, 256)) { strcpy (yol, launchDir); write_log ("SDLUI: current dir: %s\n", launchDir); } else { write_log("getcwd failed with errno %d\n", errno); return; } /* set a proper keyboard delay so we can move through lists without having hammer the keyboard... */ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); int need_redraw = 1; while (!mainloopdone) { while (SDL_PollEvent(&event)) { need_redraw = 1; switch(event.type) { case SDL_QUIT: mainloopdone = 1; break; case SDL_JOYBUTTONDOWN: switch (event.jbutton.button) { case PLATFORM_BUTTON_R: break; case PLATFORM_BUTTON_L: break; case PLATFORM_BUTTON_UP: kup = 1; break; case PLATFORM_BUTTON_DOWN: kdown = 1; break; case PLATFORM_BUTTON_LEFT: kleft = 1; break; case PLATFORM_BUTTON_RIGHT: kright = 1; break; case PLATFORM_BUTTON_CLICK: ksel = 1; break; case PLATFORM_BUTTON_B: ksel = 1; break; case PLATFORM_BUTTON_Y: break; case PLATFORM_BUTTON_START: mainloopdone = 1; break; } break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_RETURN: if((event.key.keysym.mod & KMOD_LALT) || (event.key.keysym.mod & KMOD_RALT)) { toggle_fullscreen(0); //SDL_Delay(100); break; } else { // enter to select ksel = 1; break; } case SDLK_ESCAPE: mainloopdone = 1; break; case SDLK_UP: kup = 1; break; case SDLK_DOWN: kdown = 1; break; case SDLK_LEFT: kleft = 1; break; case SDLK_RIGHT: kright = 1; break; // space to run default case SDLK_SPACE: selected_item = menu_sel_run; ksel =1; break; default: break; } break; case SDL_MOUSEMOTION: mouse_x += event.motion.xrel; mouse_y += event.motion.yrel; break; case SDL_MOUSEBUTTONDOWN: if (selected_item == 0) { if (mouse_x >= 0 && mouse_x <= 20) { if (mouse_y >= 0 && mouse_y <= 20) { mainloopdone = 1; } } } else { ksel = 1; break; } break; case SDL_ACTIVEEVENT: case SDL_KEYUP: break; default: dprintf(2, "got event %lu\n", (long) event.type); need_redraw = 0; } } if(!need_redraw) { SDL_Delay(20); continue; } if (ksel == 1) { if (selected_item == menu_sel_expansion) { sprintf (msg, "%s", "Select KickStart ROM"); sprintf (msg_status, "%s", "EXIT: Back/ESC"); sprintf (yol, "%s/roms", launchDir); dirz(1); } if (selected_item == menu_sel_floppy) { sprintf (msg, "%s", "Select Disk Image"); sprintf (msg_status, "%s", "DF0: B DF1: A"); sprintf (yol, "%s/disks", launchDir); dirz(0); } if (selected_item == menu_sel_prefs) { sprintf (msg, "%s", "Emulation Configuration"); sprintf (msg_status, "%s", "EXIT: Back/ESC"); prefz(0); } if (selected_item == menu_sel_reset) { uae_reset(0, 1); menu_exitcode = 2; mainloopdone = 1; } if (selected_item == menu_sel_keymaps) { } /* if (selected_item == menu_sel_tweaks) { sprintf(msg,"%s","Tweaks"); sprintf(msg_status,"%s","L/R = -/+ B: Apply"); tweakz(0); }*/ if (selected_item == menu_sel_storage) { strcpy(msg, "Savestates"); strcpy(msg_status, "LOAD: A SAVE: B"); sprintf (yol, "%s/saves", launchDir); dirz(2); } if (selected_item == menu_sel_run) { menu_exitcode = 1; mainloopdone = 1; } if (selected_item == menu_sel_exit) { SDL_Quit(); exit(0); } ksel = 0; } // background SDL_BlitSurface (pMenu_Surface, NULL, tmpSDLScreen, NULL); // icons iconpos_x = 10; iconpos_y = 33; selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_floppy, menu_sel_floppy); blit_image (icon_floppy, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_preferences, menu_sel_prefs); blit_image (icon_preferences, iconpos_x, iconpos_y); // iconpos_x += iconsizex + bosluk; // selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_tweaks, menu_sel_tweaks); // blit_image (icon_tweaks, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_keymaps, menu_sel_keymaps); blit_image (icon_keymaps, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; selected_hilite (iconpos_x, iconpos_y, mouse_x, mouse_y, icon_expansion, menu_sel_expansion); blit_image (icon_expansion, iconpos_x, iconpos_y); iconpos_x = 10; iconpos_y = iconpos_y + iconsizey + bosluk; selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y,icon_storage, menu_sel_storage); blit_image (icon_storage, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_reset, menu_sel_reset); blit_image (icon_reset, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_run, menu_sel_run); blit_image (icon_run, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; selected_hilite (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_exit, menu_sel_exit); blit_image (icon_exit, iconpos_x, iconpos_y); // texts write_text (TITLE_X, TITLE_Y, "PUAE //GnoStiC"); // mouse pointer ------------------------------ if (kleft == 1) { mouse_x -= (iconsizex + bosluk); kleft = 0; } if (kright == 1) { mouse_x += (iconsizex + bosluk); kright = 0; } if (kup == 1) { mouse_y -= (iconsizey + bosluk); kup = 0; } if (kdown == 1) { kdown = 0; mouse_y += (iconsizey + bosluk); } #define _MENU_X 640 #define _MENU_Y 480 if (mouse_x < 1) { mouse_x = 1; } if (mouse_y < 1) { mouse_y = 1; } /* pMainMenu_Surface->w */ #define MOUSE_MAX_X (_MENU_X - pMouse_Pointer->w) #define MOUSE_MAX_Y (_MENU_Y - pMouse_Pointer->h) if (mouse_x > MOUSE_MAX_X) { mouse_x = MOUSE_MAX_X; } if (mouse_y > MOUSE_MAX_Y) { mouse_y = MOUSE_MAX_Y; } rect.x = mouse_x; rect.y = mouse_y; //rect.w = pMouse_Pointer->w; //rect.h = pMouse_Pointer->h; SDL_BlitSurface (pMouse_Pointer, NULL, tmpSDLScreen, &rect); // mouse pointer-end SDL_BlitSurface (tmpSDLScreen, NULL, display, NULL); #ifdef USE_GL flush_gl_buffer (&glbuffer, 0, display->h - 1); render_gl_buffer (&glbuffer, 0, display->h - 1); glFlush (); SDL_GL_SwapBuffers (); #else SDL_Flip (display); #endif need_redraw = 0; SDL_Delay(20); } //while done if (stor) { memcpy(display->pixels, stor, display->h * display->pitch); free(stor); SDL_Flip(display); } SDL_EnableKeyRepeat(0, 0); /* disable keyrepeat again */ // return menu_exitcode; }
void chargement_jeu(SEcran **ptr_e, SEntite **entites) { int cont = 1, choix = 1; SEcran *ecran_ch = new_ecran(NB_COLONNES, NB_LIGNES); SImage *v1, *v2, *s1, *s2, *d1, *d2, *d3; v1 = new_image(3, 3, "=\\`oX>=/`"); // Vaisseau 1 s1 = new_image(3, 3, "21 32221 "); v2 = new_image(3, 3, "#=-#> #=-"); // Vaisseau 2 s2 = new_image(3, 3, "44455 444"); d3 = new_image(8, 5, " ____ / \\ | o O | \\ '' / |||| "); d2 = new_image(8, 5, "\\X\\ /X/ \\X\\/X/ >XX< /X/\\X\\ /X/ \\X\\"); d1 = new_image(8, 5, " || || || || || "); etat_jeu.largeur_ecran = NB_COLONNES; etat_jeu.hauteur_ecran = NB_LIGNES; // Initialisation de l'écran // Un pointeur sur pointeur a du être utilisé puisqu'on modifie ici la valeur d'un pointeur sur SEcran. *ptr_e = new_ecran(etat_jeu.largeur_ecran, etat_jeu.hauteur_ecran); // Initialisation des variables globales etat_jeu.fin=0; etat_jeu.score=0; etat_jeu.etape=0; etat_jeu.nb_entites=0;//DEBUG etat_jeu.combo=0; etat_jeu.dec_combo=0; etat_jeu.coef_vitesse=1.0; etat_jeu.coef_vie=1.0; etat_jeu.stat_nb_tir = 0; // Choix du vaisseau while(cont) { // Affichage du titre clr_ecran(ecran_ch); mv_curseur(ecran_ch, 0, 0); afficher_contour(ecran_ch); mv_curseur(ecran_ch, etat_jeu.largeur_ecran/6, 1); afficher_str(ecran_ch, "Choisissez votre vaisseau, guerrier intergalactique !"); // Affichage des vaisseaux mv_curseur(ecran_ch, NB_COLONNES/4, 6); blit_image(ecran_ch, v1); mv_curseur(ecran_ch, NB_COLONNES*3/4-5, 6); blit_image(ecran_ch, v2); // Affichage du curseur if(choix == 1) mv_curseur(ecran_ch, NB_COLONNES*1/4+1, 10); else mv_curseur(ecran_ch, NB_COLONNES*3/4-4, 10); afficher_char(ecran_ch, 'X'); // Affichage des infos mv_curseur(ecran_ch, NB_COLONNES/4-5, 12); afficher_str(ecran_ch, "Vaisseau : resistant"); mv_curseur(ecran_ch, NB_COLONNES/4-5, 13); afficher_str(ecran_ch, "Arme : missiles"); mv_curseur(ecran_ch, NB_COLONNES*3/4-10, 12); afficher_str(ecran_ch, "Vaisseau : vulnerable"); mv_curseur(ecran_ch, NB_COLONNES*3/4-10, 13); afficher_str(ecran_ch, "Arme : lasers"); mv_curseur(ecran_ch, NB_COLONNES*3/4-15, 14); afficher_str(ecran_ch, "(puissante mais detruit les bonus)"); actualiser_ecran(ecran_ch); // Gestion du clavier pour choisir entre deux choix : cont = gestion_clavier_menuchoix(&choix, 2); delais_ms(10); } // Initialisation du joueur etat_jeu.ijoueur = new_entite(entites, 3, 3); entites[etat_jeu.ijoueur]->vie = 5 * etat_jeu.coef_vie; entites[etat_jeu.ijoueur]->x = 4; entites[etat_jeu.ijoueur]->y = 8; entites[etat_jeu.ijoueur]->mort = mort_joueur; entites[etat_jeu.ijoueur]->niv_arme = 1; if(choix == 1) { entites[etat_jeu.ijoueur]->type_arme = ARME_MISSILE; entites[etat_jeu.ijoueur]->img = v1; entites[etat_jeu.ijoueur]->shape = s1; del_image(v2); del_image(s2); } else { entites[etat_jeu.ijoueur]->type_arme = ARME_LASER; entites[etat_jeu.ijoueur]->img = v2; entites[etat_jeu.ijoueur]->shape = s2; del_image(v1); del_image(s1); } // Chargement des murs chargement_murs(); // Initialisation nombre aléatoires srand(time(NULL)); // Choix de la difficulte cont = choix = 1; while(cont) { // Affichage du titre clr_ecran(ecran_ch); mv_curseur(ecran_ch, 0, 0); afficher_contour(ecran_ch); mv_curseur(ecran_ch, etat_jeu.largeur_ecran/6, 1); afficher_str(ecran_ch, "Quelle sera la difficulte de votre mission ?"); // Affichage des difficultes mv_curseur(ecran_ch, NB_COLONNES/4-4, 6); blit_image(ecran_ch, d1); mv_curseur(ecran_ch, NB_COLONNES*2/4-4, 6); blit_image(ecran_ch, d2); mv_curseur(ecran_ch, NB_COLONNES*3/4-4, 6); blit_image(ecran_ch, d3); // Affichage du curseur mv_curseur(ecran_ch, NB_COLONNES*choix/4, 12); afficher_char(ecran_ch, 'X'); // Affichage des informations mv_curseur(ecran_ch, NB_COLONNES/4-3, 14); afficher_str(ecran_ch, "Newbie "); mv_curseur(ecran_ch, NB_COLONNES*2/4-8, 14); afficher_str(ecran_ch, "Hardcore G4m3rZ"); mv_curseur(ecran_ch, NB_COLONNES*3/4-4, 14); afficher_str(ecran_ch, "God-like"); actualiser_ecran(ecran_ch); // Gestion du clavier pour choisir entre deux choix : cont = gestion_clavier_menuchoix(&choix, 3); delais_ms(10); } // Réglages de difficulté etat_jeu.difficulte = choix; if(etat_jeu.difficulte>=2) { etat_jeu.coef_vitesse=1.2; } if(etat_jeu.difficulte==3) { etat_jeu.coef_vie=2; } }
int gui_display(int shortcut){ SDL_Event event; int menu_exitcode = -1; int mainloopdone = 0; int mouse_x = 30; int mouse_y = 40; int kup = 0; int kdown = 0; int kleft = 0; int kright = 0; int ksel = 0; int iconpos_x = 0; int iconpos_y = 0; getcwd(launchDir,256); while (!mainloopdone) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { mainloopdone = 1; } if (event.type == SDL_JOYBUTTONDOWN) { switch (event.jbutton.button) { case GP2X_BUTTON_R: break; case GP2X_BUTTON_L: break; case GP2X_BUTTON_UP: kup = 1; break; case GP2X_BUTTON_DOWN: kdown = 1; break; case GP2X_BUTTON_LEFT: kleft = 1; break; case GP2X_BUTTON_RIGHT: kright = 1; break; case GP2X_BUTTON_CLICK: ksel = 1; break; case GP2X_BUTTON_B: ksel = 1; break; case GP2X_BUTTON_Y: break; case GP2X_BUTTON_START: mainloopdone = 1; break; } } if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_ESCAPE: mainloopdone = 1; break; case SDLK_UP: kup = 1; break; case SDLK_DOWN: kdown = 1; break; case SDLK_LEFT: kleft = 1; break; case SDLK_RIGHT: kright = 1; break; case SDLK_b: ksel = 1; break; default: break; } } if (event.type == SDL_MOUSEMOTION) { mouse_x += event.motion.xrel; mouse_y += event.motion.yrel; } if (event.type == SDL_MOUSEBUTTONDOWN) { if (seciliolan == 0) { if (mouse_x >= 0 && mouse_x <= 20) { if (mouse_y >= 0 && mouse_y <= 20) { mainloopdone = 1; } } } else { ksel = 1; break; } } } if (ksel == 1) { if (seciliolan == menu_sel_expansion) { sprintf(msg,"%s","Select KickStart ROM"); sprintf(msg_status,"%s"," "); sprintf(yol,"%s/roms",launchDir); dirz(1); } if (seciliolan == menu_sel_floppy) { sprintf(msg,"%s","Select Disk Image"); sprintf(msg_status,"%s","DF0: B DF1: A"); sprintf(yol,"%s/disks",launchDir); dirz(0); } if (seciliolan == menu_sel_prefs) { sprintf(msg,"%s"," "); sprintf(msg_status,"%s"," "); prefz(0); } if (seciliolan == menu_sel_reset) { //reset amiga menu_exitcode = 2; mainloopdone = 1; } if (seciliolan == menu_sel_keymaps) { } if (seciliolan == menu_sel_tweaks) { sprintf(msg,"%s","Tweaks"); sprintf(msg_status,"%s","L/R = -/+ B: Apply"); tweakz(0); } if (seciliolan == menu_sel_storage) { } if (seciliolan == menu_sel_run) { menu_exitcode = 1; mainloopdone = 1; } if (seciliolan == menu_sel_exit) { SDL_Quit(); #ifdef GP2X //remove mmuhack module system("/sbin/rmmod mmuhack"); //menu chdir("/usr/gp2x"); execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL); #endif exit(0); } ksel = 0; } // background SDL_BlitSurface (pMenu_Surface,NULL,tmpSDLScreen,NULL); // icons iconpos_x = 10; iconpos_y = 23; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y,icon_floppy, menu_sel_floppy); blit_image (icon_floppy, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_preferences, menu_sel_prefs); blit_image (icon_preferences, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_tweaks, menu_sel_tweaks); blit_image (icon_tweaks, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_keymaps, menu_sel_keymaps); blit_image (icon_keymaps, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_expansion, menu_sel_expansion); blit_image (icon_expansion, iconpos_x, iconpos_y); iconpos_x = 10; iconpos_y = 93; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y,icon_storage, menu_sel_storage); blit_image (icon_storage, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_reset, menu_sel_reset); blit_image (icon_reset, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_run, menu_sel_run); blit_image (icon_run, iconpos_x, iconpos_y); iconpos_x += iconsizex + bosluk; secilimi (iconpos_x,iconpos_y,mouse_x,mouse_y, icon_exit, menu_sel_exit); blit_image (icon_exit, iconpos_x, iconpos_y); // texts write_text (26,3,"UAE2x 0.1 alpha //GnoStiC"); // mouse pointer ------------------------------ if (kleft == 1) { mouse_x -= (iconsizex + bosluk); kleft = 0; } if (kright == 1) { mouse_x += (iconsizex + bosluk); kright = 0; } if (kup == 1) { mouse_y -= (iconsizey + bosluk); kup = 0; } if (kdown == 1) { kdown = 0; mouse_y += (iconsizey + bosluk); } if (mouse_x < 1) { mouse_x = 1; } if (mouse_y < 1) { mouse_y = 1; } if (mouse_x > 320) { mouse_x = 320; } if (mouse_y > 240) { mouse_y = 240; } rect.x = mouse_x; rect.y = mouse_y; //rect.w = pMouse_Pointer->w; //rect.h = pMouse_Pointer->h; SDL_BlitSurface (pMouse_Pointer,NULL,tmpSDLScreen,&rect); // mouse pointer-end SDL_BlitSurface (tmpSDLScreen,NULL,display,NULL); SDL_Flip(display); } //while done return menu_exitcode; }