@@ -58,7 +58,7 @@ static void pong_time_update(struct pong_time *pong_time)
58
58
59
59
static void pong_init_internal (struct pong * pong , ge_GIF * gif , bool reset )
60
60
{
61
- double ball_y = rand_double (16.0f ) + 8.0f ;
61
+ double ball_y = rand_double (16.0 ) + 8.0 ;
62
62
struct {
63
63
double y , target_y ;
64
64
} left , right ;
@@ -73,8 +73,8 @@ static void pong_init_internal(struct pong *pong, ge_GIF *gif, bool reset)
73
73
74
74
* pong = (struct pong ){
75
75
.gif = gif ,
76
- .ball_x = {.pos = 31.0f , .vel = 1.0f },
77
- .ball_y = {.pos = ball_y , .vel = rand () % 2 ? 0.5f : -0.5f },
76
+ .ball_x = {.pos = 31.0 , .vel = 1.0 },
77
+ .ball_y = {.pos = ball_y , .vel = rand () % 2 ? 0.5 : -0.5 },
78
78
.player_left = {.y = 8 , .target_y = ball_y },
79
79
.player_right = {.y = 18 , .target_y = ball_y },
80
80
.player_loss = 0 ,
@@ -149,13 +149,13 @@ static double pong_calculate_end_point(const struct pong *pong, bool hit)
149
149
x += vel_x ;
150
150
y += vel_y ;
151
151
if (hit ) {
152
- if (x >= 60.0f || x <= 2.0f )
152
+ if (x >= 60.0 || x <= 2.0 )
153
153
return y ;
154
154
} else {
155
- if (x >= 62.0f || x <= 0.0f )
155
+ if (x >= 62.0 || x <= 0.0 )
156
156
return y ;
157
157
}
158
- if (y >= 30.0f || y <= 0.0f )
158
+ if (y >= 30.0 || y <= 0.0 )
159
159
vel_y = - vel_y ;
160
160
}
161
161
}
@@ -179,49 +179,49 @@ uint64_t pong_draw(struct pong *pong)
179
179
pong -> ball_x .pos += pong -> ball_x .vel ;
180
180
pong -> ball_y .pos += pong -> ball_y .vel ;
181
181
182
- if ((pong -> ball_x .pos >= 60.0f && pong -> player_loss != 1 ) ||
183
- (pong -> ball_x .pos <= 2.0f && pong -> player_loss != -1 )) {
182
+ if ((pong -> ball_x .pos >= 60.0 && pong -> player_loss != 1 ) ||
183
+ (pong -> ball_x .pos <= 2.0 && pong -> player_loss != -1 )) {
184
184
pong -> ball_x .vel = - pong -> ball_x .vel ;
185
185
if (rand () % 4 > 0 ) {
186
186
if (rand () % 2 == 0 ) {
187
- if (pong -> ball_y .vel > 0.0f && pong -> ball_y .vel < 2.5f )
188
- pong -> ball_y .vel += 0.2f ;
189
- else if (pong -> ball_y .vel < 0.0f && pong -> ball_y .vel > -2.5f )
190
- pong -> ball_y .vel -= 0.2f ;
187
+ if (pong -> ball_y .vel > 0.0 && pong -> ball_y .vel < 2.5 )
188
+ pong -> ball_y .vel += 0.2 ;
189
+ else if (pong -> ball_y .vel < 0.0 && pong -> ball_y .vel > -2.5 )
190
+ pong -> ball_y .vel -= 0.2 ;
191
191
192
- if (pong -> ball_x .pos >= 60.0f )
193
- pong -> player_right .target_y += 1.0f + rand_double (3 );
192
+ if (pong -> ball_x .pos >= 60.0 )
193
+ pong -> player_right .target_y += 1.0 + rand_double (3 );
194
194
else
195
- pong -> player_left .target_y += 1.0f + rand_double (3 );
195
+ pong -> player_left .target_y += 1.0 + rand_double (3 );
196
196
} else {
197
- if (pong -> ball_y .vel > 0.5f )
198
- pong -> ball_y .vel -= 0.2f ;
199
- else if (pong -> ball_y .vel < -0.5f )
200
- pong -> ball_y .vel += 0.2f ;
197
+ if (pong -> ball_y .vel > 0.5 )
198
+ pong -> ball_y .vel -= 0.2 ;
199
+ else if (pong -> ball_y .vel < -0.5 )
200
+ pong -> ball_y .vel += 0.2 ;
201
201
202
- if (pong -> ball_x .pos >= 60.0f )
203
- pong -> player_right .target_y -= 1.0f + rand_double (3 );
202
+ if (pong -> ball_x .pos >= 60.0 )
203
+ pong -> player_right .target_y -= 1.0 + rand_double (3 );
204
204
else
205
- pong -> player_left .target_y -= 1.0f + rand_double (3 );
205
+ pong -> player_left .target_y -= 1.0 + rand_double (3 );
206
206
}
207
207
208
- clamp (& pong -> player_left .target_y , 0.0f , 24.0f );
209
- clamp (& pong -> player_right .target_y , 0.0f , 24.0f );
208
+ clamp (& pong -> player_left .target_y , 0.0 , 24.0 );
209
+ clamp (& pong -> player_right .target_y , 0.0 , 24.0 );
210
210
}
211
- } else if ((pong -> ball_x .pos > 62.0f && pong -> player_loss == 1 ) ||
212
- (pong -> ball_x .pos < 1.0f && pong -> player_loss == -1 )) {
211
+ } else if ((pong -> ball_x .pos > 62.0 && pong -> player_loss == 1 ) ||
212
+ (pong -> ball_x .pos < 1.0 && pong -> player_loss == -1 )) {
213
213
pong_init_internal (pong , pong -> gif , true);
214
214
}
215
215
216
- if (pong -> ball_y .pos >= 30.0f || pong -> ball_y .pos <= 0.0f )
216
+ if (pong -> ball_y .pos >= 30.0 || pong -> ball_y .pos <= 0.0 )
217
217
pong -> ball_y .vel = - pong -> ball_y .vel ;
218
218
219
- if (roundf (pong -> ball_x .pos ) == 40.0f + rand_double (13 )) {
220
- pong -> player_left .target_y = pong -> ball_y .pos - 3.0f ;
221
- clamp (& pong -> player_left .target_y , 0.0f , 24.0f );
219
+ if (roundf (pong -> ball_x .pos ) == 40.0 + rand_double (13 )) {
220
+ pong -> player_left .target_y = pong -> ball_y .pos - 3.0 ;
221
+ clamp (& pong -> player_left .target_y , 0.0 , 24.0 );
222
222
} else if (roundf (pong -> ball_x .pos ) == 8 + rand_double (13 )) {
223
- pong -> player_right .target_y = pong -> ball_y .pos - 3.0f ;
224
- clamp (& pong -> player_right .target_y , 0.0f , 24.0f );
223
+ pong -> player_right .target_y = pong -> ball_y .pos - 3.0 ;
224
+ clamp (& pong -> player_right .target_y , 0.0 , 24.0 );
225
225
}
226
226
227
227
if (pong -> player_left .target_y > pong -> player_left .y )
@@ -236,7 +236,7 @@ uint64_t pong_draw(struct pong *pong)
236
236
237
237
/* If the ball is in the middle, check if we need to lose and calculate
238
238
* the endpoint to avoid/hit the ball */
239
- if (roundf (pong -> ball_x .pos ) == 32.0f ) {
239
+ if (roundf (pong -> ball_x .pos ) == 32.0 ) {
240
240
struct pong_time cur_time = {};
241
241
242
242
pong_time_update (& cur_time );
@@ -259,7 +259,7 @@ uint64_t pong_draw(struct pong *pong)
259
259
pong -> player_left .target_y = rand_double (5 );
260
260
}
261
261
262
- clamp (& pong -> player_left .target_y , 0.0f , 24.0f );
262
+ clamp (& pong -> player_left .target_y , 0.0 , 24.0 );
263
263
} else if (pong -> ball_x .vel > 0 ) { /* Moving to the right */
264
264
pong -> player_right .target_y =
265
265
pong_calculate_end_point (pong , pong -> player_loss != 1 ) - 3 ;
@@ -270,10 +270,10 @@ uint64_t pong_draw(struct pong *pong)
270
270
pong -> player_right .target_y = rand_double (5 );
271
271
}
272
272
273
- clamp (& pong -> player_right .target_y , 0.0f , 24.0f );
273
+ clamp (& pong -> player_right .target_y , 0.0 , 24.0 );
274
274
}
275
275
276
- clamp (& pong -> ball_y .pos , 0.0f , 30.0f );
276
+ clamp (& pong -> ball_y .pos , 0.0 , 30.0 );
277
277
}
278
278
279
279
draw :
0 commit comments