Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "inventory.h"
  2. #include "PHL.h"
  3. #include "game.h"
  4. #include "text.h"
  5.  
  6. int cursorX = 0;
  7. int cursorY = 0;
  8.  
  9. #ifdef EMSCRIPTEN
  10. static char tempDark;
  11. void inventorySetup()
  12. {
  13.         tempDark = roomDarkness;
  14.         roomDarkness = 0;
  15.        
  16.         PHL_PlaySound(sounds[sndPi04], CHN_SOUND);
  17. }
  18. int inventoryEMStep()
  19. {
  20.         int result = -1;
  21.         PHL_MainLoop();
  22.  
  23.         PHL_StartDrawing();
  24.         PHL_ScanInput();
  25.        
  26.         if (inventoryStep() == 1) {
  27.                 result = 0;
  28.         }
  29.        
  30.         inventoryDraw();
  31.        
  32.         PHL_EndDrawing();
  33.        
  34.         if(!result)
  35.                 roomDarkness = tempDark;
  36.         return result;
  37. }
  38. #else
  39.  
  40. void inventory()
  41. {
  42.         char tempDark = roomDarkness;
  43.         roomDarkness = 0;
  44.        
  45.         char loop = 1;
  46.         PHL_PlaySound(sounds[sndPi04], CHN_SOUND);
  47.         while (PHL_MainLoop() && loop == 1)
  48.         {
  49.                 PHL_StartDrawing();
  50.                 PHL_ScanInput();
  51.                
  52.                 if (inventoryStep() == 1) {
  53.                         loop = 0;
  54.                 }
  55.                
  56.                 inventoryDraw();
  57.                
  58.                 PHL_EndDrawing();
  59.         }
  60.        
  61.         roomDarkness = tempDark;
  62. }
  63. #endif
  64. int inventoryStep()
  65. {              
  66.         secretCountdown();
  67.        
  68.         //Input
  69.         char playsnd = 0;
  70.        
  71.         if (btnRight.pressed - btnLeft.pressed != 0) {
  72.                 cursorX += btnRight.pressed - btnLeft.pressed;
  73.                 playsnd = 1;
  74.         }
  75.         if (btnDown.pressed - btnUp.pressed != 0) {
  76.                 cursorY += btnDown.pressed - btnUp.pressed;
  77.                 playsnd = 1;
  78.         }
  79.        
  80.         if (playsnd == 1) {
  81.                 PHL_PlaySound(sounds[sndPi01], CHN_SOUND);
  82.         }
  83.        
  84.         //Limit cursor
  85.         if (cursorX < 0) { cursorX = 6; }
  86.         if (cursorX > 6) { cursorX = 0; }
  87.         if (cursorY < 0) { cursorY = 3; }
  88.         if (cursorY > 3) { cursorY = 0; }
  89.  
  90.         if (btnStart.pressed == 1 || btnDecline.pressed == 1)
  91.         {              
  92.                 return 1;
  93.         }
  94.        
  95.         return 0;
  96. }
  97.  
  98. void inventoryDraw()
  99. {              
  100.         //Black background
  101.         PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0));
  102.        
  103.         //Labels
  104.         PHL_DrawTextBold("SUB WEAPON", 16, 16, YELLOW);
  105.         PHL_DrawTextBold("ITEM", 16, 96, YELLOW);
  106.         PHL_DrawTextBold("KEY", 16, 320, YELLOW);
  107.        
  108.         //Blue rectangles
  109.         int i, a, cx, cy;
  110.         //Weapons
  111.         for (i = 0; i < 5; i++) {
  112.                 PHL_DrawRect(18 + (48 * i), 34, 44, 44, PHL_NewRGB(255, 255, 255));
  113.                 PHL_DrawRect(20 + (48 * i), 36, 40, 40, PHL_NewRGB(119, 166, 219));
  114.                 if (hasWeapon[i] == 1) {
  115.                         cx = (i + 1) * 40;
  116.                 }else{
  117.                         cx = 0;
  118.                 }
  119.                 PHL_DrawSurfacePart(20 + (48 * i), 36, cx, 0, 40, 40, images[imgItems]);
  120.         }
  121.         //Items
  122.         int count = 0;
  123.         int imageOrder[28] = { 13, 17, 16, 15, 8, 10, 9,
  124.                                                    18, 4, 6, 5, 7, 3, 11,
  125.                                                    14, 12, 1, 2, 22, 26, 27,
  126.                                                    21, 25, 28, 23, 20, 19, 24 };
  127.                                            
  128.         for (i = 0; i <  4; i++) {
  129.                 for (a = 0; a < 7; a++) {
  130.                         PHL_DrawRect(18 + (48 * a), 114 + (48 * i), 44, 44, PHL_NewRGB(255, 255, 255));
  131.                         PHL_DrawRect(20 + (48 * a), 116 + (48 * i), 40, 40, PHL_NewRGB(119, 166, 219));
  132.                        
  133.                         if (hasItem[count] == 0) {
  134.                                 cx = 0;
  135.                                 cy = 0;
  136.                         }else{
  137.                                 cy = 0;
  138.                                 cx = (imageOrder[count] + 6) * 40;
  139.                                 while (cx >= 640) {
  140.                                         cy += 40;
  141.                                         cx -= 640;
  142.                                 }
  143.                         }
  144.                        
  145.                         PHL_DrawSurfacePart(20 + (48 * a), 116 + (48 * i), cx, cy, 40, 40, images[imgItems]);
  146.                         count++;
  147.                 }
  148.         }
  149.         //Keys
  150.         for (i = 0; i < 8; i++) {
  151.                 PHL_DrawRect(18 + (48 * i), 338, 44, 44, PHL_NewRGB(255, 255, 255));
  152.                 PHL_DrawRect(20 + (48 * i), 340, 40, 40, PHL_NewRGB(119, 166, 219));
  153.                 if (hasKey[i] == 1) {
  154.                         cx = 120 + (i * 40);
  155.                         cy = 80;
  156.                 }else{
  157.                         cx = 0;
  158.                         cy = 0;
  159.                 }
  160.                 PHL_DrawSurfacePart(20 + (48 * i), 340, cx, cy, 40, 40, images[imgItems]);
  161.         }
  162.        
  163.         //Text box
  164.         PHL_DrawRect(16, 400, 606, 46, PHL_NewRGB(255, 255, 255));
  165.         PHL_DrawRect(18, 402, 602, 42, PHL_NewRGB(0, 0, 255));
  166.        
  167.         //Text
  168.         if (hasItem[cursorX + (cursorY * 7)] == 1) {
  169.                 int drawX = 32, drawY = 402;
  170.                
  171.                 //Draw item name
  172.                 drawX = drawText(itemName[cursorX + (cursorY * 7) + 5], drawX, drawY);
  173.                 //Draw item description
  174.                 drawX = drawCharacter(6, 0, drawX, drawY);
  175.                 drawText(itemDescription[cursorX + (cursorY * 7)], drawX, drawY);
  176.         }
  177.        
  178.         //Cursor
  179.         PHL_DrawSurfacePart(16 + (cursorX * 48), 112 + (cursorY * 48), 0, 96, 48, 48, images[imgHud]);
  180. }