-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstarfield.h
96 lines (83 loc) · 1.82 KB
/
starfield.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#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;
bool visible;
double xpos;
double ypos;
double movex;
double movey;
};
typedef std::function<bool(int x, int y)> checkVisibleFunction;
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(bool centered = false);
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);
checkVisibleFunction visible;
public:
AnimatedStarfield(door::Door &door, std::mt19937 &Rng);
void regenerate(void);
void display(void);
void animate(void);
void setVisible(checkVisibleFunction cvf);
};
#endif