Interface.cpp 2.3 KB

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