@@ -19,8 +19,8 @@ using namespace sf;
19
19
Enemy::Enemy (float maxSpeed, float speedMul, float scale, int maxCounterToChange, const string &vehicle, float pY) :
20
20
Vehicle(maxSpeed / speedMul, scale, maxCounterToChange, 0 , random_float(-0 .5f , 0 .5f ),
21
21
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) {}
24
24
25
25
Vehicle::Direction randomDirection () {
26
26
const float p = random_zero_one ();
@@ -37,8 +37,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
37
37
// Original
38
38
if (current_direction_counter < max_direction_counter) {
39
39
current_direction_counter++;
40
- }
41
- else {
40
+ } else {
42
41
max_direction_counter = random_zero_n (MAX_AUTO_DIRECTION_COUNTER);
43
42
current_direction_counter = 0 ;
44
43
calculatedPath = randomDirection ();
@@ -56,8 +55,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
56
55
posX = newX;
57
56
58
57
currentDirection = calculatedPath;
59
- }
60
- else {
58
+ } else {
61
59
// AI
62
60
if (typeAI == OBSTACLE) {
63
61
const float acc = getAcceleration ();
@@ -69,13 +67,11 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
69
67
if (posX > playerPosX && posX > -0 .9f ) {
70
68
posX -= XINC * speed / maxSpeed;
71
69
currentDirection = TURNLEFT;
72
- }
73
- else if (posX < 0 .9f ) {
70
+ } else if (posX < 0 .9f ) {
74
71
posX += XINC * speed / maxSpeed;
75
72
currentDirection = TURNRIGHT;
76
73
}
77
- }
78
- else { // Acceleration control
74
+ } else { // Acceleration control
79
75
// The vehicle is in the player's path
80
76
if (posY <= playerPosY)
81
77
speed = sqrt (acc + ACC_INC);
@@ -86,28 +82,23 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
86
82
87
83
currentDirection = RIGHT;
88
84
}
89
- }
90
- else if (typeAI == EVASIVE) {
85
+ } else if (typeAI == EVASIVE) {
91
86
if (playerPosX <= -0.5 ) {
92
87
posX += XINC * speed / maxSpeed;
93
88
currentDirection = TURNRIGHT;
94
- }
95
- else if (playerPosX >= 0.5 ) {
89
+ } else if (playerPosX >= 0.5 ) {
96
90
posX -= XINC * speed / maxSpeed;
97
91
currentDirection = TURNLEFT;
98
- }
99
- else {
92
+ } else {
100
93
if (posX > playerPosX) {
101
94
posX += XINC * speed / maxSpeed;
102
95
currentDirection = TURNRIGHT;
103
- }
104
- else {
96
+ } else {
105
97
posX -= XINC * speed / maxSpeed;
106
98
currentDirection = TURNLEFT;
107
99
}
108
100
}
109
- }
110
- else { // INCONSTANT
101
+ } else { // INCONSTANT
111
102
if (currentDirection == TURNRIGHT) {
112
103
const float prevPosX = posX;
113
104
posX += XINC * speed / maxSpeed;
@@ -117,8 +108,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
117
108
else if (((prevPosX < -0 .5f && posX >= -0 .5f ) || (prevPosX < 0 .0f && posX >= 0 .0f ) ||
118
109
(prevPosX < 0 .5f && posX >= 0 .5f )) && (random_zero_one () < 0 .5f ))
119
110
currentDirection = TURNRIGHT; // Lane change
120
- }
121
- else if (currentDirection == TURNLEFT) {
111
+ } else if (currentDirection == TURNLEFT) {
122
112
const float prevPosX = posX;
123
113
posX -= XINC * speed / maxSpeed;
124
114
@@ -127,8 +117,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
127
117
else if (((prevPosX > -0 .5f && posX <= -0 .5f ) || (prevPosX > 0 .0f && posX <= 0 .0f ) ||
128
118
(prevPosX > 0 .5f && posX <= 0 .5f )) && (random_zero_one () < 0 .5f ))
129
119
currentDirection = TURNLEFT; // Lane change
130
- }
131
- else {
120
+ } else {
132
121
if (random_zero_one () < 0 .5f )
133
122
currentDirection = TURNRIGHT;
134
123
else
@@ -145,8 +134,7 @@ void Enemy::autoControl(const Config &c, float playerPosX, float playerPosY) {
145
134
if (posX > 0 .9f ) {
146
135
posX = 0 .9f ;
147
136
currentDirection = RIGHT;
148
- }
149
- else if (posX < -0 .9f ) {
137
+ } else if (posX < -0 .9f ) {
150
138
posX = -0 .9f ;
151
139
currentDirection = RIGHT;
152
140
}
@@ -179,11 +167,9 @@ void Enemy::setAI(float maxAggressiveness) {
179
167
const float p = random_zero_one ();
180
168
if (p < 0 .333f ) {
181
169
typeAI = OBSTACLE;
182
- }
183
- else if (p < 0 .666f ) {
170
+ } else if (p < 0 .666f ) {
184
171
typeAI = EVASIVE;
185
- }
186
- else {
172
+ } else {
187
173
typeAI = INCONSTANT;
188
174
probAI *= 2 .0f ;
189
175
}
@@ -202,64 +188,52 @@ void Enemy::draw(const Elevation &e, const float camX) {
202
188
if (posX <= camX) {
203
189
if (current_code_image < 1 || current_code_image > 2 )
204
190
current_code_image = 1 ;
205
- }
206
- else {
191
+ } else {
207
192
if (current_code_image < 3 || current_code_image > 4 )
208
193
current_code_image = 3 ;
209
194
}
210
- }
211
- else if (currentDirection == TURNLEFT) {
195
+ } else if (currentDirection == TURNLEFT) {
212
196
if (current_code_image < 7 || current_code_image > 8 )
213
197
current_code_image = 7 ;
214
- }
215
- else { // Turn right
198
+ } else { // Turn right
216
199
if (current_code_image < 5 || current_code_image > 6 )
217
200
current_code_image = 5 ;
218
201
}
219
- }
220
- else if (e == UP) {
202
+ } else if (e == UP) {
221
203
if (currentDirection == RIGHT) {
222
204
if (posX <= camX) {
223
205
if (current_code_image < 13 || current_code_image > 14 )
224
206
current_code_image = 13 ;
225
- }
226
- else {
207
+ } else {
227
208
if (current_code_image < 15 || current_code_image > 16 )
228
209
current_code_image = 15 ;
229
210
}
230
- }
231
- else if (currentDirection == TURNLEFT) {
211
+ } else if (currentDirection == TURNLEFT) {
232
212
if (current_code_image < 15 || current_code_image > 16 )
233
213
current_code_image = 15 ;
234
- }
235
- else { // Turn right
214
+ } else { // Turn right
236
215
if (current_code_image < 13 || current_code_image > 14 )
237
216
current_code_image = 13 ;
238
217
}
239
- }
240
- else { // Down
218
+ } else { // Down
241
219
if (currentDirection == RIGHT) {
242
220
if (posX <= camX) {
243
221
if (current_code_image < 9 || current_code_image > 10 )
244
222
current_code_image = 9 ;
245
- }
246
- else {
223
+ } else {
247
224
if (current_code_image < 11 || current_code_image > 12 )
248
225
current_code_image = 11 ;
249
226
}
250
- }
251
- else if (currentDirection == TURNLEFT) {
227
+ } else if (currentDirection == TURNLEFT) {
252
228
if (current_code_image < 11 || current_code_image > 12 )
253
229
current_code_image = 11 ;
254
- }
255
- else { // Turn right
230
+ } else { // Turn right
256
231
if (current_code_image < 9 || current_code_image > 10 )
257
232
current_code_image = 9 ;
258
233
}
259
234
}
260
235
}
261
- }
262
- else {
236
+ } else {
263
237
counter_code_image++;
264
238
}
265
239
}
@@ -282,7 +256,7 @@ float Enemy::getScale() const {
282
256
283
257
bool Enemy::hasCrashed (float prevY, float currentY, float minX, float maxX, float &crashPos) const {
284
258
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
286
260
((minX >= minScreenX && minX <= maxScreenX) ||
287
261
(maxX >= minScreenX && maxX <= maxScreenX) ||
288
262
(minScreenX >= minX && minScreenX <= maxX) ||
@@ -293,11 +267,11 @@ bool Enemy::hasCrashed(float prevY, float currentY, float minX, float maxX, floa
293
267
return false ;
294
268
}
295
269
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 {
297
272
if (posY < minY || posY > minY + float (c.renderLen ) || minScreenX < 0 || maxScreenX > c.w .getSize ().y ) {
298
273
return false ;
299
- }
300
- else {
274
+ } else {
301
275
distanceX = abs (playerX - posX);
302
276
distanceY = abs (playerY - posY);
303
277
return true ;
0 commit comments