00001 00002 // 00003 // Das Tank - Copyright (C) 2006, 2007 Windsor Schmidt <windsor@windsorworld.net> 00004 // 00005 // This program is free software; you can redistribute it and/or modify it 00006 // under the terms of the GNU General Public License as published by the Free 00007 // Software Foundation; either version 2 of the License, or (at your option) 00008 // any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 // more details. 00014 // 00015 // You should have received a copy of the GNU General Public License along with 00016 // this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 // Place, Suite 330, Boston, MA 02111-1307 USA 00018 // 00020 00021 00022 #ifndef STDAFX 00023 #include "stdafx.h" 00024 #endif 00025 00026 static char initials[40]; // names of top 10 high score players 00027 int scores[10]; // values of top 10 high scores 00028 static char textBuffer[80]; 00029 00037 int MainMenu(gcn::OpenGLGraphics* graphics, gcn::ImageFont* font) 00038 { 00039 int menuInput; 00040 int selection = 1; // player's selection from the menu 00041 int menuItemCount = 5; 00042 00043 glEnable(GL_TEXTURE_2D); 00044 glClearColor(0.282f, 0.282f, 0.282f, 0.0f); 00045 00046 while(1) 00047 { 00048 menuInput = GetMenuInput(); 00049 switch(menuInput) 00050 { 00051 case MENUINPUT_UP: // up one menu item 00052 PlaySound(SOUNDID_MENUSELECT); 00053 backAccel = .1; 00054 if(selection > 1) selection--; 00055 break; 00056 case MENUINPUT_DOWN: // down one menu item 00057 PlaySound(SOUNDID_MENUSELECT); 00058 backAccel = -.1; 00059 if(selection < menuItemCount) selection++; 00060 break; 00061 case MENUINPUT_SELECT: // select current menu item 00062 PlaySound(SOUNDID_MENUSELECT); 00063 backZ = -2; 00064 return selection; 00065 break; 00066 } 00067 00068 // draw the menu background 00069 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 00070 00071 DrawMenuBackground(1.2,-1,-1,1); 00072 00073 // draw the main menu 00074 graphics->_beginDraw(); 00075 graphics->setFont(font); 00076 graphics->drawText("das tank 1.0",SCREEN_WIDTH/2,200,gcn::Graphics::CENTER); 00077 graphics->drawText("start game",SCREEN_WIDTH/2,300,gcn::Graphics::CENTER); 00078 graphics->drawText("options",SCREEN_WIDTH/2,350,gcn::Graphics::CENTER); 00079 graphics->drawText("high scores",SCREEN_WIDTH/2,400,gcn::Graphics::CENTER); 00080 graphics->drawText("credits",SCREEN_WIDTH/2,450,gcn::Graphics::CENTER); 00081 graphics->drawText("quit game",SCREEN_WIDTH/2,500,gcn::Graphics::CENTER); 00082 00083 graphics->drawText(">",380,250+selection*50,gcn::Graphics::LEFT); 00084 graphics->drawText("<",SCREEN_WIDTH-380,250+selection*50,gcn::Graphics::RIGHT); 00085 graphics->_endDraw(); 00086 00087 // swap buffers to display 00088 SDL_GL_SwapBuffers(); 00089 } 00090 00091 return 0; 00092 } 00093 00094 00102 int OptionsMenu(gcn::OpenGLGraphics* graphics, gcn::ImageFont* font, GameState * State) 00103 { 00104 int menuInput; 00105 int selection = 1; // player's selection from the menu 00106 int menuItemCount = 10; 00107 char optionItem[80]; 00108 00109 srand(SDL_GetTicks()); // seed random number generator 00110 00111 glEnable(GL_TEXTURE_2D); 00112 00113 while(1) 00114 { 00115 00116 menuInput = GetMenuInput(); 00117 00118 switch(menuInput) 00119 { 00120 case MENUINPUT_UP: // up one menu item 00121 PlaySound(SOUNDID_MENUSELECT); 00122 backAccel = .1; 00123 if(selection > 1) selection--; 00124 break; 00125 00126 case MENUINPUT_DOWN: // down one menu item 00127 PlaySound(SOUNDID_MENUSELECT); 00128 backAccel = -.1; 00129 if(selection < menuItemCount) selection++; 00130 break; 00131 00132 case MENUINPUT_LEFT: // modify current menu selection item 00133 if((selection >= 1) && (selection <= menuItemCount - 1)) 00134 { 00135 switch(selection) 00136 { 00137 case 1: 00138 if(State->iGreenHandicap > 0) 00139 { 00140 PlaySound(SOUNDID_MENUSELECT); 00141 backZ = -2; 00142 State->iGreenHandicap -= 5; 00143 } 00144 break; 00145 00146 case 2: 00147 if(State->iBrownHandicap > 0) 00148 { 00149 PlaySound(SOUNDID_MENUSELECT); 00150 backZ = -2; 00151 State->iBrownHandicap -= 5; 00152 } 00153 break; 00154 00155 case 3: 00156 if(State->iCurrentLevel > 1) 00157 { 00158 PlaySound(SOUNDID_MENUSELECT); 00159 backZ = -2; 00160 State->iCurrentLevel--; 00161 } 00162 break; 00163 00164 case 4: 00165 PlaySound(SOUNDID_MENUSELECT); 00166 backZ = -2; 00167 State->bAutoAdvanceLevel = !State->bAutoAdvanceLevel; 00168 break; 00169 00170 case 5: 00171 if(State->iSFXLevel > 0) 00172 { 00173 PlaySound(SOUNDID_MENUSELECT); 00174 backZ = -2; 00175 State->iSFXLevel -= 5; 00176 SetSFXVolume(State->iSFXLevel); 00177 } 00178 break; 00179 00180 case 6: 00181 if(State->iBGMLevel > 0) 00182 { 00183 PlaySound(SOUNDID_MENUSELECT); 00184 backZ = -2; 00185 State->iBGMLevel -= 5; 00186 SetBGMVolume(State->iBGMLevel); 00187 } 00188 break; 00189 00190 case 7: 00191 if(State->iGreenPlayerJoystick > -1) 00192 { 00193 PlaySound(SOUNDID_MENUSELECT); 00194 State->iGreenPlayerJoystick--; 00195 } 00196 break; 00197 00198 case 8: 00199 if(State->iBrownPlayerJoystick > -1) 00200 { 00201 PlaySound(SOUNDID_MENUSELECT); 00202 State->iBrownPlayerJoystick--; 00203 } 00204 break; 00205 00206 case 9: 00207 PlaySound(SOUNDID_MENUSELECT); 00208 backZ = -2; 00209 ToggleFullScreen(State); 00210 break; 00211 } 00212 } 00213 break; 00214 00215 case MENUINPUT_RIGHT: // modify current menu selection item 00216 if((selection >= 1) && (selection <= menuItemCount - 1)) 00217 { 00218 switch(selection) 00219 { 00220 case 1: 00221 if(State->iGreenHandicap < 95) 00222 { 00223 PlaySound(SOUNDID_MENUSELECT); 00224 backZ = -2; 00225 State->iGreenHandicap += 5; 00226 } 00227 break; 00228 00229 case 2: 00230 if(State->iBrownHandicap < 95) 00231 { 00232 PlaySound(SOUNDID_MENUSELECT); 00233 backZ = -2; 00234 State->iBrownHandicap +=5; 00235 } 00236 break; 00237 00238 case 3: 00239 if(State->iCurrentLevel < State->iMaxLevel) 00240 { 00241 PlaySound(SOUNDID_MENUSELECT); 00242 backZ = -2; 00243 State->iCurrentLevel++; 00244 } 00245 break; 00246 00247 case 4: 00248 PlaySound(SOUNDID_MENUSELECT); 00249 backZ = -2; 00250 State->bAutoAdvanceLevel = !State->bAutoAdvanceLevel; 00251 break; 00252 00253 case 5: 00254 if(State->iSFXLevel < 100) 00255 { 00256 PlaySound(SOUNDID_MENUSELECT); 00257 backZ = -2; 00258 State->iSFXLevel += 5; 00259 SetSFXVolume(State->iSFXLevel); 00260 } 00261 break; 00262 00263 case 6: 00264 if(State->iBGMLevel < 100) 00265 { 00266 PlaySound(SOUNDID_MENUSELECT); 00267 backZ = -2; 00268 State->iBGMLevel += 5; 00269 SetBGMVolume(State->iBGMLevel); 00270 } 00271 break; 00272 00273 case 7: 00274 if(State->iGreenPlayerJoystick < State->iTotalJoysticks - 1) 00275 { 00276 PlaySound(SOUNDID_MENUSELECT); 00277 State->iGreenPlayerJoystick++; 00278 00279 } 00280 break; 00281 00282 case 8: 00283 if(State->iBrownPlayerJoystick < State->iTotalJoysticks - 1) 00284 { 00285 PlaySound(SOUNDID_MENUSELECT); 00286 State->iBrownPlayerJoystick++; 00287 } 00288 break; 00289 00290 case 9: 00291 PlaySound(SOUNDID_MENUSELECT); 00292 backZ = -2; 00293 ToggleFullScreen(State); 00294 break; 00295 } 00296 } 00297 break; 00298 00299 case MENUINPUT_SELECT: // select current menu item 00300 if(selection == 10) 00301 { 00302 backZ = -2; 00303 PlaySound(SOUNDID_MENUSELECT); 00304 return selection; 00305 } 00306 break; 00307 00308 case MENUINPUT_ESCAPE: // select current menu item 00309 backZ = -2; 00310 PlaySound(SOUNDID_MENUSELECT); 00311 return selection; 00312 break; 00313 } 00314 00315 // draw the menu background 00316 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 00317 00318 DrawMenuBackground(1.5,-1.8,-2.3,2.3); 00319 00320 // draw the options menu 00321 graphics->_beginDraw(); 00322 graphics->setFont(font); 00323 graphics->drawText("options",SCREEN_WIDTH/2,150,gcn::Graphics::CENTER); 00324 00326 graphics->drawText("green tank handicap",SCREEN_WIDTH/2 - 360,200,gcn::Graphics::LEFT); 00327 if(selection == 1) 00328 { 00329 sprintf_s(optionItem, ">%d<", State->iGreenHandicap); 00330 } 00331 else 00332 { 00333 sprintf_s(optionItem, "%d ", State->iGreenHandicap); 00334 } 00335 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 200, gcn::Graphics::RIGHT); 00336 00338 graphics->drawText("brown tank handicap", SCREEN_WIDTH/2 - 360, 250, gcn::Graphics::LEFT); 00339 if(selection == 2) 00340 { 00341 sprintf_s(optionItem, ">%d<", State->iBrownHandicap); 00342 } 00343 else 00344 { 00345 sprintf_s(optionItem, "%d ", State->iBrownHandicap); 00346 } 00347 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 250, gcn::Graphics::RIGHT); 00348 00350 graphics->drawText("level", SCREEN_WIDTH/2 - 360,300, gcn::Graphics::LEFT); 00351 if(selection == 3) 00352 { 00353 sprintf_s(optionItem, ">%d<", State->iCurrentLevel); 00354 } 00355 else 00356 { 00357 sprintf_s(optionItem, "%d ", State->iCurrentLevel); 00358 } 00359 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 300, gcn::Graphics::RIGHT); 00360 00362 graphics->drawText("auto advance level", SCREEN_WIDTH/2 - 360, 350, gcn::Graphics::LEFT); 00363 if(selection == 4) 00364 { 00365 if(State->bAutoAdvanceLevel) 00366 { 00367 graphics->drawText(">yes<", SCREEN_WIDTH/2 + 370, 350, gcn::Graphics::RIGHT); 00368 } 00369 else 00370 { 00371 graphics->drawText(">no<", SCREEN_WIDTH/2 + 370, 350, gcn::Graphics::RIGHT); 00372 } 00373 } 00374 else 00375 { 00376 if(State->bAutoAdvanceLevel) 00377 { 00378 graphics->drawText("yes ", SCREEN_WIDTH/2 + 370, 350, gcn::Graphics::RIGHT); 00379 } 00380 else 00381 { 00382 graphics->drawText("no ", SCREEN_WIDTH/2 + 370, 350, gcn::Graphics::RIGHT); 00383 } 00384 } 00385 00387 graphics->drawText("sound fx volume", SCREEN_WIDTH/2 - 360, 400, gcn::Graphics::LEFT); 00388 if(selection == 5) 00389 { 00390 sprintf_s(optionItem, ">%d<", State->iSFXLevel); 00391 } 00392 else 00393 { 00394 sprintf_s(optionItem, "%d ", State->iSFXLevel); 00395 } 00396 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 400, gcn::Graphics::RIGHT); 00397 00399 graphics->drawText("bgm volume", SCREEN_WIDTH/2 - 360, 450, gcn::Graphics::LEFT); 00400 if(selection == 6) 00401 { 00402 sprintf_s(optionItem, ">%d<", State->iBGMLevel); 00403 } 00404 else 00405 { 00406 sprintf_s(optionItem, "%d ", State->iBGMLevel); 00407 } 00408 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 450, gcn::Graphics::RIGHT); 00409 00411 graphics->drawText("p1 stick:", SCREEN_WIDTH/2 - 360, 500, gcn::Graphics::LEFT); 00412 if(selection == 7) 00413 { 00414 if(State->iGreenPlayerJoystick == -1) 00415 { 00416 sprintf_s(optionItem, ">off (%d available)<", SDL_NumJoysticks()); 00417 //sprintf_s(optionItem, ">none<"); 00418 } 00419 else 00420 { 00421 sprintf_s(optionItem, ">%s<", State->cJoystickNames[State->iGreenPlayerJoystick]); 00422 } 00423 } 00424 else 00425 { 00426 if(State->iGreenPlayerJoystick == -1) 00427 { 00428 sprintf_s(optionItem, "off (%d available) ", SDL_NumJoysticks()); 00429 //sprintf_s(optionItem, "none"); 00430 } 00431 else 00432 { 00433 sprintf_s(optionItem, "%s ", State->cJoystickNames[State->iGreenPlayerJoystick]); 00434 } 00435 } 00436 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 500, gcn::Graphics::RIGHT); 00437 00439 graphics->drawText("p2 stick:", SCREEN_WIDTH/2 - 360, 550, gcn::Graphics::LEFT); 00440 if(selection == 8) 00441 { 00442 if(State->iBrownPlayerJoystick == -1) 00443 { 00444 sprintf_s(optionItem, ">off (%d available)<", SDL_NumJoysticks()); 00445 //sprintf_s(optionItem, ">none<"); 00446 } 00447 else 00448 { 00449 sprintf_s(optionItem, ">%s<", State->cJoystickNames[State->iBrownPlayerJoystick]); 00450 } 00451 } 00452 else 00453 { 00454 if(State->iBrownPlayerJoystick == -1) 00455 { 00456 sprintf_s(optionItem, "off (%d available) ", SDL_NumJoysticks()); 00457 //sprintf_s(optionItem, "none"); 00458 } 00459 else 00460 { 00461 sprintf_s(optionItem, "%s ", State->cJoystickNames[State->iBrownPlayerJoystick]); 00462 } 00463 } 00464 graphics->drawText(optionItem, SCREEN_WIDTH/2 + 370, 550, gcn::Graphics::RIGHT); 00465 00467 graphics->drawText("run fullscreen",SCREEN_WIDTH/2 - 360,600,gcn::Graphics::LEFT); 00468 if(selection == 9) 00469 { 00470 if(State->bFullScreen) 00471 { 00472 graphics->drawText(">yes<", SCREEN_WIDTH/2 + 370, 600, gcn::Graphics::RIGHT); 00473 } 00474 else 00475 { 00476 graphics->drawText(">no<", SCREEN_WIDTH/2 + 370, 600, gcn::Graphics::RIGHT); 00477 } 00478 } 00479 else 00480 { 00481 if(State->bFullScreen) 00482 { 00483 graphics->drawText("yes ", SCREEN_WIDTH/2 + 370, 600, gcn::Graphics::RIGHT); 00484 } 00485 else 00486 { 00487 graphics->drawText("no ", SCREEN_WIDTH/2 + 370, 600, gcn::Graphics::RIGHT); 00488 } 00489 } 00490 00492 graphics->drawText("back", SCREEN_WIDTH/2, 650, gcn::Graphics::CENTER); 00493 if(selection == 10) 00494 { 00495 graphics->drawText(">", SCREEN_WIDTH/2-56, 650, gcn::Graphics::CENTER); 00496 graphics->drawText("<", SCREEN_WIDTH/2+56, 650, gcn::Graphics::CENTER); 00497 } 00498 00499 graphics->_endDraw(); 00500 00501 // swap buffers to display 00502 SDL_GL_SwapBuffers(); 00503 } 00504 return 0; 00505 } 00506 00507 00514 int HighScoreMenu(gcn::OpenGLGraphics* graphics, gcn::ImageFont* font) 00515 { 00516 static char string[256]; 00517 00518 int menuInput; 00519 int selection = 1; // player's selection from the menu 00520 int menuItemCount = 1; 00521 int iX=0; 00522 00523 glEnable(GL_TEXTURE_2D); 00524 00525 LoadHighScores(); // load latest high score data in to memory 00526 00527 while(1) 00528 { 00529 menuInput = GetMenuInput(); 00530 00531 switch(menuInput) 00532 { 00533 case MENUINPUT_ESCAPE: // up one menu item 00534 PlaySound(SOUNDID_MENUSELECT); 00535 return 0; 00536 break; 00537 } 00538 00539 // draw the menu background 00540 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 00541 00542 DrawMenuBackground(1.2,-1.4,-1,1); 00543 00544 // draw the main menu 00545 graphics->_beginDraw(); 00546 graphics->setFont(font); 00547 graphics->drawText("high scores",SCREEN_WIDTH/2,200,gcn::Graphics::CENTER); 00548 00549 for (iX=0; iX<10; iX++) 00550 { 00551 sprintf_s(string, "%d.", iX+1); 00552 graphics->drawText(string,SCREEN_WIDTH/2-90,300+iX*30,gcn::Graphics::RIGHT); 00553 sprintf_s(string, "%s %d", &initials[iX*4], scores[iX]); 00554 graphics->drawText(string,SCREEN_WIDTH/2-70,300+iX*30,gcn::Graphics::LEFT); 00555 } 00556 graphics->_endDraw(); 00557 00558 // swap buffers to display 00559 SDL_GL_SwapBuffers(); 00560 } 00561 00562 return 0; 00563 } 00564 00565 00575 void DrawMenuBackground(GLfloat top, GLfloat bottom, GLfloat left, GLfloat right) 00576 { 00577 int iX, iY; 00578 float tickDelta = 0; 00579 00580 glLoadIdentity(); // Reset The View 00581 00582 backAngle += backAccel; 00583 backAccel *= .995; 00584 backZ *= .999; 00585 00586 glColor3f(1,1,1); 00587 00588 glBindTexture( GL_TEXTURE_2D, GetTexture(TEXID_MENUBACK)); 00589 00590 // draw background tiles 00591 glPushMatrix(); 00592 glRotatef(backAngle,0,0,1); 00593 glTranslatef(-16.0f,-16.0f,-20.0f); 00594 for(iY=0; iY<8; iY++) 00595 { 00596 for(iX=0; iX<8; iX++) 00597 { 00598 glPushMatrix(); 00599 glTranslatef(iX*4, iY*4, 0); 00600 glBegin(GL_QUADS); // start drawing a polygon (4 sided) 00601 glTexCoord2d(0.0,0.0); glVertex3f(0, 4, backDropZ[iY*9+iX]+backZ); // Top Left 00602 glTexCoord2d(1.0,0.0); glVertex3f(4, 4, backDropZ[iY*9+iX+1]+backZ); // Top Right 00603 glTexCoord2d(1.0,1.0); glVertex3f(4, 0, backDropZ[iY*8+iX+1]+backZ); // Bottom Right 00604 glTexCoord2d(0.0,1.0); glVertex3f(0, 0, backDropZ[iY*8+iX]+backZ); // Bottom Left 00605 glEnd(); // done with the polygon 00606 glPopMatrix(); 00607 } 00608 } 00609 glPopMatrix(); 00610 00611 // update the background vertices 00612 tickDelta = 0; 00613 for(iY=0; iY<9; iY++) 00614 { 00615 for(iX=0; iX<9; iX++) 00616 { 00617 backDropZ[iX*8+iY] = cos(ticks+tickDelta); 00618 tickDelta+=.1; 00619 ticks+=.00001; 00620 } 00621 } 00622 00623 // draw a shadow for the menu text 00624 glDisable(GL_TEXTURE_2D); 00625 glEnable(GL_BLEND); 00626 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00627 glColor4f(0,0,0,.4); 00628 glBegin(GL_QUADS); // start drawing a polygon (4 sided) 00629 glVertex3f(left,top, -5); // Top Left 00630 glVertex3f(right,top, -5); // Top Right 00631 glVertex3f(right,bottom, -5); // Bottom Right 00632 glVertex3f(left,bottom, -5); // Bottom Left 00633 glEnd(); // done with the polygon 00634 glEnable(GL_TEXTURE_2D); 00635 glDisable(GL_BLEND); 00636 } 00637 00638 00645 int SaveHighScores(void) 00646 { 00647 FILE * file; // credits file 00648 int iX, iY; // index vars 00649 char string[256]; 00650 int charsWritten; 00651 char newline = 10; 00652 00653 fopen_s(&file, "dat\\highscore", "w" ); // open the credits file 00654 if (file == NULL) return DAS_ERROR; 00655 00656 for(iY=0; iY<10; iY++) // for each score 00657 { 00658 // write the name 00659 fwrite(&initials[iY*4+0], 1, 1, file); 00660 fwrite(&initials[iY*4+1], 1, 1, file); 00661 fwrite(&initials[iY*4+2], 1, 1, file); 00662 00663 iX = 0; 00664 00665 // convert score integer to string and write 00666 _itoa_s(scores[iY], string, 10); 00667 fwrite(string, strlen(string), 1, file); 00668 fwrite(&newline, 1, 1, file); 00669 } 00670 00671 fclose(file); 00672 00673 return 0; 00674 } 00675 00676 00682 int LoadHighScores(void) 00683 { 00684 FILE * file; // credits file 00685 int iX, iY; // index vars 00686 char string[256]; 00687 int charsRead; 00688 char currentChar = 0; 00689 00690 fopen_s(&file, "dat\\highscore", "r" ); // open the credits file 00691 if (file == NULL) return DAS_ERROR; 00692 00693 for(iY=0; iY<10; iY++) // for each score 00694 { 00695 // read the name 00696 fread(&initials[iY*4+0], 1, 1, file); 00697 fread(&initials[iY*4+1], 1, 1, file); 00698 fread(&initials[iY*4+2], 1, 1, file); 00699 initials[iY*4+3]=0; // null terminator 00700 00701 iX = 0; 00702 00703 while(1) //read the score text 00704 { 00705 charsRead = fread(¤tChar, 1, 1, file); 00706 00707 if(currentChar == 10) // newline 00708 { 00709 string[iX] = 0; 00710 break; 00711 } 00712 else 00713 { 00714 string[iX] = currentChar; 00715 iX++; 00716 } 00717 } 00718 00719 scores[iY] = atoi(string); 00720 } 00721 00722 fclose(file); 00723 00724 return 0; 00725 } 00726 00727 00737 int HighScore(int score, const char * name) 00738 { 00739 int iX = 0; 00740 int iY = 0; 00741 00742 if(score < scores[9]) return DAS_ERROR; // wasn't so high after all 00743 00744 while(score < scores[iX]) // skip until finding our insertion point 00745 { 00746 iX++; 00747 } 00748 00749 // move others down (losing previous 10th place score)... 00750 for(iY=8; iY>=iX; iY--) 00751 { 00752 scores[iY+1] = scores[iY]; 00753 initials[(iY+1)*4+0] = initials[(iY)*4+0]; 00754 initials[(iY+1)*4+1] = initials[(iY)*4+1]; 00755 initials[(iY+1)*4+2] = initials[(iY)*4+2]; 00756 initials[(iY+1)*4+3] = initials[(iY)*4+3]; 00757 } 00758 // and 'new' spot with current score 00759 scores[iX] = score; 00760 00761 // make sure initials are lowercase when we store them 00762 initials[(iX)*4+0] = tolower(name[0]); 00763 initials[(iX)*4+1] = tolower(name[1]); 00764 initials[(iX)*4+2] = tolower(name[2]); 00765 initials[(iX)*4+3] = 0; 00766 00767 return 0; 00768 } 00769 00770 00778 int GetMenuInput(void) 00779 { 00780 SDL_Event event; 00781 00782 while(SDL_PollEvent(&event)) // process all events (input from players) 00783 { 00784 switch(event.type) 00785 { 00786 case SDL_KEYDOWN: 00787 switch(event.key.keysym.sym) 00788 { 00789 case SDLK_UP: 00790 return MENUINPUT_UP; 00791 break; 00792 00793 case SDLK_DOWN: 00794 return MENUINPUT_DOWN; 00795 break; 00796 00797 case SDLK_LEFT: 00798 return MENUINPUT_LEFT; 00799 break; 00800 00801 case SDLK_RIGHT: 00802 return MENUINPUT_RIGHT; 00803 break; 00804 00805 case SDLK_RETURN: 00806 return MENUINPUT_SELECT; 00807 break; 00808 00809 case SDLK_ESCAPE: 00810 return MENUINPUT_ESCAPE; 00811 break; 00812 } 00813 00814 case SDL_JOYHATMOTION: 00815 if(event.jhat.value & SDL_HAT_UP) return MENUINPUT_UP; 00816 if(event.jhat.value & SDL_HAT_DOWN) return MENUINPUT_DOWN; 00817 if(event.jhat.value & SDL_HAT_LEFT) return MENUINPUT_LEFT; 00818 if(event.jhat.value & SDL_HAT_RIGHT) return MENUINPUT_RIGHT; 00819 break; 00820 00821 case SDL_JOYBUTTONDOWN: 00822 if(event.jbutton.button == 0) return MENUINPUT_SELECT; 00823 if(event.jbutton.button == 1) return MENUINPUT_ESCAPE; 00824 break; 00825 } 00826 } 00827 return MENUINPUT_NULL; 00828 }
Copyright Windsor Schmidt 2006 - All rights reserved.