-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle.hpp
95 lines (81 loc) · 2.31 KB
/
Circle.hpp
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
/*
Developers:
Clara Rosa (github.com/claraxsilveira)
Lucas Turci (github.com/lucasturci)
Raphael Medeiros Vieira (github.com/rmedeiros23)
*/
#ifndef CIRCLE_HPP
#define CIRCLE_HPP
#include <cstdlib>
#include "constants.h"
#include "RandomNumber.hpp"
class Circle {
public:
static const int seed = 205;
const float vel = 5;
float radius = 20;
float x, y;
bool horizontal;
int orientation; // 0 = positive 1 = negative
bool active;
int iterations_until_active;
static RandomNumber * gen;
Circle() {
// init its position
if(gen == NULL) gen = RandomNumber::getGenerator();
horizontal = gen->randInt(0, 1);
orientation = gen->randInt(0, 1);
x = gen->randInt(radius, window_width - radius);
y = gen->randInt(radius, window_height - radius);
active = false;
iterations_until_active = 100;
}
static void setGenerator() {
gen = new RandomNumber(seed);
}
void setPosition(float x, float y) {
this->x = x;
this->y = y;
}
void move() {
// horizontal circle
if(horizontal) {
if(orientation == 0) {
x += vel;
if(x + radius >= window_width) {
x -= (x + radius - (window_width - 1)); // kickback
orientation = 1 - orientation;
}
} else {
x -= vel;
if(x - radius < 0) {
x += 0 - (x - radius); // kickback
orientation = 1 - orientation;
}
}
} else { // vertical circle
if(orientation == 0) {
y += vel;
if(y + radius >= window_height) {
y -= (y + radius - (window_height - 1)); // kickback
orientation = 1 - orientation;
}
} else {
y -= vel;
if(y - radius < 0) { // kickback
y += 0 - (y - radius);
orientation = 1 - orientation;
}
}
}
iterations_until_active--;
if(iterations_until_active == 0) {
active = true;
}
}
~Circle() {
// does nothing
}
};
RandomNumber * Circle::gen = NULL;
#endif