-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble.h
104 lines (86 loc) · 2.68 KB
/
bubble.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
97
98
99
100
101
102
103
104
#include <simplecpp>
/* Bubble Vars */
const int BUBBLE_START_X = 250;
const int BUBBLE_START_Y = 75;
const int BUBBLE_DEFAULT_RADIUS = 10;
const int BUBBLE_RADIUS_THRESHOLD = 10; //if radius greater than threshold, split the bubbles
const int BUBBLE_DEFAULT_VX = 100;
const int BUBBLE_DEFAULT_VY = 0;
const Color BUBBLE_DEFAULT_COLOR=COLOR(29,201,153); //default colour of bubbles, not required in current game implementation
const int BUBBLE_DEFAULT_NO=2; //default number of bubbles initially
const double BUBBLE_DEFAULT_AY = 10; // gravity
class Bubble
{
private:
Circle circle; // the circle representing the bubble
double vx, vy; // velocity in x and y direction
double ay; // acceleration in y direction
Color color; // color of the bubble
public:
bool in_collision; //true if the bubble is currently in collision with shooter, else false
Bubble(double cx, double cy, int r, double vx_=BUBBLE_DEFAULT_VX, double vy_=BUBBLE_DEFAULT_VY, Color color_=BUBBLE_DEFAULT_COLOR,double ay_=BUBBLE_DEFAULT_AY)
{
// Bubble constructor
in_collision=false;
color = color_;
circle = Circle(cx, cy, r);
circle.setColor(color);
circle.setFill(true);
ay=ay_;
vx = vx_;
vy = vy_;
}
void nextStep(double t)
{
// move the bubble
double new_x = circle.getX() + vx*t;
double new_y = circle.getY() + vy*t;
vy=vy+ay*t;
if ((vx < 0 && new_x < (0 + circle.getRadius())) // bounce along X direction at left border
||
(vx > 0 && new_x > (WINDOW_X - circle.getRadius()))) // bounce along X direction at right border
{
vx = -vx;
new_x = circle.getX() + vx*t;
}
//bounce along the bottom and top
if(((vy>0) && (new_y>(450-circle.getRadius())))
||
((vy<0) && (new_y<(0+circle.getRadius()))))
{
vy=-vy;
new_y=circle.getY()-vy*t;
}
circle.moveTo(new_x, new_y);
}
int get_radius()
{
// return the radius of the bubble
return circle.getRadius();
}
double get_center_x()
{
// return the x coordinate of the center of the bubble
return circle.getX();
}
double get_center_y()
{
// return the y coordinate of the center of the bubble
return circle.getY();
}
double get_vx()
{
// return the x velocity of the bubble
return vx;
}
double get_vy()
{
// return the y velocity of the bubble
return vy;
}
Color get_color()
{
// return the color of the bubble
return color;
}
};