Interface.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. }
  63. void Interface::update(float deltaTime)
  64. {
  65. }
  66. void glutBitmapString(std::string str, int x, int y)
  67. {
  68. glRasterPos2f(x, y);
  69. for (int i = 0; i < str.size(); i++)
  70. {
  71. glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
  72. }
  73. }