starfield.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef STARFIELD_H
  2. #define STARFIELD_H
  3. #include "door.h"
  4. #include <random>
  5. #include <set>
  6. struct star_pos {
  7. int x;
  8. int y;
  9. int symbol;
  10. int color;
  11. /**
  12. * @brief Provide less than operator.
  13. *
  14. * This will allow the star_pos to be stored sorted (top->bottom,
  15. * left->right) in a set.
  16. *
  17. * @param rhs
  18. * @return true
  19. * @return false
  20. */
  21. bool operator<(const star_pos rhs) const {
  22. if (rhs.y > y)
  23. return true;
  24. if (rhs.y == y) {
  25. if (rhs.x > x)
  26. return true;
  27. return false;
  28. }
  29. return false;
  30. }
  31. };
  32. class Starfield {
  33. door::Door &door;
  34. std::mt19937 &rng;
  35. std::set<star_pos> sky;
  36. std::uniform_int_distribution<int> uni_x;
  37. std::uniform_int_distribution<int> uni_y;
  38. star_pos make_pos(void);
  39. door::ANSIColor white; //(door::COLOR::WHITE);
  40. door::ANSIColor dark; //(door::COLOR::BLACK, door::ATTR::BRIGHT);
  41. const char *stars[2];
  42. public:
  43. Starfield(door::Door &Door, std::mt19937 &Rng);
  44. void regenerate(void);
  45. void display(void);
  46. };
  47. struct moving_star {
  48. int x;
  49. int y;
  50. int symbol;
  51. int color;
  52. double xpos;
  53. double ypos;
  54. double movex;
  55. double movey;
  56. };
  57. class AnimatedStarfield {
  58. door::Door &door;
  59. std::mt19937 &rng;
  60. std::vector<moving_star> sky;
  61. std::uniform_int_distribution<int> uni_x;
  62. std::uniform_int_distribution<int> uni_y;
  63. moving_star make_pos(void);
  64. int mx;
  65. int my;
  66. double cx;
  67. double cy;
  68. double max_d;
  69. door::ANSIColor white;
  70. door::ANSIColor dark;
  71. const char *stars[2];
  72. double distance(double x, double y);
  73. public:
  74. AnimatedStarfield(door::Door &door, std::mt19937 &Rng);
  75. void regenerate(void);
  76. void display(void);
  77. void animate(void);
  78. };
  79. #endif