Interface.cpp 2.1 KB

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