Skip to content

Commit b5054db

Browse files
committed
Limpieza automática de código
1 parent 80a18a5 commit b5054db

17 files changed

+1008
-919
lines changed

Button.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11

22
#include "Button.hpp"
33

4-
Button::Button(){}
4+
Button::Button() {}
55

6-
Button::Button (float x, float y, float width, float height, Font& f,
7-
string text, Color idleColor, Color hoverColor, Color activeColor, int initialState, float screenScale)
8-
{
6+
Button::Button(float x, float y, float width, float height, Font &f,
7+
string text, Color idleColor, Color hoverColor, Color activeColor, int initialState, float screenScale) {
98
shape.setPosition(Vector2f(x, y));
109
shape.setSize(Vector2f(width, height));
1110
shape.setOutlineColor(Color::Black);
1211
shape.setOutlineThickness(3.0f * screenScale);
1312
textButton.setString(text);
1413
textButton.setFont(f);
1514
textButton.setFillColor(Color::Blue);
16-
textButton.setCharacterSize(int(12.0f * screenScale));
15+
textButton.setCharacterSize(static_cast<unsigned int>(int(12.0f * screenScale)));
1716
textButton.setPosition(
18-
shape.getPosition().x + (shape.getGlobalBounds().width / 2.f) - textButton.getGlobalBounds().width / 2.f,
19-
shape.getPosition().y + (shape.getGlobalBounds().height / 2.f) - textButton.getGlobalBounds().height / 2.f - 5
17+
shape.getPosition().x + (shape.getGlobalBounds().width / 2.f) - textButton.getGlobalBounds().width / 2.f,
18+
shape.getPosition().y + (shape.getGlobalBounds().height / 2.f) - textButton.getGlobalBounds().height / 2.f -
19+
5
2020
);
2121

2222
// Store the possible colors of the button
@@ -25,52 +25,49 @@ Button::Button (float x, float y, float width, float height, Font& f,
2525
activeColorButton = activeColor;
2626

2727
// Check the initial state of the button
28-
switch (initialState){
29-
case 0:
30-
buttonState = BUTTON_IDLE;
28+
switch (initialState) {
29+
case 0:;
3130
shape.setFillColor(idleColorButton);
32-
break;
33-
case 1:
34-
buttonState = BUTTON_HOVER;
31+
break;
32+
case 1:;
3533
shape.setFillColor(hoverColorButton);
36-
break;
37-
case 2:
38-
buttonState = BUTTON_PRESSED;
34+
break;
35+
case 2:;
3936
shape.setFillColor(activeColorButton);
37+
break;
38+
default:
39+
break;
4040
}
4141
}
4242

4343

44-
45-
void Button::setButtonState(button_states stateButton){
46-
switch(stateButton){
44+
void Button::setButtonState(button_states stateButton) {
45+
switch (stateButton) {
4746
case BUTTON_IDLE:
4847
shape.setFillColor(idleColorButton);
49-
break;
48+
break;
5049
case BUTTON_HOVER:
5150
shape.setFillColor(hoverColorButton);
52-
break;
51+
break;
5352
case BUTTON_PRESSED:
5453
shape.setFillColor(activeColorButton);
5554
}
5655
}
5756

5857

59-
void Button::render (RenderTexture* app){
58+
void Button::render(RenderTexture *app) {
6059
app->draw(shape);
6160
app->draw(textButton);
6261
}
6362

6463

65-
void Button::setTextButton(string newString){
64+
void Button::setTextButton(string newString) {
6665
textButton.setString(newString);
6766
textButton.setPosition(
68-
shape.getPosition().x + (shape.getGlobalBounds().width / 2.f) - textButton.getGlobalBounds().width / 2.f,
69-
shape.getPosition().y + (shape.getGlobalBounds().height / 2.f) - textButton.getGlobalBounds().height / 2.f - 5
67+
shape.getPosition().x + (shape.getGlobalBounds().width / 2.f) - textButton.getGlobalBounds().width / 2.f,
68+
shape.getPosition().y + (shape.getGlobalBounds().height / 2.f) - textButton.getGlobalBounds().height / 2.f -
69+
5
7070
);
7171
}
7272

7373

74-
string Button::getTextButton(){
75-
return textButton.getString();
76-
}

Button.hpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,26 @@ enum button_states {
1818
};
1919

2020
class Button {
21-
private:
22-
RectangleShape shape;
23-
Font fontButton;
24-
Text textButton;
21+
private:
22+
RectangleShape shape;
23+
Text textButton;
2524

26-
Color idleColorButton;
27-
Color hoverColorButton;
28-
Color activeColorButton;
25+
Color idleColorButton;
26+
Color hoverColorButton;
27+
Color activeColorButton;
2928

30-
bool hover, pressed;
31-
int buttonState;
29+
public:
3230

33-
public:
31+
Button();
3432

35-
const bool isPressed() const;
33+
Button(float x, float y, float width, float height, Font &f, string text,
34+
Color idleColor, Color hoverColor, Color activeColor, int initialState, float screenScale);
3635

37-
const bool isHovered() const;
36+
void setButtonState(button_states buttonState);
3837

39-
Button();
38+
void render(RenderTexture *app);
4039

41-
Button (float x, float y, float width, float height, Font& f, string text,
42-
Color idleColor, Color hoverColor, Color activeColor, int initialState, float screenScale);
43-
44-
void getPressed (Button& otherButton);
45-
46-
void setButtonState(button_states buttonState);
47-
48-
void render (RenderTexture* app);
49-
50-
void setTextButton(string newString);
51-
52-
string getTextButton();
40+
void setTextButton(string newString);
5341

5442
};
5543

Enemy.cpp

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ using namespace sf;
1919
Enemy::Enemy(float maxSpeed, float speedMul, float scale, int maxCounterToChange, const string &vehicle, float pY) :
2020
Vehicle(maxSpeed / speedMul, scale, maxCounterToChange, 0, random_float(-0.5f, 0.5f),
2121
pY, pY, 0, 0, vehicle, ENEMY_TEXTURES, 1, 0), oriX(this->posX),
22-
currentDirection(RIGHT), calculatedPath(RIGHT), current_direction_counter(0), max_direction_counter(0),
23-
probAI(0), typeAI(OBSTACLE) {}
22+
currentDirection(RIGHT), calculatedPath(RIGHT), current_direction_counter(0), max_direction_counter(0),
23+
probAI(0), typeAI(OBSTACLE) {}
2424

2525
Vehicle::Direction randomDirection() {
2626
const float p = random_zero_one();
@@ -37,8 +37,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
3737
// Original
3838
if (current_direction_counter < max_direction_counter) {
3939
current_direction_counter++;
40-
}
41-
else {
40+
} else {
4241
max_direction_counter = random_zero_n(MAX_AUTO_DIRECTION_COUNTER);
4342
current_direction_counter = 0;
4443
calculatedPath = randomDirection();
@@ -56,8 +55,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
5655
posX = newX;
5756

5857
currentDirection = calculatedPath;
59-
}
60-
else {
58+
} else {
6159
// AI
6260
if (typeAI == OBSTACLE) {
6361
const float acc = getAcceleration();
@@ -69,13 +67,11 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
6967
if (posX > playerPosX && posX > -0.9f) {
7068
posX -= XINC * speed / maxSpeed;
7169
currentDirection = TURNLEFT;
72-
}
73-
else if (posX < 0.9f) {
70+
} else if (posX < 0.9f) {
7471
posX += XINC * speed / maxSpeed;
7572
currentDirection = TURNRIGHT;
7673
}
77-
}
78-
else { // Acceleration control
74+
} else { // Acceleration control
7975
// The vehicle is in the player's path
8076
if (posY <= playerPosY)
8177
speed = sqrt(acc + ACC_INC);
@@ -86,28 +82,23 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
8682

8783
currentDirection = RIGHT;
8884
}
89-
}
90-
else if (typeAI == EVASIVE) {
85+
} else if (typeAI == EVASIVE) {
9186
if (playerPosX <= -0.5) {
9287
posX += XINC * speed / maxSpeed;
9388
currentDirection = TURNRIGHT;
94-
}
95-
else if (playerPosX >= 0.5) {
89+
} else if (playerPosX >= 0.5) {
9690
posX -= XINC * speed / maxSpeed;
9791
currentDirection = TURNLEFT;
98-
}
99-
else {
92+
} else {
10093
if (posX > playerPosX) {
10194
posX += XINC * speed / maxSpeed;
10295
currentDirection = TURNRIGHT;
103-
}
104-
else {
96+
} else {
10597
posX -= XINC * speed / maxSpeed;
10698
currentDirection = TURNLEFT;
10799
}
108100
}
109-
}
110-
else { // INCONSTANT
101+
} else { // INCONSTANT
111102
if (currentDirection == TURNRIGHT) {
112103
const float prevPosX = posX;
113104
posX += XINC * speed / maxSpeed;
@@ -117,8 +108,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
117108
else if (((prevPosX < -0.5f && posX >= -0.5f) || (prevPosX < 0.0f && posX >= 0.0f) ||
118109
(prevPosX < 0.5f && posX >= 0.5f)) && (random_zero_one() < 0.5f))
119110
currentDirection = TURNRIGHT; // Lane change
120-
}
121-
else if (currentDirection == TURNLEFT) {
111+
} else if (currentDirection == TURNLEFT) {
122112
const float prevPosX = posX;
123113
posX -= XINC * speed / maxSpeed;
124114

@@ -127,8 +117,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
127117
else if (((prevPosX > -0.5f && posX <= -0.5f) || (prevPosX > 0.0f && posX <= 0.0f) ||
128118
(prevPosX > 0.5f && posX <= 0.5f)) && (random_zero_one() < 0.5f))
129119
currentDirection = TURNLEFT; // Lane change
130-
}
131-
else {
120+
} else {
132121
if (random_zero_one() < 0.5f)
133122
currentDirection = TURNRIGHT;
134123
else
@@ -145,8 +134,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
145134
if (posX > 0.9f) {
146135
posX = 0.9f;
147136
currentDirection = RIGHT;
148-
}
149-
else if (posX < -0.9f) {
137+
} else if (posX < -0.9f) {
150138
posX = -0.9f;
151139
currentDirection = RIGHT;
152140
}
@@ -179,11 +167,9 @@ void Enemy::setAI(float maxAggressiveness) {
179167
const float p = random_zero_one();
180168
if (p < 0.333f) {
181169
typeAI = OBSTACLE;
182-
}
183-
else if (p < 0.666f) {
170+
} else if (p < 0.666f) {
184171
typeAI = EVASIVE;
185-
}
186-
else {
172+
} else {
187173
typeAI = INCONSTANT;
188174
probAI *= 2.0f;
189175
}
@@ -202,64 +188,52 @@ void Enemy::draw(const Elevation &e, const float camX) {
202188
if (posX <= camX) {
203189
if (current_code_image < 1 || current_code_image > 2)
204190
current_code_image = 1;
205-
}
206-
else {
191+
} else {
207192
if (current_code_image < 3 || current_code_image > 4)
208193
current_code_image = 3;
209194
}
210-
}
211-
else if (currentDirection == TURNLEFT) {
195+
} else if (currentDirection == TURNLEFT) {
212196
if (current_code_image < 7 || current_code_image > 8)
213197
current_code_image = 7;
214-
}
215-
else { // Turn right
198+
} else { // Turn right
216199
if (current_code_image < 5 || current_code_image > 6)
217200
current_code_image = 5;
218201
}
219-
}
220-
else if (e == UP) {
202+
} else if (e == UP) {
221203
if (currentDirection == RIGHT) {
222204
if (posX <= camX) {
223205
if (current_code_image < 13 || current_code_image > 14)
224206
current_code_image = 13;
225-
}
226-
else {
207+
} else {
227208
if (current_code_image < 15 || current_code_image > 16)
228209
current_code_image = 15;
229210
}
230-
}
231-
else if (currentDirection == TURNLEFT) {
211+
} else if (currentDirection == TURNLEFT) {
232212
if (current_code_image < 15 || current_code_image > 16)
233213
current_code_image = 15;
234-
}
235-
else { // Turn right
214+
} else { // Turn right
236215
if (current_code_image < 13 || current_code_image > 14)
237216
current_code_image = 13;
238217
}
239-
}
240-
else { // Down
218+
} else { // Down
241219
if (currentDirection == RIGHT) {
242220
if (posX <= camX) {
243221
if (current_code_image < 9 || current_code_image > 10)
244222
current_code_image = 9;
245-
}
246-
else {
223+
} else {
247224
if (current_code_image < 11 || current_code_image > 12)
248225
current_code_image = 11;
249226
}
250-
}
251-
else if (currentDirection == TURNLEFT) {
227+
} else if (currentDirection == TURNLEFT) {
252228
if (current_code_image < 11 || current_code_image > 12)
253229
current_code_image = 11;
254-
}
255-
else { // Turn right
230+
} else { // Turn right
256231
if (current_code_image < 9 || current_code_image > 10)
257232
current_code_image = 9;
258233
}
259234
}
260235
}
261-
}
262-
else {
236+
} else {
263237
counter_code_image++;
264238
}
265239
}
@@ -282,7 +256,7 @@ float Enemy::getScale() const {
282256

283257
bool Enemy::hasCrashed(float prevY, float currentY, float minX, float maxX, float &crashPos) const {
284258
if (minScreenX != maxScreenX && ((prevY <= posY + 2.5f && currentY >= posY - 2.5f) ||
285-
(currentY <= posY + 2.5f && prevY >= posY - 2.5f)) && // y matches
259+
(currentY <= posY + 2.5f && prevY >= posY - 2.5f)) && // y matches
286260
((minX >= minScreenX && minX <= maxScreenX) ||
287261
(maxX >= minScreenX && maxX <= maxScreenX) ||
288262
(minScreenX >= minX && minScreenX <= maxX) ||
@@ -293,11 +267,11 @@ bool Enemy::hasCrashed(float prevY, float currentY, float minX, float maxX, floa
293267
return false;
294268
}
295269

296-
bool Enemy::isVisible(const Config &c, float minY, float playerX, float playerY, float &distanceX, float &distanceY) const {
270+
bool
271+
Enemy::isVisible(const Config &c, float minY, float playerX, float playerY, float &distanceX, float &distanceY) const {
297272
if (posY < minY || posY > minY + float(c.renderLen) || minScreenX < 0 || maxScreenX > c.w.getSize().y) {
298273
return false;
299-
}
300-
else {
274+
} else {
301275
distanceX = abs(playerX - posX);
302276
distanceY = abs(playerY - posY);
303277
return true;

Enemy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Enemy : public Vehicle {
101101

102102
void setMaxScreenX(float screenX);
103103

104-
const Texture* getCurrentTexture() const;
104+
const Texture *getCurrentTexture() const;
105105

106106
float getScale() const;
107107

0 commit comments

Comments
 (0)