Skip to content

Commit 5c0b0ce

Browse files
committed
Don't use "f" suffix in double values
1 parent 8e86abc commit 5c0b0ce

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/samples/clock/pong.c

+36-36
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void pong_time_update(struct pong_time *pong_time)
5858

5959
static void pong_init_internal(struct pong *pong, ge_GIF *gif, bool reset)
6060
{
61-
double ball_y = rand_double(16.0f) + 8.0f;
61+
double ball_y = rand_double(16.0) + 8.0;
6262
struct {
6363
double y, target_y;
6464
} left, right;
@@ -73,8 +73,8 @@ static void pong_init_internal(struct pong *pong, ge_GIF *gif, bool reset)
7373

7474
*pong = (struct pong){
7575
.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},
7878
.player_left = {.y = 8, .target_y = ball_y},
7979
.player_right = {.y = 18, .target_y = ball_y},
8080
.player_loss = 0,
@@ -149,13 +149,13 @@ static double pong_calculate_end_point(const struct pong *pong, bool hit)
149149
x += vel_x;
150150
y += vel_y;
151151
if (hit) {
152-
if (x >= 60.0f || x <= 2.0f)
152+
if (x >= 60.0 || x <= 2.0)
153153
return y;
154154
} else {
155-
if (x >= 62.0f || x <= 0.0f)
155+
if (x >= 62.0 || x <= 0.0)
156156
return y;
157157
}
158-
if (y >= 30.0f || y <= 0.0f)
158+
if (y >= 30.0 || y <= 0.0)
159159
vel_y = -vel_y;
160160
}
161161
}
@@ -179,49 +179,49 @@ uint64_t pong_draw(struct pong *pong)
179179
pong->ball_x.pos += pong->ball_x.vel;
180180
pong->ball_y.pos += pong->ball_y.vel;
181181

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)) {
184184
pong->ball_x.vel = -pong->ball_x.vel;
185185
if (rand() % 4 > 0) {
186186
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;
191191

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);
194194
else
195-
pong->player_left.target_y += 1.0f + rand_double(3);
195+
pong->player_left.target_y += 1.0 + rand_double(3);
196196
} 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;
201201

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);
204204
else
205-
pong->player_left.target_y -= 1.0f + rand_double(3);
205+
pong->player_left.target_y -= 1.0 + rand_double(3);
206206
}
207207

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);
210210
}
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)) {
213213
pong_init_internal(pong, pong->gif, true);
214214
}
215215

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)
217217
pong->ball_y.vel = -pong->ball_y.vel;
218218

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);
222222
} 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);
225225
}
226226

227227
if (pong->player_left.target_y > pong->player_left.y)
@@ -236,7 +236,7 @@ uint64_t pong_draw(struct pong *pong)
236236

237237
/* If the ball is in the middle, check if we need to lose and calculate
238238
* 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) {
240240
struct pong_time cur_time = {};
241241

242242
pong_time_update(&cur_time);
@@ -259,7 +259,7 @@ uint64_t pong_draw(struct pong *pong)
259259
pong->player_left.target_y = rand_double(5);
260260
}
261261

262-
clamp(&pong->player_left.target_y, 0.0f, 24.0f);
262+
clamp(&pong->player_left.target_y, 0.0, 24.0);
263263
} else if (pong->ball_x.vel > 0) { /* Moving to the right */
264264
pong->player_right.target_y =
265265
pong_calculate_end_point(pong, pong->player_loss != 1) - 3;
@@ -270,10 +270,10 @@ uint64_t pong_draw(struct pong *pong)
270270
pong->player_right.target_y = rand_double(5);
271271
}
272272

273-
clamp(&pong->player_right.target_y, 0.0f, 24.0f);
273+
clamp(&pong->player_right.target_y, 0.0, 24.0);
274274
}
275275

276-
clamp(&pong->ball_y.pos, 0.0f, 30.0f);
276+
clamp(&pong->ball_y.pos, 0.0, 30.0);
277277
}
278278

279279
draw:

0 commit comments

Comments
 (0)