static void init_gmx(t_x11 *x11, char *program, int nfile, t_filenm fnm[], const output_env_t oenv) { Pixmap pm; t_gmx *gmx; XSizeHints hints; int w0, h0; int natom, natom_trx; t_topology top; int ePBC; matrix box; t_trxframe fr; t_trxstatus *status; char quote[256]; snew(gmx, 1); snew(gmx->wd, 1); ePBC = read_tpx_top(ftp2fn(efTPR, nfile, fnm), NULL, box, &natom, NULL, NULL, &top); read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr, TRX_DONT_SKIP); close_trx(status); natom_trx = fr.natoms; /* Creates a simple window */ w0 = DisplayWidth(x11->disp, x11->screen)-132; h0 = DisplayHeight(x11->disp, x11->screen)-140; bromacs(quote, 255); InitWin(gmx->wd, 0, 0, w0, h0, 3, quote); gmx->wd->self = XCreateSimpleWindow(x11->disp, x11->root, gmx->wd->x, gmx->wd->y, gmx->wd->width, gmx->wd->height, gmx->wd->bwidth, WHITE, BLACK); pm = XCreatePixmapFromBitmapData(x11->disp, x11->root, (char *)gromacs_bits, gromacs_width, gromacs_height, WHITE, BLACK, 1); hints.flags = PMinSize; hints.min_width = 2*EWIDTH+40; hints.min_height = EHEIGHT+LDHEIGHT+LEGHEIGHT+40; XSetStandardProperties(x11->disp, gmx->wd->self, gmx->wd->text, program, pm, NULL, 0, &hints); x11->RegisterCallback(x11, gmx->wd->self, x11->root, MainCallBack, gmx); x11->SetInputMask(x11, gmx->wd->self, ButtonPressMask | ButtonReleaseMask | OwnerGrabButtonMask | ExposureMask | StructureNotifyMask); /* The order of creating windows is important here! */ /* Manager */ gmx->man = init_man(x11, gmx->wd->self, 0, 0, 1, 1, WHITE, BLACK, ePBC, box, oenv); gmx->logo = init_logo(x11, gmx->wd->self, false); /* Now put all windows in the proper place */ move_gmx(x11, gmx, w0, h0, false); XMapWindow(x11->disp, gmx->wd->self); map_man(x11, gmx->man); /* Pull Down menu */ gmx->pd = init_pd(x11, gmx->wd->self, gmx->wd->width, x11->fg, x11->bg, MSIZE, gmx_pd_size, gmx_pd, MenuTitle); /* Dialogs & Filters */ gmx->filter = init_filter(&(top.atoms), ftp2fn_null(efNDX, nfile, fnm), natom_trx); init_dlgs(x11, gmx); /* Now do file operations */ set_file(x11, gmx->man, ftp2fn(efTRX, nfile, fnm), ftp2fn(efTPR, nfile, fnm)); ShowDlg(gmx->dlgs[edFilter]); }
int main() { SDL_Surface* background, *background2, *background3, *background4; SDL_Rect src, dest; int frames; Uint32 colorkey; SDL_AudioSpec desired, obtained; sound_t bus_sound; /*initialize video and sound subsystem*/ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0){ printf("Unable to initialize video: %s\n.", SDL_GetError()); return 1; } /*ensure all subsystems exit safely*/ atexit(SDL_Quit); atexit(SDL_CloseAudio); /*set video mode*/ screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_HWSURFACE); if (screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } /*load background images*/ background = SDL_LoadBMP("img/src.bmp"); if (background == NULL) { printf("Unable to load image."); return 1; } background2 = SDL_LoadBMP("img/background2.bmp"); if (background2 == NULL) { printf("Unable to load background2."); return 1; } background3 = SDL_LoadBMP("img/background3.bmp"); if (background3 == NULL) { printf("Unable to load background3."); return 1; } background4 = SDL_LoadBMP("img/background4.bmp"); if (background4 == NULL) { printf("Unable to load background4."); return 1; } /*load bus*/ bus = SDL_LoadBMP("img/bus.bmp"); if (bus == NULL) { printf("Unable to load image."); return 1; } colorkey = SDL_MapRGB(bus->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(bus, SDL_SRCCOLORKEY, colorkey); /*load man*/ man = SDL_LoadBMP("img/man.bmp"); if (man == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(man->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(man, SDL_SRCCOLORKEY, colorkey); man2 = SDL_LoadBMP("img/man2.bmp"); if (man2 == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(man2->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(man2, SDL_SRCCOLORKEY, colorkey); car1 = SDL_LoadBMP("img/car1.bmp"); if (car1 == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(car1->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(car1, SDL_SRCCOLORKEY, colorkey); car2 = SDL_LoadBMP("img/car2.bmp"); if (car2 == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(car2->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(car2, SDL_SRCCOLORKEY, colorkey); //open audio device desired.freq = 44100; desired.format = AUDIO_S16; desired.samples = 4096; desired.channels = 2; desired.callback = AudioCallback; desired.userdata = NULL; if (SDL_OpenAudio(&desired, &obtained) < 0) { printf("Unable to open audio device: %s\n", SDL_GetError()); return 1; } //load sound files and convert them to sound card's format if (LoadAndConvertSound("audio/bus-pass.wav", &obtained, &bus_sound) != 0) { printf("Unable to load sound.\n"); return 1; } ClearPlayingSounds(); SDL_PauseAudio(0); init_bus(); init_man(); int passenger_in = 0; PlaySound(&bus_sound); while (psv.x > 0) { src.x = 0; src.y = 0; src.w = background->w; src.h = background->h; dest = src; SDL_BlitSurface(background, &src, screen, &dest); draw_obj(&psv, bus); if (psv.x < screen->w/2 && !passenger_in) { /*pause bus for passenger to enter*/ SDL_PauseAudio(1); if (passenger.x > psv.x + 40){ /*check if passenger has got in*/ passenger_in = 1; SDL_PauseAudio(0); } draw_man(); SDL_Flip(screen); move_obj(&passenger); } else { SDL_Flip(screen); move_obj(&psv); } } psv.x = 639; psv.y = 320; init_cars(); PlaySound(&bus_sound); while (psv.x + bus->w/2 > 0) { SDL_BlitSurface(background2, &src, screen, &dest); draw_obj(&priv1, car1); draw_obj(&priv2, car2); draw_obj(&psv, bus); SDL_Flip(screen); move_obj(&psv); move_obj(&priv1); move_obj(&priv2); } psv.x = 639; psv.y = 350; PlaySound(&bus_sound); while (psv.x + bus->w/2 > 0) { SDL_BlitSurface(background3, &src, screen, &dest); draw_obj(&psv, bus); SDL_Flip(screen); move_obj(&psv); } psv.x = 639; psv.y = 267; passenger.y = 270; passenger_in = 1; int has_paused = 0; PlaySound(&bus_sound); while (psv.x + bus->w/2 > 0) { SDL_BlitSurface(background4, &src, screen, &dest); if (screen->w/2 > psv.x && passenger_in == 1) { SDL_PauseAudio(1); if (has_paused == 0) { SDL_Delay(1000); has_paused = 1;} if (passenger.x > 639) {passenger_in = 0; SDL_PauseAudio(0);} draw_obj(&psv, bus); draw_man(); SDL_Flip(screen); move_obj(&passenger); } else { draw_obj(&psv, bus); SDL_Flip(screen); move_obj(&psv); } } //pause and lock sound system SDL_PauseAudio(1); SDL_LockAudio(); free(bus_sound.samples); SDL_UnlockAudio(); SDL_FreeSurface(background4); SDL_FreeSurface(background3); SDL_FreeSurface(background2); SDL_FreeSurface(background); SDL_FreeSurface(man); SDL_FreeSurface(bus); return 0; }