Interface.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. }
  13. Interface::~Interface()
  14. {
  15. }
  16. void Interface::draw()
  17. {
  18. Player* player = Player::getInstance();
  19. //Switch view to Ortho
  20. glMatrixMode(GL_PROJECTION);
  21. glLoadIdentity();
  22. glOrtho(0, 1000, 1000, 0, -10, 10);
  23. glMatrixMode(GL_MODELVIEW);
  24. glLoadIdentity();
  25. glDisable(GL_LIGHTING);
  26. glDisable(GL_DEPTH_TEST);
  27. glDisable(GL_TEXTURE_2D);
  28. //Draw interface
  29. //Health bar
  30. glBegin(GL_QUADS);
  31. glColor4f(0,0,0, 1.0);
  32. glVertex2f(250, 980);
  33. glVertex2f(250, 965);
  34. glVertex2f(750, 965);
  35. glVertex2f(750, 980);
  36. glEnd();
  37. glBegin(GL_QUADS);
  38. glColor4f(1.0f, 0.1f, 0.1f, 1.0);
  39. glVertex2f(250, 980);
  40. glVertex2f(250, 965);
  41. glColor4f(1.0f, 0.5f, 0.5f, 1.0);
  42. glVertex2f(250 + (player->health / 100 * 500), 965);
  43. glVertex2f(250 + (player->health / 100 * 500), 980);
  44. glEnd();
  45. //XP bar
  46. glBegin(GL_QUADS);
  47. glColor4f(0, 0, 0, 1.0);
  48. glVertex2f(250, 950);
  49. glVertex2f(250, 935);
  50. glVertex2f(750, 935);
  51. glVertex2f(750, 950);
  52. glEnd();
  53. glBegin(GL_QUADS);
  54. glColor4f(1.0f, 1.0f, 0.1f, 1.0);
  55. glVertex2f(250, 950);
  56. glVertex2f(250, 935);
  57. glColor4f(1.0f, 1.0f, 0.5f, 1.0);
  58. glVertex2f(250 + (player->xp / 100 * 500), 935);
  59. glVertex2f(250 + (player->xp / 100 * 500), 950);
  60. glEnd();
  61. //Text: level
  62. glColor4f(1.0f, 1.0f, 0.1f, 1.0);
  63. Util::glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
  64. int cw, ch, offset;
  65. cw = 20;
  66. ch = 50;
  67. offset = 5;
  68. for (int i = 0; i < player->crystals; i++)
  69. {
  70. glBegin(GL_QUADS);
  71. glColor4f(0, 1.0f, 1.0f, 1.0f);
  72. glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i);
  73. glVertex2f(975 - crystalWidth , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
  74. glColor4f(0, 0.8f, 0.8f, 1.0f);
  75. glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
  76. glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
  77. glEnd();
  78. }
  79. glEnable(GL_LIGHTING);
  80. glEnable(GL_DEPTH_TEST);
  81. }
  82. void Interface::update(float deltaTime)
  83. {
  84. }