Interface.cpp 2.6 KB

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