home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 November / Chip_2002-11_cd1.bin / oddech / orbital / orbital.exe / src / gameover.cpp < prev    next >
C/C++ Source or Header  |  2002-07-15  |  5KB  |  143 lines

  1. ///////////////////////////////////////////////
  2. // 
  3. //  Snipe2d ludum dare 48h compo entry
  4. //
  5. //  Jari Komppa aka Sol 
  6. //  http://iki.fi/sol
  7. // 
  8. ///////////////////////////////////////////////
  9. // License
  10. ///////////////////////////////////////////////
  11. // 
  12. //     This software is provided 'as-is', without any express or implied
  13. //     warranty.    In no event will the authors be held liable for any damages
  14. //     arising from the use of this software.
  15. // 
  16. //     Permission is granted to anyone to use this software for any purpose,
  17. //     including commercial applications, and to alter it and redistribute it
  18. //     freely, subject to the following restrictions:
  19. // 
  20. //     1. The origin of this software must not be misrepresented; you must not
  21. //        claim that you wrote the original software. If you use this software
  22. //        in a product, an acknowledgment in the product documentation would be
  23. //        appreciated but is not required.
  24. //     2. Altered source versions must be plainly marked as such, and must not be
  25. //        misrepresented as being the original software.
  26. //     3. This notice may not be removed or altered from any source distribution.
  27. // 
  28. // (eg. same as ZLIB license)
  29. //
  30. ///////////////////////////////////////////////
  31. //
  32. // Houses are taken from a satellite picture of glasgow.
  33. //
  34. // The sources are a mess, as I didn't even try to do anything
  35. // really organized here.. and hey, it's a 48h compo =)
  36. //
  37. #include "snipe2d.h"
  38.  
  39. void fillrect(int x1, int y1, int x2, int y2, int color)
  40. {
  41.     SDL_Rect r;
  42.     r.x = x1;
  43.     r.y = y1;
  44.     r.w = x2-x1;
  45.     r.h = y2-y1;
  46.     int sdlcolor = SDL_MapRGB(gScreen->format, 
  47.                               (color >> 16) & 0xff,
  48.                               (color >> 8) & 0xff,
  49.                               (color >> 0) & 0xff);
  50.     SDL_FillRect(gScreen, &r, sdlcolor);
  51. }
  52.  
  53. void gameoverscreen(int aReason)
  54. {
  55.     gGameState = 0;
  56.     fillrect(0,0,640,480,0);
  57.     fillrect(159,59,461,421,0x007f00);
  58.     fillrect(160,60,460,420,0x003f00);
  59.     fillrect(159,80,461,81,0x007f00);
  60.     print(290, 68, COLOR_GREEN, "game over");
  61.     print(260 + 8, 400, COLOR_GREEN, "click to play again");
  62.     print(260 + 12, 412, COLOR_GREEN, "press ESC to quit");
  63.     int row = 88 + 40;
  64.     switch (aReason)
  65.     {
  66.     case 0:
  67.         printShadow(240, row, "You left your post!"); row += 8;
  68.         break;
  69.     case 1:
  70.         printShadow(240, row, "You shot a VIP!"); row += 8;
  71.         break;
  72.     case 2:
  73.         printShadow(240, row, "You let a VIP die!"); row += 8;
  74.         break;
  75.     }
  76.     row += 8;
  77.     printShadow(240, row, "The VIP protection bureau has found your "); row += 8;
  78.     printShadow(240, row, "actions unacceptable, and thus has decided"); row += 8;
  79.     printShadow(240, row, "to let you go."); row += 8;
  80.     row += 8;
  81.     print(240, row, (gScore<=0)?COLOR_RED:COLOR_GREEN, "Your final score was: %d", gScore); row += 8;
  82.     row += 8;
  83.     row += 8;
  84.     row += 8;
  85.     printShadow(240, row, "Based on your score, your retirement will be:"); row += 8;
  86.     row += 8;
  87.     if (gScore < -10000)
  88.         printShadow(240, row, "Slow and extremely painful."); 
  89.     else
  90.     if (gScore < 0)
  91.         printShadow(240, row, "Quick and painless."); 
  92.     else
  93.     if (gScore < 25000)
  94.         printShadow(240, row, "Poor."); 
  95.     else
  96.     if (gScore < 50000)
  97.         printShadow(240, row, "Decent."); 
  98.     else
  99.     if (gScore < 100000)
  100.         printShadow(240, row, "Above average."); 
  101.     else
  102.         printShadow(240, row, "Welcome to heaven, baby!"); 
  103.     row += 8;
  104.     row += 8;
  105.     row += 8;
  106.     row += 8;
  107.     printShadow(240, row, "Stats:"); row += 8;
  108.     row += 8;
  109.     printShadow(240, row, "Threats neutralized:%4d", gBadGuisKilled); row += 8;
  110.     printShadow(240, row, "VIPs with safe trip:%4d", gVIPsGottenToSafety); row += 8;
  111.     printShadow(240, row, "Pedestrians wasted: %4d", gPedestriansKilled); row += 8;
  112.     printShadow(240, row, "Game time:         %02d:%02d", ((GetTickCount() - gGameStartTick) / 60000), ((GetTickCount() - gGameStartTick) / 1000)%60); row += 8;
  113.  
  114.  
  115.  
  116.  
  117.     int i = 0;
  118.     for (i = 0; i < 56; i++)
  119.         print(162, 83 + i * 6, COLOR_YELLOW, "%u%u", rand(), rand());
  120.     SDL_UpdateRect(gScreen, 0, 0, 640, 480);    
  121.     int go = 0;
  122.     int startTick = GetTickCount();
  123.     while (1)
  124.     {
  125.         SDL_Event event;
  126.         while ( SDL_PollEvent(&event) ) 
  127.         {
  128.             switch (event.type) 
  129.             {
  130.             case SDL_KEYUP:
  131.                 if (event.key.keysym.sym == SDLK_ESCAPE)
  132.                     exit(0);
  133.                 break;
  134.             case SDL_MOUSEBUTTONUP:
  135.                 if ((GetTickCount() - startTick) > 500)
  136.                     return;
  137.                 break;
  138.             case SDL_QUIT:
  139.                 exit(0);
  140.             }
  141.         }
  142.     }
  143. }