Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "titlescreen.h"
  2. #include "game.h"
  3. #include <stdio.h>
  4. #include "text.h"
  5.  
  6. int tempsave = 0;
  7. int cursor = 0;
  8.  
  9. void titleScreenSetup();
  10.  
  11. int titleScreenStep();
  12. void titleScreenDraw();
  13.  
  14. #ifdef EMSCRIPTEN
  15. int titleEMStep()
  16. {
  17.         PHL_MainLoop();
  18.         //Get input
  19.         PHL_ScanInput();
  20.        
  21.         //Titlescreen step
  22.         int result = titleScreenStep();
  23.        
  24.         //Draw titlescreen
  25.         PHL_StartDrawing();
  26.                
  27.         titleScreenDraw();
  28.  
  29.         if (result != -1)
  30.                 PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0));
  31.  
  32.         PHL_EndDrawing();              
  33.  
  34.         return result;
  35. }
  36. #endif
  37.  
  38. int titleScreen()
  39. {
  40.         titleScreenSetup();
  41.        
  42.         char loop = 1;
  43.         int result = -1;
  44.        
  45.         while (PHL_MainLoop() && loop == 1)
  46.         {
  47.                 //__asm__("int3");     
  48.                 //Get input
  49.                 PHL_ScanInput();
  50.                
  51.                 //Titlescreen step
  52.                 result = titleScreenStep();
  53.                
  54.                 //Draw titlescreen
  55.                 PHL_StartDrawing();
  56.                        
  57.                 titleScreenDraw();
  58.  
  59.                 if (result != -1) {
  60.                         loop = 0;
  61.                         //Force screen to black
  62.                         PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0));
  63.                 }
  64.                 PHL_EndDrawing();              
  65.         }
  66.        
  67.         return result; 
  68. }
  69.  
  70. void titleScreenSetup()
  71. {      
  72.         cursor = 0;
  73.        
  74.         //Move cursor if save file exists
  75.         if ( fileExists(savemap) ) {
  76.                 cursor = 1;
  77.         }      
  78.        
  79.         //Check if temp save file exists
  80.         tempsave = 0;
  81.         if ( fileExists(savename) ) {
  82.                 #ifndef EMSCRIPTEN
  83.                 tempsave = 1;
  84.                 #endif
  85.                 cursor = 1;            
  86.         }
  87. }
  88.  
  89. int titleScreenStep()
  90. {
  91.         //Move cursor
  92.         if (btnDown.pressed == 1 || btnSelect.pressed == 1) {
  93.                 cursor += 1;
  94.                 if (cursor > 3) {
  95.                         cursor = 0;
  96.                 }
  97.                 PHL_PlaySound(sounds[sndPi01], 1);
  98.         }
  99.        
  100.         if (btnUp.pressed == 1) {
  101.                 cursor -= 1;
  102.                 if (cursor < 0) {
  103.                         cursor = 3;
  104.                 }
  105.                 PHL_PlaySound(sounds[sndPi01], 1);
  106.         }
  107.        
  108.         //Selection
  109.         if (btnAccept.pressed == 1 || btnStart.pressed == 1) {
  110.                 PHL_PlaySound(sounds[sndOk], 1);
  111.                 return cursor;
  112.         }
  113.        
  114.         return -1;
  115. }
  116.  
  117. void titleScreenDraw()
  118. {
  119.         //Blackdrop
  120.         PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0));
  121.        
  122.         if (tempsave == 0) {
  123.                 //Title image
  124.                 PHL_DrawSurfacePart(168, 72, 0, 0, 304, 168, images[imgTitle01]);
  125.         }else{
  126.                 //Save error message
  127.                 drawTextCentered(saveError[0], 320, 80);
  128.                 drawTextCentered(saveError[1], 320, 80 + 50);
  129.                 drawTextCentered(saveError[2], 320, 80 + 96);
  130.         }
  131.        
  132.         //Cursor
  133.         PHL_DrawSurfacePart(228, 264 + (cursor * 32), 4, 176, 184, 32, images[imgTitle01]);
  134.        
  135.         //Text
  136.         PHL_DrawTextBold("NEW GAME", 256, 272, YELLOW);
  137.         PHL_DrawTextBold("LOAD GAME", 248, 304, YELLOW);
  138.         PHL_DrawTextBold("OPTIONS", 264, 336, YELLOW);
  139.         PHL_DrawTextBold("EXIT", 288, 368, YELLOW);
  140.         PHL_DrawTextBold("(C) 2011 E.HASHIMOTO", 160, 410, WHITE);
  141.         PHL_DrawTextBold("GPL2 PTITSEB", 224, 442, WHITE);
  142. }