Interface.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "Interface.h"
  2. #include <GL/freeglut.h>
  3. #include "CrystalPoint.h"
  4. #include <string>
  5. #include "Player.h"
  6. #include "Util.h"
  7. Interface::Interface()
  8. {
  9. crystalWidth = 20;
  10. crystalHeight = 50;
  11. crystalOffset = 5;
  12. maxCrystals = 0;
  13. }
  14. Interface::Interface(int maxCrystal)
  15. {
  16. crystalWidth = 20;
  17. crystalHeight = 50;
  18. crystalOffset = 5;
  19. maxCrystals = maxCrystal;
  20. }
  21. Interface::~Interface()
  22. {
  23. }
  24. void Interface::draw()
  25. {
  26. Player* player = Player::getInstance();
  27. //Switch view to Ortho
  28. glMatrixMode(GL_PROJECTION);
  29. glLoadIdentity();
  30. glOrtho(0, 1000, 1000, 0, -10, 10);
  31. glMatrixMode(GL_MODELVIEW);
  32. glLoadIdentity();
  33. glDisable(GL_LIGHTING);
  34. glDisable(GL_DEPTH_TEST);
  35. glDisable(GL_TEXTURE_2D);
  36. //Draw interface
  37. //Health bar
  38. glBegin(GL_QUADS);
  39. glColor4f(0,0,0, 1.0);
  40. glVertex2f(250, 980);
  41. glVertex2f(250, 965);
  42. glVertex2f(750, 965);
  43. glVertex2f(750, 980);
  44. glEnd();
  45. glBegin(GL_QUADS);
  46. glColor4f(1.0f, 0.1f, 0.1f, 1.0);
  47. glVertex2f(250, 980);
  48. glVertex2f(250, 965);
  49. glColor4f(1.0f, 0.5f, 0.5f, 1.0);
  50. glVertex2f(250 + (player->health / 100 * 500), 965);
  51. glVertex2f(250 + (player->health / 100 * 500), 980);
  52. glEnd();
  53. //XP bar
  54. glBegin(GL_QUADS);
  55. glColor4f(0, 0, 0, 1.0);
  56. glVertex2f(250, 950);
  57. glVertex2f(250, 935);
  58. glVertex2f(750, 935);
  59. glVertex2f(750, 950);
  60. glEnd();
  61. glBegin(GL_QUADS);
  62. glColor4f(1.0f, 1.0f, 0.1f, 1.0);
  63. glVertex2f(250, 950);
  64. glVertex2f(250, 935);
  65. glColor4f(1.0f, 1.0f, 0.5f, 1.0);
  66. glVertex2f(250 + (player->xp / 100 * 500), 935);
  67. glVertex2f(250 + (player->xp / 100 * 500), 950);
  68. glEnd();
  69. //Text: level
  70. glColor4f(1.0f, 1.0f, 0.1f, 1.0);
  71. Util::glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
  72. for (int i = 0; i < maxCrystals; i++)
  73. {
  74. glBegin(GL_QUADS);
  75. if(i < player->crystals)
  76. glColor4f(0, 1.0f, 1.0f, 1.0f);
  77. else
  78. glColor4f(0, 0.4f, 0.4f, 1.0f);
  79. glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i);
  80. glVertex2f(975 - crystalWidth , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
  81. if (i < player->crystals)
  82. glColor4f(0, 0.7f, 0.7f, 1.0f);
  83. else
  84. glColor4f(0, 0.2f, 0.2f, 1.0f);
  85. glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
  86. glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
  87. glEnd();
  88. }
  89. glEnable(GL_LIGHTING);
  90. glEnable(GL_DEPTH_TEST);
  91. }
  92. void Interface::update(float deltaTime)
  93. {
  94. }