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 00038 int Credits(gcn::OpenGLGraphics* graphics, gcn::ImageFont* font) 00039 { 00040 Uint32 oldTime; 00041 Uint32 currentTime; 00042 Uint32 timeDelta; 00043 00044 oldTime = 0; 00045 currentTime = SDL_GetTicks(); 00046 00047 glDisable(GL_TEXTURE_2D); 00048 glClearColor(0.2,0.2,0.2,0); 00049 00050 int menuInput; 00051 00052 char page_A[PAGE_WIDTH*PAGE_HEIGHT]; // memory for page buffers 00053 char page_B[PAGE_WIDTH*PAGE_HEIGHT]; 00054 00055 float a_pos = 0; // keep track of page buffers' position on-screen 00056 float b_pos = SCREEN_HEIGHT; 00057 00058 FILE * file; // credits file 00059 int iX, iY; // index vars 00060 int lineHeight = SCREEN_HEIGHT/PAGE_HEIGHT; 00061 int screenMiddle = SCREEN_WIDTH/2; 00062 00063 float boxAX = 0; 00064 float boxAY = 0; 00065 float boxAZ = 10; 00066 float boxBX = 0; 00067 float boxBY = 0; 00068 float boxBZ = 10; 00069 float boxCX = 0; 00070 float boxCY = 0; 00071 float boxCZ = 10; 00072 00073 float camX = 0; 00074 float camY = 0; 00075 float camZ = 0; 00076 00077 float lookX = 10; 00078 float lookY = 10; 00079 float lookZ = 10; 00080 00081 int boxNext = 0; 00082 int boxNextOld = 0; 00083 00084 int boxRand; 00085 00086 int boxTimer = 600; 00087 00088 float angle = 0; 00089 00090 fopen_s(&file, "dat\\credits", "r" ); // open the credits file 00091 if (file == NULL) return DAS_ERROR; 00092 00093 graphics->setFont(font); 00094 00095 creditsReadPage(file, page_A); // load up the initial page buffers with text 00096 creditsReadPage(file, page_B); 00097 00098 // per-frame loop starts here 00099 while(1) 00100 { 00101 menuInput = GetMenuInput(); 00102 00103 switch(menuInput) 00104 { 00105 case MENUINPUT_ESCAPE: // exit credit screen 00106 fclose(file); 00107 PlaySound(SOUNDID_MENUSELECT); 00108 return 0; 00109 break; 00110 } 00111 00112 // draw background graphics 00113 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer 00114 00115 glLoadIdentity(); // Reset The View 00116 00117 gluLookAt(camX,camY,camZ,lookX,lookY,lookZ,0,1,0); 00118 00119 glColor4f(0.35,0.30,0.15,1.0); // army brown 00120 00121 glPushMatrix(); 00122 glTranslatef(0,0,10); 00123 glScalef(30,30,30); 00124 glutWireDodecahedron(); 00125 glPopMatrix(); 00126 00127 if(boxAX<camX)camX-=.002; 00128 if(boxAX>camX)camX+=.002; 00129 if(boxAY<camY)camY-=.002; 00130 if(boxAY>camY)camY+=.002; 00131 if(boxAZ<camZ)camZ-=.002; 00132 if(boxAZ>camZ)camZ+=.002; 00133 00134 if(boxCX<lookX)lookX-=.002; 00135 if(boxCX>lookX)lookX+=.002; 00136 if(boxCY<lookY)lookY-=.002; 00137 if(boxCY>lookY)lookY+=.002; 00138 if(boxCZ<lookZ)lookZ-=.002; 00139 if(boxCZ>lookZ)lookZ+=.002; 00140 00141 glColor3f(0.30,0.35,0.21); // army green 00142 00143 glPushMatrix(); 00144 glTranslatef(boxAX,boxAY,boxAZ); 00145 glutWireCube(1); 00146 glPopMatrix(); 00147 00148 glPushMatrix(); 00149 glTranslatef(boxBX,boxBY,boxBZ); 00150 glutWireCube(1); 00151 glPopMatrix(); 00152 00153 glPushMatrix(); 00154 glTranslatef(boxCX,boxCY,boxCZ); 00155 glutWireCube(1); 00156 glPopMatrix(); 00157 00158 switch(boxNextOld) // draw oldstick 00159 { 00160 case 0: 00161 glPushMatrix(); 00162 glTranslatef(boxCX,boxCY-1,boxCZ); 00163 glScalef(.2,1,.2); 00164 glutWireCube(1); 00165 glPopMatrix(); 00166 break; 00167 case 1: 00168 glPushMatrix(); 00169 glTranslatef(boxCX,boxCY+1,boxCZ); 00170 glScalef(.2,1,.2); 00171 glutWireCube(1); 00172 glPopMatrix(); 00173 break; 00174 case 2: 00175 glPushMatrix(); 00176 glTranslatef(boxCX+1,boxCY,boxCZ); 00177 glScalef(1,.2,.2); 00178 glutWireCube(1); 00179 glPopMatrix(); 00180 break; 00181 case 3: 00182 glPushMatrix(); 00183 glTranslatef(boxCX-1,boxCY,boxCZ); 00184 glScalef(1,.2,.2); 00185 glutWireCube(1); 00186 glPopMatrix(); 00187 break; 00188 case 4: 00189 glPushMatrix(); 00190 glTranslatef(boxCX,boxCY,boxCZ-1); 00191 glScalef(.2,.2,1); 00192 glutWireCube(1); 00193 glPopMatrix(); 00194 break; 00195 case 5: 00196 glPushMatrix(); 00197 glTranslatef(boxCX,boxCY,boxCZ+1); 00198 glScalef(.2,.2,1); 00199 glutWireCube(1); 00200 glPopMatrix(); 00201 break; 00202 } 00203 00204 if(boxTimer<300) // draw new stick 00205 { 00206 switch(boxNext) 00207 { 00208 case 0: 00209 glPushMatrix(); 00210 glTranslatef(boxCX,boxCY+1,boxCZ); 00211 glScalef(.2,1,.2); 00212 glutWireCube(1); 00213 glPopMatrix(); 00214 break; 00215 case 1: 00216 glPushMatrix(); 00217 glTranslatef(boxCX,boxCY-1,boxCZ); 00218 glScalef(.2,1,.2); 00219 glutWireCube(1); 00220 glPopMatrix(); 00221 break; 00222 case 2: 00223 glPushMatrix(); 00224 glTranslatef(boxCX-1,boxCY,boxCZ); 00225 glScalef(1,.2,.2); 00226 glutWireCube(1); 00227 glPopMatrix(); 00228 break; 00229 case 3: 00230 glPushMatrix(); 00231 glTranslatef(boxCX+1,boxCY,boxCZ); 00232 glScalef(1,.2,.2); 00233 glutWireCube(1); 00234 glPopMatrix(); 00235 break; 00236 case 4: 00237 glPushMatrix(); 00238 glTranslatef(boxCX,boxCY,boxCZ+1); 00239 glScalef(.2,.2,1); 00240 glutWireCube(1); 00241 glPopMatrix(); 00242 break; 00243 case 5: 00244 glPushMatrix(); 00245 glTranslatef(boxCX,boxCY,boxCZ-1); 00246 glScalef(.2,.2,1); 00247 glutWireCube(1); 00248 glPopMatrix(); 00249 break; 00250 } 00251 00252 } 00253 00254 00255 boxTimer--; // tick timer 00256 if(boxTimer<0) // if timer has expired 00257 { 00258 boxTimer = 600; // reset timer 00259 00260 boxAX = boxBX; 00261 boxAY = boxBY; 00262 boxAZ = boxBZ; 00263 00264 boxBX = boxCX; 00265 boxBY = boxCY; 00266 boxBZ = boxCZ; 00267 00268 switch(boxNext) 00269 { 00270 case 0: 00271 boxCY+=2; 00272 break; 00273 case 1: 00274 boxCY-=2; 00275 break; 00276 case 2: 00277 boxCX-=2; 00278 break; 00279 case 3: 00280 boxCX+=2; 00281 break; 00282 case 4: 00283 boxCZ+=2; 00284 break; 00285 case 5: 00286 boxCZ-=2; 00287 break; 00288 } 00289 00290 boxNextOld=boxNext; 00291 00292 while (5 <= (boxRand = rand() / (RAND_MAX/5))); 00293 if (boxRand != boxNext) boxNext = boxRand; 00294 00295 } 00296 00297 // update / draw credits text 00298 00299 // recycle text pages, moving to the bottom of the screen and loading on new text 00300 if(a_pos < SCREEN_HEIGHT * -1) 00301 { 00302 creditsReadPage(file, page_A); 00303 a_pos = SCREEN_HEIGHT; 00304 } 00305 00306 if(b_pos < SCREEN_HEIGHT * -1) 00307 { 00308 creditsReadPage(file, page_B); 00309 b_pos = SCREEN_HEIGHT; 00310 } 00311 00312 graphics->_beginDraw(); 00313 00314 // draw page A 00315 for(iY=0; iY<PAGE_HEIGHT; iY++) 00316 { 00317 graphics->drawText(&page_A[iY*PAGE_WIDTH],screenMiddle,a_pos+iY*(lineHeight),gcn::Graphics::CENTER); 00318 } 00319 00320 // draw page B 00321 for(iY=0; iY<PAGE_HEIGHT; iY++) 00322 { 00323 graphics->drawText(&page_B[iY*PAGE_WIDTH],screenMiddle,b_pos+iY*(lineHeight),gcn::Graphics::CENTER); 00324 } 00325 00326 // scroll both text pages up a bit 00327 oldTime = currentTime; 00328 currentTime = SDL_GetTicks(); 00329 timeDelta = currentTime - oldTime; 00330 00331 a_pos-=timeDelta * 0.06; 00332 b_pos-=timeDelta * 0.06; 00333 00334 graphics->_endDraw(); 00335 00336 // swap buffers to display 00337 SDL_GL_SwapBuffers(); 00338 } 00339 00340 fclose(file); // close credits file 00341 return 0; 00342 } 00343 00344 00353 int creditsReadPage(FILE * file, char * page) 00354 { 00355 char currentChar; 00356 int charsRead; 00357 int iX, iY; // index vars 00358 00359 for(iY=0; iY < PAGE_HEIGHT; iY++) // read in a page, line by line 00360 { 00361 for(iX=0; iX < PAGE_WIDTH; iX++) // read in a line 00362 { 00363 charsRead = fread(¤tChar, 1, 1, file); 00364 if(charsRead < 1) 00365 { 00366 fseek(file, 0, SEEK_SET); // loop to beginning if at the end of file 00367 charsRead = fread(¤tChar, 1, 1, file); 00368 if(charsRead < 1) return DAS_ERROR; // couldn't read from file? return error 00369 } 00370 00371 if(currentChar == 10) // newline 00372 { 00373 00374 page[iX+iY*PAGE_WIDTH] = 0; // set null char at the end of this line 00375 iX = PAGE_WIDTH; // move to end of line to start new line next loop iteration 00376 } 00377 else 00378 { 00379 page[iX+iY*PAGE_WIDTH] = currentChar; // add current char to page buffer 00380 } 00381 } 00382 } 00383 return 0; 00384 } 00385 00386 00394 int boxOpposite(int boxDir) 00395 { 00396 switch(boxDir) 00397 { 00398 case 0: 00399 return 1; 00400 break; 00401 case 1: 00402 return 0; 00403 break; 00404 case 2: 00405 return 3; 00406 break; 00407 case 3: 00408 return 2; 00409 break; 00410 case 4: 00411 return 5; 00412 break; 00413 case 5: 00414 return 4; 00415 break; 00416 } 00417 return 0; 00418 }
Copyright Windsor Schmidt 2006 - All rights reserved.