void CGame::draw(SDL_Surface *sfc,SDL_Rect vp) { if (focusing_objects.Length()>0) { SDL_Rect vp2; int dx; List<CObject> l; CObject *o; List<float> l2; List<int> l3; float *fy; int *cp_delay; dx=vp.w/focusing_objects.Length(); vp2.x=vp.x+(focusing_objects.Length()-1)*dx; vp2.y=vp.y; if (focusing_objects.Length()>1) vp2.w=dx-1; else vp2.w=dx; vp2.h=vp.h; l.Instance(focusing_objects); l2.Instance(focusing_fy); l3.Instance(checkpoint_delay); l.Rewind(); l2.Rewind(); l3.Rewind(); while(l.Iterate(o) && l2.Iterate(fy) && l3.Iterate(cp_delay)) { /* draw a viewport: */ draw(sfc,vp2,(CCarObject *)o,fy,cp_delay); vp2.x-=dx; } /* while */ } /* if */ { float f=float(game_timmer)/float(fade_time); if (f<0) f=0; if (f>=1.0) f=1.0; if (f<1.0) surface_fader(sfc,f,f,f,&vp); } if (paused) { surface_fader(sfc,0.5F,0.5F,0.5F,&vp); extra_tiles[9]->draw(vp.x+vp.w/2-extra_tiles[9]->get_dx()/2,vp.y+vp.h/2-64,sfc); } /* if */ } /* CGame::draw */
bool state_gameover_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { font_print_centered(sx/2,(sy/2)-24,"GAME OVER",screen); font_print_centered(sx/2,(sy/2)-16,"PRESS R TO VIEW THE REPLAYS",screen); if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE==32) { if (keyboard[SDLK_BACKSPACE] && !old_keyboard[SDLK_BACKSPACE]) { SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY]) { SUBSTATE2=1; SUBSTATE++; } /* if */ } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { if (SUBSTATE2==1) { STATE=1; SUBSTATE=0; } /* if */ if (SUBSTATE2==0) { STATE=7; SUBSTATE=0; } /* if */ } /* if */ } /* if */ return true; } /* state_gameover_cycle */
bool ChooseAnImageFTP(int sx,int sy, char *ftp_dir, int slot, char **filename, bool *isdir, int *index_file) { /* Parameters: sx, sy - window size, ftp_dir - what FTP directory to use, slot - in what slot should an image go (common: #6 for 5.25' 140Kb floppy disks, and #7 for hard-disks). slot #5 - for 800Kb floppy disks, but we do not use them in Apple][? (They are as a rule with .2mg extension) index_file - from which file we should start cursor (should be static and 0 when changing dir) Out: filename - chosen file name (or dir name) isdir - if chosen name is a directory */ double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); SDL_Surface *my_screen; // for background struct ftpparse FTP_PARSE; // for parsing ftp directories #ifndef _WIN32 struct stat info; #endif if(font_sfc == NULL) if(!fonts_initialization()) return false; //if we don't have a fonts, we just can do none char tmpstr[512]; char ftpdirpath [MAX_PATH]; snprintf(ftpdirpath, MAX_PATH, "%s/%s%s", g_sFTPLocalDir, g_sFTPDirListing, md5str(ftp_dir)); // get path for FTP dir listing // printf("Dir: %s, MD5(dir)=%s\n",ftp_dir,ftpdirpath); List<char> files; // our files List<char> sizes; // and their sizes (or 'dir' for directories) int act_file; // current file int first_file; // from which we output files char ch = 0; // prepare screen SDL_Surface *tempSurface; if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background // ch = 0; #define NORMAL_LENGTH 60 if(strlen(ftp_dir) > NORMAL_LENGTH) { ch = ftp_dir[NORMAL_LENGTH]; ftp_dir[NORMAL_LENGTH] = 0;} //cut-off too long string font_print_centered(sx/2 ,5 * facy , ftp_dir, screen, 1.5 * facx, 1.3 * facy); if(ch) ftp_dir[NORMAL_LENGTH] = ch; //restore cut-off char font_print_centered(sx/2,20 * facy,"Connecting to FTP server... Please wait.", screen, 1 * facx, 1 * facy); SDL_Flip(screen); // show the screen bool OKI; #ifndef _WIN32 if(stat(ftpdirpath,&info) == 0 && info.st_mtime > time(NULL) - RENEW_TIME) { OKI = false; // use this file } else { OKI = ftp_get(ftp_dir,ftpdirpath); // get ftp dir listing } #else // in WIN32 let's use constant caching? -- need to be redone using file.mtime if(GetFileAttributes(ftpdirpath) != DWORD(-1)) OKI = false; else OKI = ftp_get(ftp_dir,ftpdirpath); // get ftp dir listing #endif if(OKI) { // error printf("Failed getting FTP directory %s to %s\n",ftp_dir,ftpdirpath); font_print_centered(sx/2,30 * facy, "Failure. Press any key!",screen, 1.4 * facx, 1.1 * facy); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(100); SDL_PollEvent(&event); } SDL_FreeSurface(my_screen); return false; } FILE *fdir = fopen(ftpdirpath,"r"); char *tmp; int i,j, B, N; // for cycles, beginning and end of list // build prev dir if(strcmp(ftp_dir, "ftp://")) { tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs while (tmp = fgets(tmpstr,512,fdir)) // first looking for directories { // clear and then try to fill in FTP_PARSE struct memset(&FTP_PARSE,0,sizeof(FTP_PARSE)); ftpparse(&FTP_PARSE, tmp, strlen(tmp)); int what = getstatFTP(&FTP_PARSE, NULL); if (strlen(FTP_PARSE.name) > 0 && what == 1) // is directory! { tmp = new char[strlen(FTP_PARSE.name)+1]; // add entity to list strcpy(tmp, FTP_PARSE.name); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } /* if */ } // sort directories. Please, don't laugh at my bubble sorting - it the simplest thing I've ever seen --bb if(files.Length() > 2) { N = files.Length() - 1; // B = 1; - defined above for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } B = files.Length(); // start for files (void) rewind (fdir); // to the start // now get all regular files while (tmp = fgets(tmpstr,512,fdir)) { int fsize; // clear and then try to fill in FTP_PARSE struct memset(&FTP_PARSE,0,sizeof(FTP_PARSE)); ftpparse(&FTP_PARSE, tmp, strlen(tmp)); if ((getstatFTP(&FTP_PARSE, &fsize) == 2)) // is normal file! { tmp = new char[strlen(FTP_PARSE.name)+1]; // add this entity to list strcpy(tmp, FTP_PARSE.name); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", fsize); sizes.Add(tmp); // add this size to list } /* if */ } (void) fclose (fdir); // do sorting for files if(files.Length() > 2 && B < files.Length()) { N = files.Length() - 1; // B = 1; for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } // Count out cursor position and file number output act_file = *index_file; if(act_file >= files.Length()) act_file = 0; // cannot be more than files in list first_file = act_file - (FILES_IN_SCREEN / 2); if (first_file < 0) first_file = 0; // cannot be negativ... // Show all directories (first) and files then // char *tmp; char *siz; // int i; while(true) { SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background font_print_centered(sx/2 ,5 * facy , ftp_dir, screen, 1.5 * facx, 1.3 * facy); if (slot == 6) font_print_centered(sx/2,20 * facy,"Choose image for floppy 140KB drive", screen, 1 * facx, 1 * facy); else if (slot == 7) font_print_centered(sx/2,20 * facy,"Choose image for Hard Disk", screen, 1 * facx, 1 * facy); else if (slot == 5) font_print_centered(sx/2,20 * facy,"Choose image for floppy 800KB drive", screen, 1 * facx, 1 * facy); else if (slot == 1) font_print_centered(sx/2,20 * facy,"Select file name for saving snapshot", screen, 1 * facx, 1 * facy); else if (slot == 0) font_print_centered(sx/2,20 * facy,"Select snapshot file name for loading", screen, 1 * facx, 1 * facy); font_print_centered(sx/2,30 * facy, "Press ENTER to choose, or ESC to cancel",screen, 1.4 * facx, 1.1 * facy); files.Rewind(); // from start sizes.Rewind(); i = 0; // printf("We've printed some messages, go to file list!\n"); // show all fetched dirs and files // topX of first fiel visible int TOPX = 45 * facy; while(files.Iterate(tmp)) { sizes.Iterate(siz); // also fetch size string if (i >= first_file && i < first_file + FILES_IN_SCREEN) { // FILES_IN_SCREEN items on screen // char tmp2[80],tmp3[256]; if (i == act_file) { // show item under cursor (in inverse mode) SDL_Rect r; r.x= 2; r.y= TOPX + (i-first_file) * 15 * facy - 1; if(strlen(tmp) > 46) r.w = 46 * 6 * 1.7 * facx + 2; else r.w= strlen(tmp) * 6 * 1.7 * facx + 2; // 6- FONT_SIZE_X r.h= 9 * 1.5 * facy; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format,255,0,0));// in RED } /* if */ // print file name with enlarged font ch = 0; if(strlen(tmp) > 46) { ch = tmp[46]; tmp[46] = 0;} //cut-off too long string font_print(4, TOPX + (i - first_file) * 15 * facy, tmp, screen, 1.7 * facx, 1.5 * facy); // show name font_print(sx - 70*facx, TOPX + (i - first_file) * 15 * facy, siz, screen, 1.7 * facx, 1.5 * facy);// show info (dir or size) if(ch) tmp[46] = ch; //restore cut-off char } /* if */ i++; // next item } /* while */ ///////////////////////////////////////////////////////////////////////////////////////////// // draw rectangles rectangle(screen, 0, TOPX - 5, g_ScreenWidth, 320 * facy, SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 480 * facx, TOPX - 5, 0, 320 * facy, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(10); SDL_PollEvent(&event); } // control cursor keyboard = SDL_GetKeyState(NULL); // get current state of pressed (and not pressed) keys if (keyboard[SDLK_UP] || keyboard[SDLK_LEFT]) { if (act_file>0) act_file--; // up one position if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_DOWN] || keyboard[SDLK_RIGHT]) { if (act_file < (files.Length() - 1)) act_file++; if (act_file >= (first_file + FILES_IN_SCREEN)) first_file=act_file - FILES_IN_SCREEN + 1; } /* if */ if (keyboard[SDLK_PAGEUP]) { act_file-=FILES_IN_SCREEN; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN]) { act_file+=FILES_IN_SCREEN; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+FILES_IN_SCREEN)) first_file=act_file-FILES_IN_SCREEN + 1; } /* if */ // choose an item? if (keyboard[SDLK_RETURN]) { // dup string from selected file name *filename = strdup(php_trim(files[act_file],strlen(files[act_file]))); // printf("files[act_file]=%s, *filename=%s\n\n", files[act_file], *filename); if(!strcmp(sizes[act_file], "<DIR>") || !strcmp(sizes[act_file], "<UP>")) *isdir = true; else *isdir = false; // this is directory (catalog in Apple][ terminology) *index_file = act_file; // remember current index files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return true; } /* if */ if (keyboard[SDLK_ESCAPE]) { files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return false; // ESC has been pressed } /* if */ if (keyboard[SDLK_HOME]) { // HOME? act_file=0; first_file=0; } /* if */ if (keyboard[SDLK_END]) { // END? act_file=files.Length() - 1; // go to the last possible file in list first_file=act_file - FILES_IN_SCREEN + 1; if(first_file < 0) first_file = 0; } /* if */ } } /* ChooseAnImageFTP */
void FrameShowHelpScreen(int sx, int sy) // sx, sy - sizes of current window (screen) { // on pressing F1 button shows help screen const char * HelpStrings[] = { "Welcome to LinApple - Apple][ emulator for Linux!", "Conf file is linapple.conf in ~/.linapple directory by default", "Hugest archive of Apple][ stuff you can find at ftp.apple.asimov.net", " F1 - This help", " F2 - Cold reset, Shift+F2 - Reload conf file and restart", " F3, F4 - Choose an image file name for floppy disk", " in Slot 6 drive 1 or 2 respectively", " Shift+F3, Shift+F4 - The same thing for Apple hard disks", " (in Slot 7)", " F5 - Swap drives for Slot 6", " F6 - Toggle fullscreen mode", " F7 - Reserved for Debugger!", " F8 - Save current screen as a .bmp file", " Shift+F8 - Save settings changable at runtime in conf file", " F9 - Cycle through various video modes", " F10 - Quit emulator", " F11 - Save current state to file, Alt+F11 - quick save", " F12 - Reload it from file, Alt+F12 - quick load", " Ctrl+F12 - Hot reset", " Pause - Pause emulator", " Scroll Lock - Toggle full speed", "Num pad keys:", " Grey + - Speed up emulator", " Grey - - Speed it down", " Grey * - Normal speed" }; // const int PositionsY[] = { 7, 15, 26 }; SDL_Surface *my_screen; // for background SDL_Surface *tempSurface = NULL; // temporary surface if(font_sfc == NULL) if(!fonts_initialization()) { fprintf(stderr, "Font file was not loaded.\n"); return; //if we don't have a fonts, we just can do none } if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; if(tempSurface == NULL) tempSurface = screen; // use screen, if none available my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); font_print_centered(sx/2, int(5*facy), (char*)HelpStrings[0], screen, 1.5*facx, 1.3*facy); font_print_centered(sx/2, int(20*facy), (char*)HelpStrings[1], screen, 1.3*facx, 1.2*facy); font_print_centered(sx/2, int(30*facy), (char*)HelpStrings[2], screen, 1.2*facx, 1.0*facy); int Help_TopX = int(45*facy); int i; for(i = 3; i < 25; i++) font_print(4, Help_TopX + (i - 3) * 15 * facy, (char*)HelpStrings[i], screen, 1.5*facx, 1.5*facy); // show keys // show frames rectangle(screen, 0, Help_TopX - 5, /*SCREEN_WIDTH*/g_ScreenWidth - 1, int(335*facy), SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 1, Help_TopX - 4, /*SCREEN_WIDTH*/g_ScreenWidth, int(335*facy), SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 1, 1, /*SCREEN_WIDTH*/g_ScreenWidth - 2, (Help_TopX - 8), SDL_MapRGB(screen->format, 255, 255, 0)); if(apple_icon != NULL) { // display Apple logo tempSurface = SDL_DisplayFormat(apple_icon); SDL_Rect logo, scrr; logo.x = logo.y = 0; logo.w = tempSurface->w; logo.h = tempSurface->h; scrr.x = int(460*facx); scrr.y = int(270*facy); scrr.w = scrr.h = int(100*facy); SDL_SoftStretchOr(tempSurface, &logo, screen, &scrr); } SDL_Flip(screen); // show the screen SDL_Delay(1000); // wait 1 second to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN /*&& event.key.keysym.sym != SDLK_ESCAPE*/) {// wait for ESC-key pressed usleep(100); SDL_PollEvent(&event); } DrawFrameWindow(); // restore screen }
bool state_keyredefinition_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { int i; if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); if (image2!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); font_print_centered(sx/2,20,"REDEFINE CONTROLS:",screen); font_print_centered(sx/2,40,"[PRESS SELECT TO SKIP]",screen); if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE>39) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { save_configuration(); SDL_FreeSurface(image); image=0; STATE=1; SUBSTATE=0; } /* if */ } /* if */ if (SUBSTATE>=32) { bool found; char keystr[256]; char *upstr; SUBSTATE-=32; if (SUBSTATE>=0) { font_print(16,60,"PRESS A BUTTON FOR THRUST:",screen); } /* if */ if (SUBSTATE>=1) { strcpy(keystr,get_key_name((SDLKey)THRUST_KEY)); upstr=strupr(keystr); font_print(200,60,upstr,screen); font_print(16,70,"PRESS A BUTTON FOR ANTITHRUST:",screen); } /* if */ if (SUBSTATE>=2) { strcpy(keystr,get_key_name((SDLKey)ANTITHRUST_KEY)); upstr=strupr(keystr); font_print(200,70,upstr,screen); font_print(16,80,"PRESS A BUTTON FOR LEFT:",screen); } /* if */ if (SUBSTATE>=3) { strcpy(keystr,get_key_name((SDLKey)LEFT_KEY)); upstr=strupr(keystr); font_print(200,80,upstr,screen); font_print(16,90,"PRESS A BUTTON FOR RIGHT:",screen); } /* if */ if (SUBSTATE>=4) { strcpy(keystr,get_key_name((SDLKey)RIGHT_KEY)); upstr=strupr(keystr); font_print(200,90,upstr,screen); font_print(16,100,"PRESS A BUTTON FOR FIRE:",screen); } /* if */ if (SUBSTATE>=5) { strcpy(keystr,get_key_name((SDLKey)FIRE_KEY)); upstr=strupr(keystr); font_print(200,100,upstr,screen); font_print(16,110,"PRESS A BUTTON FOR ATRACTOR:",screen); } /* if */ if (SUBSTATE>=6) { strcpy(keystr,get_key_name((SDLKey)ATRACTOR_KEY)); upstr=strupr(keystr); font_print(200,110,upstr,screen); font_print(16,120,"PRESS A BUTTON FOR PAUSE:",screen); } /* if */ if (SUBSTATE>=7) { strcpy(keystr,get_key_name((SDLKey)PAUSE_KEY)); upstr=strupr(keystr); font_print(200,120,upstr,screen); font_print(32,140,"PRESS ANY BUTTON",screen); } /* if */ found=SUBSTATE < 7 ? false : true; for(i=0;!found && i<SDLK_LAST;i++) { if (keyboard[i] && !old_keyboard[i]) { if ((SDLKey)i == SDLK_ESCAPE) { keyboard[i] = 0; SUBSTATE++; break; } switch(SUBSTATE) { case 0:THRUST_KEY=(SDLKey)i; SUBSTATE++; found=true; break; case 1:ANTITHRUST_KEY=(SDLKey)i; SUBSTATE++; found=true; break; case 2:LEFT_KEY=(SDLKey)i; SUBSTATE++; found=true; break; case 3:RIGHT_KEY=(SDLKey)i; SUBSTATE++; found=true; break; case 4:FIRE_KEY=(SDLKey)i; SUBSTATE++; found=true; break; case 5:ATRACTOR_KEY=(SDLKey)i; SUBSTATE++; found=true; break; case 6:PAUSE_KEY=(SDLKey)i; SUBSTATE++; found=true; break; } /* switch */ } /* if */ } /* for */ if (SUBSTATE==7 && ((keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) || (keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY]) )) { SUBSTATE++; } /* if */ SUBSTATE+=32; } /* if */ return true; } /* state_keyredefinition_cycle */
bool state_changepack_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); { levelpacks.Delete(); #ifdef _WIN32 /* Find files: */ WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile("maps/*.lp",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); levelpacks.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); levelpacks.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; dp = opendir ("maps"); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-3]=='.' && ep->d_name[strlen(ep->d_name)-2]=='l' && ep->d_name[strlen(ep->d_name)-1]=='p') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); levelpacks.Add(tmp); } /* if */ } (void) closedir (dp); } #endif act_levelpack=0; } } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); font_print_centered(sx/2,(sy/2)-24,"CHOOSE LEVEL-PACK:",screen); { int i,y; char *tmp; i=0; y=(sy/2)-8; levelpacks.Rewind(); while(levelpacks.Iterate(tmp)) { if (i==act_levelpack) { SDL_Rect r; r.x=0; r.y=y; r.w=SCREEN_X; r.h=8; SDL_FillRect(screen,&r,SDL_MapRGB(screen->format,255,0,0)); } /* if */ font_print_centered(sx/2,y,tmp,screen); i++; y+=8; } /* while */ } if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE==32) { if (keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY]) { /* change level-pack: */ strcpy(levelpack,levelpacks[act_levelpack]); NLEVELS=-1; SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_UP] && !old_keyboard[SDLK_UP]) { if (act_levelpack>0) act_levelpack--; } /* if */ if (keyboard[SDLK_DOWN] && !old_keyboard[SDLK_DOWN]) { if (act_levelpack<(levelpacks.Length()-1)) act_levelpack++; } /* if */ } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { STATE=1; SUBSTATE=0; } /* if */ } /* if */ return true; } /* state_changepack_cycle */
bool state_mainmenu_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); SDL_SetColorKey(image,SDL_SRCCOLORKEY,SDL_MapRGB(image->format,0,0,0)); demotimer=0; demoon=false; } /* if */ if (demoon) { int retval; int i; unsigned char tmp[SDLK_LAST]; for(i=0;i<SDLK_LAST;i++) tmp[i]=0; tmp[THRUST_KEY]=fgetc(replayfile); tmp[ANTITHRUST_KEY]=fgetc(replayfile); tmp[LEFT_KEY]=fgetc(replayfile); tmp[RIGHT_KEY]=fgetc(replayfile); tmp[FIRE_KEY]=fgetc(replayfile); tmp[ATRACTOR_KEY]=fgetc(replayfile); game->cycle(tmp); retval=fgetc(replayfile); game->render(screen,sx,sy); if (retval!=0) { delete game; game=0; fclose(replayfile); replayfile=0; demoon=false; } /* if */ } else { SDL_FillRect(screen,0,0); } /* if */ if (demoon) { SDL_SetAlpha(image,SDL_SRCALPHA,tittle_alpha--); if (tittle_alpha<=0) tittle_alpha=0; } else { SDL_SetAlpha(image,SDL_SRCALPHA,tittle_alpha); tittle_alpha+=2; if (tittle_alpha>=255) tittle_alpha=255; } /* if */ SDL_BlitSurface(image,0,screen,0); { SDL_Rect r; r.x=SCREEN_X/2-80; r.w=160; r.y=sy-80; r.h=64; surface_fader(screen,0.5F,0.5F,0.5F,-1,&r); r.x=0; r.w=SCREEN_X; r.y=sy-16; r.h=16; surface_fader(screen,0.5F,0.5F,0.5F,-1,&r); r.x=SCREEN_X/2-80; r.w=160; r.y=sy-72+cursor*8; r.h=8; SDL_FillRect(screen,&r,SDL_MapRGB(screen->format,255,0,0)); } font_print_centered(SCREEN_X/2,sy-72,"START GAME",screen); font_print_centered(SCREEN_X/2,sy-64,"ENTER CODE",screen); font_print_centered(SCREEN_X/2,sy-56,"CHANGE LEVEL-PACK",screen); font_print_centered(SCREEN_X/2,sy-48,"REDEFINE CONTROLS",screen); font_print_centered(SCREEN_X/2,sy-40,"INSTRUCTIONS",screen); font_print_centered(SCREEN_X/2,sy-32,"REPLAYS",screen); font_print_centered(SCREEN_X/2,sy-24,"QUIT GAME",screen); { char tmp[256]; sprintf(tmp,"LEVELPACK: %s",levelpack); font_print(SCREEN_X/2-strlen(tmp)*3,sy-12,tmp,screen); } if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE==32) { if (!demoon) demotimer++; if (demotimer>=256) { int i; char tmp[80]; char levelname[256]; int fuel; int v1,v2; demoon=true; demotimer=0; tittle_alpha=255; sprintf(tmp,"demos/demo%i.rpl",((rand()%40)/10)+1); replayfile=fopen(tmp,"rb"); v1=fgetc(replayfile); v2=fgetc(replayfile); // To maintain compatibility with a previous version level=0; for(i=0;i<256;i++) levelname[i]=fgetc(replayfile); fuel=fgetc(replayfile); ship_type=fgetc(replayfile); if (game!=0) delete game; game=new TRANSBALL("graphics/","sound/","maps/",fuel,levelname,ship_type); } /* if */ if (keyboard[SDLK_UP]) { keyboard[SDLK_UP] = 0; cursor--; if (cursor < 0) cursor = 6; } /* if */ else if (keyboard[SDLK_DOWN]) { keyboard[SDLK_DOWN] = 0; cursor++; if (cursor > 6) cursor = 0; } /* if */ if ((keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY]) || (keyboard[SDLK_LCTRL] && !old_keyboard[SDLK_LCTRL])) { switch (cursor) { case 0: SUBSTATE++; SUBSTATE2=0; break; case 1: SUBSTATE++; SUBSTATE2=3; break; case 2: SUBSTATE++; SUBSTATE2=6; break; case 3: SUBSTATE++; SUBSTATE2=5; break; case 4: SUBSTATE++; SUBSTATE2=2; break; case 5: SUBSTATE++; SUBSTATE2=4; break; case 6: SUBSTATE++; SUBSTATE2=1; break; default: break; } timer=0; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE++; SUBSTATE2=1; } /* if */ } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { SDL_FreeSurface(image); image=0; if (game!=0) delete game; game=0; if (replayfile!=0) fclose(replayfile); replayfile=0; demoon=false; demotimer=0; if (SUBSTATE2==0) { int i; for(i=0;i<1000;i++) { char tmp[256]; snprintf(tmp,sizeof(tmp),"%s/replay%.3i.rpl",replay_dir, i); remove(tmp); } /* for */ STATE=4; SUBSTATE=0; level=0; replaynum=0; } /* if */ if (SUBSTATE2==1) { return false; } /* if */ if (SUBSTATE2==2) { STATE=2; SUBSTATE=0; } /* if */ if (SUBSTATE2==3) { STATE=3; SUBSTATE=0; SUBSTATE2=0; edit_text[0]=0; edit_position=0; } /* if */ if (SUBSTATE2==4) { STATE=7; SUBSTATE=0; } /* if */ if (SUBSTATE2==5) { STATE=11; SUBSTATE=0; } /* if */ if (SUBSTATE2==6) { STATE=12; SUBSTATE=0; } /* if */ } /* if */ } /* if */ return true; } /* state_mainmenu_cycle */
bool state_chooseship_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); if (image2!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.pcx"); image2=IMG_Load("graphics/tiles.pcx"); SDL_SetColorKey(image2,SDL_SRCCOLORKEY,SDL_MapRGB(image2->format,0,0,0)); } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); font_print_centered(sx/2,40,"CHOOSE YOUR SHIP:",screen); font_print(100,60,"SHADOW RUNNER:",screen); font_print(100,70," - HIGH SPEED AND RETRO THRUSTERS.",screen); font_print(100,80," - LOW POWERED WEAPONS.",screen); font_print(100,100,"V-PANTHER 2:",screen); font_print(100,110," - MODERATE SPEED.",screen); font_print(100,120," - MEDIUM POWERED WEAPONS.",screen); font_print(100,140,"X-TERMINATOR:",screen); font_print(100,150," - LOW SPEED.",screen); font_print(100,160," - HIGH POWERED WEAPONS.",screen); rectangle(screen,60,56+40*ship_type,32,32,SDL_MapRGB(screen->format,255,255,255)); { SDL_Rect r,d; r.x=96; r.y=272; r.w=32; r.h=32; d.x=60; d.y=60; SDL_BlitSurface(image2,&r,screen,&d); r.x=32; r.y=240; r.w=32; r.h=32; d.x=60; d.y=100; SDL_BlitSurface(image2,&r,screen,&d); r.x=96; r.y=336; r.w=32; r.h=32; d.x=60; d.y=140; SDL_BlitSurface(image2,&r,screen,&d); } if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { SDL_FreeSurface(image); image=0; SDL_FreeSurface(image2); image2=0; if (SUBSTATE2==0) { STATE=5; SUBSTATE=0; } /* if */ if (SUBSTATE2==1) { STATE=1; SUBSTATE=0; } /* if */ } /* if */ } /* if */ if (SUBSTATE==32) { if (keyboard[SDLK_LEFT] && !old_keyboard[SDLK_LEFT] && ship_type>0) ship_type--; if (keyboard[SDLK_RIGHT] && !old_keyboard[SDLK_RIGHT] && ship_type<2) ship_type++; if (keyboard[SDLK_UP] && !old_keyboard[SDLK_UP] && ship_type>0) ship_type--; if (keyboard[SDLK_DOWN] && !old_keyboard[SDLK_DOWN] && ship_type<2) ship_type++; if (keyboard[SDLK_SPACE] && !old_keyboard[SDLK_SPACE]) { SUBSTATE++; SUBSTATE2=0; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE++; SUBSTATE2=1; } /* if */ } /* if */ return true; } /* state_chooseship_cycle */
bool state_replaymanager_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); refind_files=true; SUBSTATE2=0; } /* if */ if (refind_files) { refind_files=false; files.Delete(); #ifdef _WIN32 /* Find files: */ WIN32_FIND_DATA finfo; HANDLE h; if (replay_source==0) h=FindFirstFile("replays/*.rpl",&finfo); else h=FindFirstFile("high/*.rpl",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; if (replay_source==0) dp = opendir (replay_dir); else dp = opendir (high_dir); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-4]=='.' && ep->d_name[strlen(ep->d_name)-3]=='r' && ep->d_name[strlen(ep->d_name)-2]=='p' && ep->d_name[strlen(ep->d_name)-1]=='l') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); files.Add(tmp); } /* if */ } (void) closedir (dp); } #endif first_file=0; act_file=0; } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); if (replay_source==0) font_print_centered(sx/2,20,"REPLAY FILES [L - CHANGE SOURCE]:",screen); else font_print_centered(sx/2,20,"HIGH SCORE FILES [L - CHANGE SOURCE]:",screen); if (replay_source!=0) font_print_centered(sx/2,30,"PRESS FIRE TO VIEW OR R TO REBUILD",screen); { char *tmp; int i; files.Rewind(); i=0; while(files.Iterate(tmp)) { if (i>=first_file && i<first_file+18) { char *sname[3]={"SH.RNR.","PNTR.2","X-TRM."}; int ship,length; char tmp2[256],tmp3[256]; if (i==act_file) { SDL_Rect r; r.x=2; r.y=42+(i-first_file)*10-1; r.w=strlen(tmp)*6+2; r.h=9; SDL_FillRect(screen,&r,SDL_MapRGB(screen->format,255,0,0)); } /* if */ font_print(4,42+(i-first_file)*10,tmp,screen); if (replay_source==0) snprintf(tmp2, sizeof(tmp2), "%s/%s",replay_dir, tmp); else snprintf(tmp2, sizeof(tmp2), "%s/%s",high_dir, tmp); replay_parameters(tmp2,&ship,&length,tmp3); { int min,sec,dec; dec=(length*18)/10; sec=dec/100; dec=dec%100; min=sec/60; sec=sec%60; sprintf(tmp2,"%.2i:%.2i'%.2i %s",min,sec,dec,sname[ship]); font_print(220,42+(i-first_file)*10,tmp2,screen); } } /* if */ i++; } /* while */ } rectangle(screen,-1,40,321,185,SDL_MapRGB(screen->format,255,255,255)); rectangle(screen,214,40,0,185,SDL_MapRGB(screen->format,255,255,255)); if (SUBSTATE<32) { surface_fader(screen,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,float(SUBSTATE)/32.0F,-1,0); SUBSTATE++; } /* if */ if (SUBSTATE>32) { surface_fader(screen,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,float(64-SUBSTATE)/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==64) { SDL_FreeSurface(image); image=0; if (SUBSTATE2==0) { STATE=1; SUBSTATE=0; } /* if */ if (SUBSTATE2==1) { int i; char tmp[256]; char levelname[256]; int v1,v2; int fuel; STATE=8; SUBSTATE=0; if (replay_source==0) snprintf(tmp,sizeof(tmp), "%s/%s", replay_dir, files[act_file]); else snprintf(tmp, sizeof(tmp), "%s/%s",high_dir, files[act_file]); replayfile=fopen(tmp,"rb"); v1=fgetc(replayfile); v2=fgetc(replayfile); // To maintain compatibility with a previous version level=0; for(i=0;i<256;i++) levelname[i]=fgetc(replayfile); fuel=fgetc(replayfile); ship_type=fgetc(replayfile); game=new TRANSBALL("graphics/","sound/","maps/",fuel,levelname,ship_type); timer=0; } /* if */ } /* if */ } /* if */ if (SUBSTATE==32) { if ((keyboard[SDLK_UP] && !old_keyboard[SDLK_UP]) || (keyboard[SDLK_LEFT] && !old_keyboard[SDLK_LEFT])) { if (act_file>0) act_file--; if (act_file<first_file) first_file=act_file; } /* if */ if ((keyboard[SDLK_DOWN] && !old_keyboard[SDLK_DOWN]) || (keyboard[SDLK_RIGHT] && !old_keyboard[SDLK_RIGHT])) { if (act_file<(files.Length()-1)) act_file++; if (act_file>=(first_file+18)) first_file=act_file-17; } /* if */ if (keyboard[SDLK_PAGEUP] && !old_keyboard[SDLK_PAGEUP]) { act_file-=18; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN] && !old_keyboard[SDLK_PAGEDOWN]) { act_file+=18; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+18)) first_file=act_file-17; } /* if */ if (keyboard[SDLK_LCTRL] && !old_keyboard[SDLK_LCTRL]) { SUBSTATE2=1; if (files.EmptyP()) SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_ESCAPE] && !old_keyboard[SDLK_ESCAPE]) { SUBSTATE2=0; SUBSTATE++; } /* if */ if (keyboard[SDLK_TAB] && !old_keyboard[SDLK_TAB]) { if (replay_source==0) replay_source=1; else replay_source=0; act_file=0; first_file=0; refind_files=true; } /* if */ if (keyboard[SDLK_BACKSPACE] && !old_keyboard[SDLK_BACKSPACE] && replay_source==1) { { List<char> replays; char *replay; char complete_replayname[256]; /* look for files: */ #ifdef _WIN32 WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile("replays/*.rpl",&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); while(FindNextFile(h,&finfo)==TRUE) { char *tmp; tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); replays.Add(tmp); } /* while */ } /* if */ #else DIR *dp; struct dirent *ep; dp = opendir (replay_dir); if (dp != NULL) { while (ep = readdir (dp)) { char *tmp; if (strlen(ep->d_name)>4 && ep->d_name[strlen(ep->d_name)-4]=='.' && ep->d_name[strlen(ep->d_name)-3]=='r' && ep->d_name[strlen(ep->d_name)-2]=='p' && ep->d_name[strlen(ep->d_name)-1]=='l') { tmp=new char[strlen(ep->d_name)+1]; strcpy(tmp,ep->d_name); replays.Add(tmp); } /* if */ } (void) closedir (dp); } #endif /* Check if this replay is a highscore: */ replays.Rewind(); while(replays.Iterate(replay)) { int level; int ship,current_time,previous_high=-1; char levelname[256]; snprintf(complete_replayname, sizeof(complete_replayname), "%s/%s",replay_dir, replay); if (replay_parameters(complete_replayname,&ship,¤t_time,levelname)==2) { for(level=0;level<NLEVELS;level++) { if (strcmp(levelname,levelnames[level])==0) { /* the replay corresponds to level 'i' of the current level pack: */ /* UPDATE THE HIGHSCORES: */ int best_time=-1; int i,j; char highname[256],filename2[256]; previous_high=-1; j=0; snprintf(highname, sizeof(highname), "%s/", high_dir); j+=strlen(highname); for(i=0;levelpack[i]!='.' && levelpack[i]!=0;i++) highname[j++]=levelpack[i]; highname[j++]='-'; sprintf(highname+j,"%.3i",level); j+=3; highname[j++]='-'; if (ship==0) highname[j++]='S'; if (ship==0) highname[j++]='R'; if (ship==1) highname[j++]='V'; if (ship==1) highname[j++]='P'; if (ship==2) highname[j++]='X'; if (ship==2) highname[j++]='T'; highname[j++]='.'; highname[j++]='r'; highname[j++]='p'; highname[j++]='l'; highname[j++]=0; { int retval; int s,l; char levelname[256]; retval=replay_parameters(highname,&s,&l,levelname); if (retval==2) { previous_high=l; } /* if */ } if (previous_high==-1 || previous_high>current_time) { snprintf(filename2, sizeof(filename2), "%s/%s",replay_dir, replay); replay_copy(filename2,highname); } /* if */ } /* if */ } /* if */ } /* if */ } /* while */ } act_file=0; first_file=0; refind_files=true; } /* if */ } /* if */ return true; } /* state_replaymanager_cycle */
bool state_game_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { int retval=0; if (keyboard[PAUSE_KEY] && !old_keyboard[PAUSE_KEY]) { if (pause) pause=false; else pause=true; } /* if */ if (!pause) { retval=game->cycle(keyboard); if (replayfile!=0) { fputc(keyboard[THRUST_KEY],replayfile); fputc(keyboard[ANTITHRUST_KEY],replayfile); fputc(keyboard[LEFT_KEY],replayfile); fputc(keyboard[RIGHT_KEY],replayfile); fputc(keyboard[FIRE_KEY],replayfile); fputc(keyboard[ATRACTOR_KEY],replayfile); fputc(retval,replayfile); } /* if */ } /* if */ game->render(screen,sx,sy); if (pause) { surface_fader(screen,0.5F,0.5F,0.5F,-1,0); font_print(sx/2,sy/2-16,"PAUSE",screen); } else { timer++; } /* if */ /* Print time */ { char tmp[128]; int min,sec,dec; dec=(timer*18)/10; sec=dec/100; dec=dec%100; min=sec/60; sec=sec%60; sprintf(tmp,"%.2i:%.2i",min,sec); font_print_right(sx,0,tmp,screen); } if (retval!=0) { /* Retrieve statistics: */ // timmer=game->get_statistics(0); used_fuel=game->get_statistics(1); remaining_fuel=game->get_statistics(2); n_shots=game->get_statistics(3); n_hits=game->get_statistics(4); enemies_destroyed=game->get_statistics(5); delete game; game=0; fclose(replayfile); replayfile=0; } /* if */ if (retval==1) { STATE=5; SUBSTATE=0; } /* if */ if (retval==2) { STATE=13; SUBSTATE=0; } /* if */ if (retval==3) { STATE=9; SUBSTATE=0; } /* if */ return true; } /* state_game_cycle */
bool ChooseAnImage(int sx,int sy, char *incoming_dir, int slot, char **filename, bool *isdir, int *index_file) { /* Parameters: sx, sy - window size, incoming_dir - in what dir find files, slot - in what slot should an image go (common: #6 for 5.25' 140Kb floppy disks, and #7 for hard-disks). slot #5 - for 800Kb floppy disks, but we do not use them in Apple][? (They are as a rule with .2mg extension) index_file - from which file we should start cursor (should be static and 0 when changing dir) Out: filename - chosen file name (or dir name) isdir - if chosen name is a directory */ /* Surface: */ SDL_Surface *my_screen; // for background if(font_sfc == NULL) if(!fonts_initialization()) return false; //if we don't have a fonts, we just can do none List<char> files; // our files List<char> sizes; // and their sizes (or 'dir' for directories) int act_file; // current file int first_file; // from which we output files printf("Disckchoose! We are here: %s\n",incoming_dir); // files.Delete(); // sizes.Delete(); #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ DIR *dp; struct dirent *ep; dp = opendir (incoming_dir); // open and read incoming directory char *tmp; int i,j, B, N; // for cycles, beginning and end of list // build prev dir if(strcmp(incoming_dir, "/")) { tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs if (dp != NULL) { while (ep = readdir (dp)) // first looking for directories { int what = getstat(incoming_dir, ep->d_name, NULL); if (strlen(ep->d_name) > 0 && /*strcmp(ep->d_name,".")*/// omit "." (cur dir) ep->d_name[0] != '.'/*strcmp(ep->d_name,"..")*/ && what == 1) // is directory! { tmp = new char[strlen(ep->d_name)+1]; // add entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } /* if */ } } #else /* Windows specific functions of reading directory structure */ /* Find subdirs: */ if(strcmp(incoming_dir, "/")) { // we are not in upper direcory tmp = new char[3]; strcpy(tmp, ".."); files.Add(tmp); tmp = new char[5]; strcpy(tmp, "<UP>"); sizes.Add(tmp); // add sign of directory B = 1; } else B = 0; // for sorting dirs WIN32_FIND_DATA finfo; HANDLE h; h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { char *tmp; if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0) { // add this entry if it is directory tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[6]; strcpy(tmp, "<DIR>"); sizes.Add(tmp); // add sign of directory } } /* while */ } /* if */ #endif // sort directories. Please, don't laugh at my bubble sorting - it the simplest thing I've ever seen --bb if(files.Length() > 2) { N = files.Length() - 1; // B = 1;`- defined above for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } B = files.Length(); // start for files #ifndef _WIN32 /* POSIX specific routines of reading directory structure */ (void) rewinddir (dp); // to the start // now get all regular files while (ep = readdir (dp)) { int fsize; if (strlen(ep->d_name) > 4 && ep->d_name[0] != '.' && (getstat(incoming_dir, ep->d_name, &fsize) == 2)) // is normal file! { tmp = new char[strlen(ep->d_name)+1]; // add this entity to list strcpy(tmp, ep->d_name); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", fsize); sizes.Add(tmp); // add this size to list } /* if */ } (void) closedir (dp); #else /* Windows specific functions of reading directory structure */ /* Find files: */ h=FindFirstFile(incoming_dir,&finfo); if (h!=INVALID_HANDLE_VALUE) { // char *tmp; - must be defined in previous section, when searching subdirs if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } while(FindNextFile(h,&finfo)==TRUE) { if(finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY == 0) { // add this entry if it is NOT directory! tmp=new char[strlen(finfo.cFileName)+1]; strcpy(tmp,finfo.cFileName); files.Add(tmp); tmp = new char[10]; // 1400000KB snprintf(tmp, 9, "%dKB", ((finfo.nFileSizeHigh * (MAXDWORD+1)) + finfo.nFileSizeLow)); sizes.Add(tmp); // add this size to list } } /* while */ } /* if */ #endif // do sorting for files if(files.Length() > 2 && B < files.Length()) { N = files.Length() - 1; // B = 1; for(i = N; i > B; i--) for(j = B; j < i; j++) if(strcasecmp(files[j], files[j + 1]) > 0) { files.Swap(j,j + 1); sizes.Swap(j,j + 1); } } // Count out cursor position and file number output act_file = *index_file; if(act_file >= files.Length()) act_file = 0; // cannot be more than files in list first_file = act_file - (FILES_IN_SCREEN / 2); if (first_file < 0) first_file = 0; // cannot be negativ... // Show all directories (first) and files then // char *tmp; char *siz; // int i; // prepare screen double facx = double(g_ScreenWidth) / double(SCREEN_WIDTH); double facy = double(g_ScreenHeight) / double(SCREEN_HEIGHT); SDL_Surface *tempSurface = NULL; if(!g_WindowResized) { if(g_nAppMode == MODE_LOGO) tempSurface = g_hLogoBitmap; // use logobitmap else tempSurface = g_hDeviceBitmap; } else tempSurface = g_origscreen; if(tempSurface == NULL) tempSurface = screen; // use screen, if none available my_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, tempSurface->w, tempSurface->h, tempSurface->format->BitsPerPixel, 0, 0, 0, 0); if(tempSurface->format->palette && my_screen->format->palette) SDL_SetColors(my_screen, tempSurface->format->palette->colors, 0, tempSurface->format->palette->ncolors); surface_fader(my_screen, 0.2F, 0.2F, 0.2F, -1, 0); // fade it out to 20% of normal SDL_BlitSurface(tempSurface, NULL, my_screen, NULL); while(true) { SDL_BlitSurface(my_screen, NULL, screen, NULL); // show background font_print_centered(sx/2 ,5*facy , incoming_dir, screen, 1.5*facx, 1.3*facy); if (slot == 6) font_print_centered(sx/2,20*facy,"Choose image for floppy 140KB drive", screen, 1*facx, 1*facy); else if (slot == 7) font_print_centered(sx/2,20*facy,"Choose image for Hard Disk", screen, 1*facx, 1*facy); else if (slot == 5) font_print_centered(sx/2,20*facy,"Choose image for floppy 800KB drive", screen, 1*facx, 1*facy); else if (slot == 1) font_print_centered(sx/2,20*facy,"Select file name for saving snapshot", screen, 1*facx, 1*facy); else if (slot == 0) font_print_centered(sx/2,20*facy,"Select snapshot file name for loading", screen, 1*facx, 1*facy); font_print_centered(sx/2,30*facy, "Press ENTER to choose, or ESC to cancel",screen, 1.4*facx, 1.1*facy); files.Rewind(); // from start sizes.Rewind(); i = 0; // printf("We've printed some messages, go to file list!\n"); // show all fetched dirs and files // topX of first fiel visible int TOPX = int(45*facy); while(files.Iterate(tmp)) { sizes.Iterate(siz); // also fetch size string if (i >= first_file && i < first_file + FILES_IN_SCREEN) { // FILES_IN_SCREEN items on screen // char tmp2[80],tmp3[256]; if (i == act_file) { // show item under cursor (in inverse mode) SDL_Rect r; r.x= 2; r.y= TOPX + (i-first_file) * 15 * facy - 1; if(strlen(tmp) > 46) r.w = 46 * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; else r.w= strlen(tmp) * FONT_SIZE_X /* 6 */ * 1.7 * facx + 2; // 6- FONT_SIZE_X r.h= 9 * 1.5 * facy; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format,255,0,0));// in RED } /* if */ // print file name with enlarged font char ch; ch = 0; if(strlen(tmp) > 46) { ch = tmp[46]; tmp[46] = 0;} //cut-off too long string font_print(4, TOPX + (i - first_file) * 15 * facy, tmp, screen, 1.7*facx, 1.5*facy); // show name font_print(sx - 70 * facx, TOPX + (i - first_file) * 15 * facy, siz, screen, 1.7*facx, 1.5*facy);// show info (dir or size) if(ch) tmp[46] = ch; //restore cut-off char } /* if */ i++; // next item } /* while */ ///////////////////////////////////////////////////////////////////////////////////////////// // draw rectangles rectangle(screen, 0, TOPX - 5, sx, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); rectangle(screen, 480*facx, TOPX - 5, 0, 320*facy, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_Flip(screen); // show the screen SDL_Delay(KEY_DELAY); // wait some time to be not too fast ////////////////////////////////// // Wait for keypress ////////////////////////////////// SDL_Event event; // event Uint8 *keyboard; // key state event.type = SDL_QUIT; while(event.type != SDL_KEYDOWN) { // wait for key pressed SDL_Delay(10); SDL_PollEvent(&event); } // control cursor keyboard = SDL_GetKeyState(NULL); // get current state of pressed (and not pressed) keys if (keyboard[SDLK_UP] || keyboard[SDLK_LEFT]) { if (act_file>0) act_file--; // up one position if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_DOWN] || keyboard[SDLK_RIGHT]) { if (act_file < (files.Length() - 1)) act_file++; if (act_file >= (first_file + FILES_IN_SCREEN)) first_file=act_file - FILES_IN_SCREEN + 1; } /* if */ if (keyboard[SDLK_PAGEUP]) { act_file-=FILES_IN_SCREEN; if (act_file<0) act_file=0; if (act_file<first_file) first_file=act_file; } /* if */ if (keyboard[SDLK_PAGEDOWN]) { act_file+=FILES_IN_SCREEN; if (act_file>=files.Length()) act_file=(files.Length()-1); if (act_file>=(first_file+FILES_IN_SCREEN)) first_file=act_file-FILES_IN_SCREEN + 1; } /* if */ // choose an item? if (keyboard[SDLK_RETURN]) { // dup string from selected file name *filename = strdup(files[act_file]); // printf("files[act_file]=%s, *filename=%s\n\n", files[act_file], *filename); if(!strcmp(sizes[act_file], "<DIR>") || !strcmp(sizes[act_file], "<UP>")) *isdir = true; else *isdir = false; // this is directory (catalog in Apple][ terminology) *index_file = act_file; // remember current index files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return true; } /* if */ if (keyboard[SDLK_ESCAPE]) { files.Delete(); sizes.Delete(); SDL_FreeSurface(my_screen); return false; // ESC has been pressed } /* if */ if (keyboard[SDLK_HOME]) { // HOME? act_file=0; first_file=0; } /* if */ if (keyboard[SDLK_END]) { // END? act_file=files.Length() - 1; // go to the last possible file in list first_file=act_file - FILES_IN_SCREEN + 1; if(first_file < 0) first_file = 0; } /* if */ } } /* ChooseAnImage */
bool state_instructions_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard) { if (SUBSTATE==0) { if (image!=0) SDL_FreeSurface(image); image=IMG_Load("graphics/tittle.png"); } /* if */ SDL_BlitSurface(image,0,screen,0); surface_fader(screen,0.5F,0.5F,0.5F,-1,0); if (SUBSTATE<64) { font_print(16,10," SUPER TRANSBALL 2 V1.5",screen); font_print(16,30," THE FUTURE, THE SUN DOES NOT SHINE ANYMORE",screen); font_print(16,40,"AND THE ONLY ENERGY SOURCE ARE \"THE SPHERES\".",screen); font_print(16,50,"THE SPHERES CONTAIN ENOUGH ENERGY FOR A PLANET",screen); font_print(16,60,"TO SURVIVE. THEY ARE CHARGED WITH THE ENERGY",screen); font_print(16,70,"OF OTHER STARS.",screen); font_print(16,90," AS THE HUMANS ARE HIGHLY DEPENDENT ON THE",screen); font_print(16,100,"SPHERES, AN OPORTUNIST CIVILIZATION HAS STOLEN",screen); font_print(16,110,"ALL THE CHARGED SPHERES FROM THE EARTH EXPECTING",screen); font_print(16,120,"TO COLONIZE THE PLANET. AS A LAST CHANCE, THE",screen); font_print(16,130,"LAST ENERGY HAS BEEN TRANSFERED TO A SCOUT SHIP",screen); font_print(16,140,"AND SENT TO RECOVER THE SPHERES...",screen); font_print(16,160,"YOU COMMAND THIS SHIP, YOU ARE THE LAST CHANCE",screen); font_print(16,170,"FOR THE SURVIVAL OF THE HUMAN RACE...",screen); } /* if */ if (SUBSTATE>64 && SUBSTATE<128) { font_print(16,10," SUPER TRANSBALL 2 V1.5",screen); font_print(16,30," THE CONTROLS OF THE SHIP ARE [REDEFINIBLE]:",screen); font_print(16,50," UP - PROPULSORS",screen); font_print(16,60," DOWN - RETROPROPULSORS [NOT ALL THE SHIPS]",screen); font_print(16,70," LEFT - TURN LEFT",screen); font_print(16,80," RIGHT - TURN RIGHT",screen); font_print(16,90," A - FIRE",screen); font_print(16,100," B - BALL ATRACTOR",screen); font_print(16,120,"TO ACHIEVE YOUR GOAL, YOU CAN CHOOSE BETWEEN",screen); font_print(16,130,"THREE DIFFERENT SHIPS, EACH ONE WITH ITS OWN",screen); font_print(16,140,"CHARACTERISTICS:",screen); font_print(16,160," THE SHADOW RUNNER: HIGH SPEED, FEW WEAPONS",screen); font_print(16,170," THE V-PANTHER 2 : MEDIUM SPEED, MEDIUM WEAPONS",screen); font_print(16,180," THE X-TERMINATOR : LOW SPEED, DEFINITIVE WEAPONS",screen); } /* if */ if (SUBSTATE>128 && SUBSTATE<192) { font_print(16,10," SUPER TRANSBALL 2 V1.5",screen); font_print(16,30, "GUIDE[1]:",screen); font_print(16,50, " - YOUR SHIP IS UNDER THE EFFECT OF THE GRAVITY.",screen); font_print(16,60, " - WITH YOUR THRUSTER, YOU MUST AVOID TO COLLIDE",screen); font_print(16,70, " WITH THE BACKGROUND.",screen); font_print(16,80, " - YOU MUST FIND THE WHITE BALL, THEN USE THE",screen); font_print(16,90, " ATRACTOR OVER IT DURING A WHILE. IT WILL TURN",screen); font_print(16,100," BLUE. ",screen); font_print(16,110," - WHEN THE BALL IS BLUE, YOUR SHIP ATRACTS IT.",screen); font_print(16,120," - TO COMPLETE A LEVEL YOU MUST CARRY THE BALL",screen); font_print(16,130," TO THE UPPER PART.",screen); font_print(16,140," - YOU CAN KILL THE MANY ENEMIES YOU WILL FIND",screen); font_print(16,150," USING YOUR CANONS, SEVERAL SHOTS ARE NEEDED",screen); font_print(16,160," TO KILL THE ENEMIES [DEPENDING ON THE SHIP].",screen); } /* if */ if (SUBSTATE>192 && SUBSTATE<256) { font_print(16,10," SUPER TRANSBALL 2 V1.5",screen); font_print(16,30, "GUIDE[2]:",screen); font_print(16,50, " - YOU WILL FIND DOORS THAT OPEN OR CLOSE WHEN",screen); font_print(16,60, " YOU TAKE THE BALL.",screen); font_print(16,70, " - SOME OTHER DOORS ARE ACTIVATED BY SWITCHES.",screen); font_print(16,80, " - TO PRESS A SWITCH, YOU MUST MAKE THE BALL TO",screen); font_print(16,90, " BOUNCE ON IT.",screen); font_print(16,100," - YOUR THRUSTER AND WEAPONS USE FUEL, YOU MUST ",screen); font_print(16,110," RECHARGE IT WHENEVER POSSIBLE.",screen); font_print(16,120," - SOME LEVELS MAY SEEM VERY DIFFICULT THE FIRST",screen); font_print(16,130," TIME, BUT WITH PRACTICE, EVERY LEVEL BECOMES",screen); font_print(16,140," EASY... :]",screen); } /* if */ if (SUBSTATE>256 && SUBSTATE<320) { font_print(16,10," SUPER TRANSBALL 2 V1.5",screen); font_print(16,30,"THIS GAME IS INSPIRED ON THARA ZHRUSTA FOR THE",screen); font_print(16,40,"AMIGA 500, BUT UNFORTUNATELY CANNOT COMPARE WITH",screen); font_print(16,50,"IT...",screen); font_print(16,100," BRAIN 2002-2005",screen); font_print(16,110," SANTI ONTA~ON VILLAR",screen); font_print(16,120," SEE README FILE FOR MORE INFO",screen); font_print(16,140," GCW ZERO PORT 2015 ARTUR \"ZEAR\" ROJEK",screen); } /* if */ if ((SUBSTATE%64)<32) { surface_fader(screen,float((SUBSTATE%64))/32.0F,float((SUBSTATE%64))/32.0F,float((SUBSTATE%64))/32.0F,-1,0); SUBSTATE++; } /* if */ if ((SUBSTATE%64)==32) { if (keyboard[FIRE_KEY] && !old_keyboard[FIRE_KEY]) SUBSTATE++; } /* if */ if ((SUBSTATE%64)>32) { surface_fader(screen,float(64-(SUBSTATE%64))/32.0F,float(64-(SUBSTATE%64))/32.0F,float(64-(SUBSTATE%64))/32.0F,-1,0); SUBSTATE++; if (SUBSTATE==320) { SDL_FreeSurface(image); image=0; STATE=1; SUBSTATE=0; } /* if */ } /* if */ return true; } /* state_instructions_cycle */