-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.hpp
122 lines (97 loc) · 2.78 KB
/
Ball.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#define XStep 1
#include <vector>
class Ball
{
private:
float positionX;
float positionY;
float speedX;
float speedY;
float ballRadius;
float speedRatio;
public:
Ball(int inputPositionX, int inputPositionY, float inputSpeed, int inputBallRadius){
positionX = inputPositionX;
positionY = inputPositionY - inputBallRadius;
speedY = inputSpeed;
speedX = inputSpeed;
ballRadius = inputBallRadius;
}
// interact with either ball or a wall
// multiply speed with some constant
float getPositionX(){
return positionX;
}
void revertSpeedY(){
speedY *= -1;
}
float getSpeedY(){
return speedY;
}
void setSpeedY(float inputSpeedY){
speedY = inputSpeedY;
}
float getBallRadius(){
return ballRadius;
}
void increaseSize(){
if (ballRadius < 50)
ballRadius += 1;
}
void decreaseSize(){
if (ballRadius > 2)
ballRadius -= 1;
}
float getPositionY(){
return positionY;
}
// why 2*ballRadius
// because an object is initiated on its topleft, see the + sign
// +-------------
// | |
// | |
// --------------
void moveYNeg(){
if (positionY > 0)
positionY += speedY;
std::cout << positionY << " " << ballRadius << std::endl;
}
void moveYPos(){
if (positionY + ballRadius*2 < 100)
positionY += speedY;
std::cout << positionY << " " << ballRadius << std::endl;
}
void moveXPos(){
if (positionX + ballRadius*2 < 100)
positionX += XStep;
}
void moveXNeg(){
if (positionX > 0)
positionX -= XStep;
}
void setYPos(float yCoord){
positionY = yCoord;
}
// TODO: refactor the code
// it is actually down
bool canMoveUp(){
if (positionY + ballRadius*2 + speedY < 100)
return true;
return false;
}
bool canMoveDown(){
if (positionY + speedY > 0)
return true;
return false;
}
bool touchingWallBelow(){
if (positionY + ballRadius*2 + speedY >= 100)
return true;
return false;
}
bool touchingWallAbove(){
if (positionY + speedY < 0)
return true;
return false;
}
};