commit adef6611598f04979e5690a768b873e6f3eb2e4a
parent bf99ee5e45e20f75539e34d4cae7a236a5638430
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 5 Jan 2023 08:00:46 +0900
change unclear while statements to usual for statements
Diffstat:
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/ex9/main.c b/ex9/main.c
@@ -199,22 +199,18 @@ game_play(void)
xi <= (int) player->p.x / BLOCK_SIZE + 1 &&
xi < WORLD_WIDTH;
xi++) {
- blc = blh[xi]->first;
- while (blc != NULL) {
+ for (blc = blh[xi]->first; blc != NULL; blc = blc->next) {
if (is_on_floor_before(player, blc->o)) {
player_is_falling = 0;
}
if (test_collision(player, blc->o))
append_ol(collidings, blc->o);
- blc = blc->next;
}
}
if (collidings->first != NULL) {
sort_ol(collidings, player);
- blc = collidings->first;
- while (blc != NULL) {
+ for (blc = collidings->first; blc != NULL; blc = blc->next) {
handle_collision_mf(player, blc->o);
- blc = blc->next;
}
}
free_ol(collidings);
@@ -243,28 +239,26 @@ game_play(void)
for (int xi = scroll_dst / BLOCK_SIZE;
xi < (WIN_WIDTH + scroll_dst) / BLOCK_SIZE + 1 &&
xi < WORLD_WIDTH; xi++) {
- blc = blh[xi]->first;
- while (blc != NULL) {
+ for (blc = blh[xi]->first; blc != NULL; blc = blc->next) {
x_draw_rectangle(0x00FF00,
blc->o->p.x - scroll_dst, blc->o->p.y, // position
blc->o->body.rectangle.w,
blc->o->body.rectangle.h);
- blc = blc->next;
}
}
x_draw_rectangle(0x009FFF,
player->p.x - scroll_dst, player->p.y, // position
player->body.rectangle.w, player->body.rectangle.h);
- flc = flh->first;
- if (0 <= flc->o->p.x - scroll_dst &&
- flc->o->p.x - scroll_dst < WIN_WIDTH) {
- while (flc != NULL) {
+ for (flc = flh->first; flc != NULL; flc = flc->next) {
+ if (0 <= flc->o->p.x - scroll_dst &&
+ flc->o->p.x - scroll_dst < WIN_WIDTH) {
x_draw_rectangle(0xFFFF00,
flc->o->p.x - scroll_dst, flc->o->p.y, // position
flc->o->body.rectangle.w,
flc->o->body.rectangle.h);
- flc = flc->next;
+ } else {
+ break;
}
}