1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #ifndef STARFIELD_H
- #define STARFIELD_H
- #include "door.h"
- #include <random>
- #include <set>
- struct star_pos {
- int x;
- int y;
- int symbol;
- int color;
- /**
- * @brief Provide less than operator.
- *
- * This will allow the star_pos to be stored sorted (top->bottom,
- * left->right) in a set.
- *
- * @param rhs
- * @return true
- * @return false
- */
- bool operator<(const star_pos rhs) const {
- if (rhs.y > y)
- return true;
- if (rhs.y == y) {
- if (rhs.x > x)
- return true;
- return false;
- }
- return false;
- }
- };
- class Starfield {
- door::Door &door;
- std::mt19937 &rng;
- std::set<star_pos> sky;
- std::uniform_int_distribution<int> uni_x;
- std::uniform_int_distribution<int> uni_y;
- star_pos make_pos(void);
- door::ANSIColor white; //(door::COLOR::WHITE);
- door::ANSIColor dark; //(door::COLOR::BLACK, door::ATTR::BRIGHT);
- const char *stars[2];
- public:
- Starfield(door::Door &Door, std::mt19937 &Rng);
- void regenerate(void);
- void display(void);
- };
- struct moving_star {
- int x;
- int y;
- int symbol;
- int color;
- double xpos;
- double ypos;
- double movex;
- double movey;
- };
- class AnimatedStarfield {
- door::Door &door;
- std::mt19937 &rng;
- std::vector<moving_star> sky;
- std::uniform_int_distribution<int> uni_x;
- std::uniform_int_distribution<int> uni_y;
- moving_star make_pos(void);
- int mx;
- int my;
- double cx;
- double cy;
- double max_d;
- door::ANSIColor white;
- door::ANSIColor dark;
- const char *stars[2];
- double distance(double x, double y);
- public:
- AnimatedStarfield(door::Door &door, std::mt19937 &Rng);
- void regenerate(void);
- void display(void);
- void animate(void);
- };
- #endif
|