int doInit(Uint32 vidFlags, int doWipe) { int i; BrInitError error; if(br_init(&error, "kuri2d") == 0 && error != BR_INIT_ERROR_DISABLED) { printf("Warning: BinReloc failed to initialize (error code %d)\n", error); printf("Will fallback to hardcoded default path.\n"); } if(SDL_Init((Uint32)(SDL_INIT_VIDEO | SDL_INIT_AUDIO))) { printf("Unable to init SDL: %s\n", SDL_GetError()); return 0; } (void)atexit(SDL_Quit); (void)atexit(TTF_Quit); /* malloc some defaults - they *should* be reloaded later */ level = (KuriLevel *)malloc(sizeof(KuriLevel)); startState = malloc(sizeof(State)); state = malloc(sizeof(State)); strcpy(state->name, "Player"); state->level = (Uint8)0; state->score = (Uint8)0; state->lives = (Uint8)3; for(i=0; i<MAX_HISCORES; i++) { strcpy(hiscores[i].name, "nobody"); hiscores[i].score = 0; hiscores[i].level = 0; } if(level && startState && state && (doWipe ? 1 : loadHiScores()) && loadBackgrounds() && loadBlocks() && loadLevels() && loadSounds() && loadFonts() && loadTexts() && openFrame(vidFlags)) { return 1; } return 0; }
// drawHiScoreBoard - draws the hiscore board, and updates it with the hiscore from the latest game void drawHiScoreBoard(unsigned long int newscore) { SCORE scores[MAX_HISCORES]; short int loop, pos = -1; char name[10], str[50], *error = "File I/O Error"; HANDLE dlg; // restore interrupt handlers OSSetSR(0x0000); if (!loadHiScores(scores)) { // cannot open hiscore file -- display error DlgMessage(error,"Unable to Load HiScore Data",BT_OK,BT_NONE); return; } // check if latest score is a highscore for (loop = (MAX_HISCORES - 1); loop >= 0; loop--) { if (newscore > scores[loop].score) { // new HiScore!! pos = loop; } } if (pos != -1) { // if we found a new hiscore if ((dlg = DialogNewSimple(DLGWIDTH,DLGHEIGHT)) == H_NULL) { DlgMessage("Memory Allocation Error","Not Enough Free Memory!",BT_OK,BT_NONE); } else { DialogAddTitle(dlg,"New Hiscore!",BT_OK,BT_NONE); DialogAddRequest(dlg,5,25,"Your Name:",0,9,11); sprintf(str,"You earned the #%hd hiscore position!",pos+1); DialogAddText(dlg,5,15,str); do { // truncate name variable name[0] = 0; } while (DialogDo(dlg,CENTER,CENTER,name,NULL) != KEY_ENTER); // free the dialog box memory HeapFree(dlg); // move the hiscore list down if (pos < (MAX_HISCORES - 1)) { for (loop = (MAX_HISCORES - 1); loop > pos; loop--) { scores[loop].score = scores[loop - 1].score; scores[loop].name[0] = 0; strcpy(scores[loop].name,scores[loop - 1].name); } } // fill in the new hiscore scores[pos].score = newscore; scores[pos].name[0] = 0; strcpy(scores[pos].name,name); if (!saveHiScores(scores)) { DlgMessage(error,"Unable to save HiScore Board",BT_OK,BT_NONE); } } } // display the hiscore board // clear the screen ClrScr(); // draw the screen borders drawBorder(); // draw the game logo drawLogo(); FontSetSys(F_8x10); DrawStr(25,35,"Hiscore Board",A_NORMAL); FontSetSys(F_6x8); for (loop = 0; loop < 5; loop++) { printf_xy(20,50+loop*10,"#%hd %-9s %lu",loop+1,scores[loop].name,scores[loop].score); } ngetchx(); // disable interrupts OSSetSR(0x0700); // wait for keypresses to dissipate delay(KEYDELAY); }