xlib_playground

Xlib playground for experiments.
Log | Files | Refs

commit 8ffa18bbfb20799020f4a99a1ec9d3ac8f858ff2
parent 8ab1c705d3044bf35335602858aa326e4fd51527
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 31 Dec 2022 12:14:06 +0900

add collision handling for linked list

Diffstat:
Mex8/main.c | 34++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/ex8/main.c b/ex8/main.c @@ -54,6 +54,7 @@ void receive_events(enum key_state[]); void handle_inputs(enum key_state[]); /* sort */ void sort_blocks(int colliding_blocks[], int distance[], int count); +void sort_ll(struct ObjectList *ol, struct Object *player); void start_menu(void) @@ -178,8 +179,37 @@ game_play(void) } - for (int i = 0; i < NUM_BLOCK; i++) - next_tick(&block[i], 1e9 / FPS / SUB_TICK); + struct ObjectList *collidings, *cur; + collidings = NULL; + for (int xi = (int) player.p.x / BLOCK_SIZE; + xi <= (int) player.p.x / BLOCK_SIZE + 1 && xi < WORLD_WIDTH; + xi++) { + blc[xi] = blh[xi]; + while (blc[xi] != NULL) { + if (test_collision(&player, blc[xi]->o)) { + if (collidings == NULL) { + collidings = (struct ObjectList *)malloc( + sizeof(struct ObjectList)); + collidings->o = NULL; + collidings->next = NULL; + cur = collidings; + } else { + cur->next = (struct ObjectList *)malloc( + sizeof(struct ObjectList)); + cur = cur->next; + cur->next = NULL; + } + cur->o = blc[xi]->o; + } + blc[xi] = blc[xi]->next; + } + } + //sort_ll(collidings, &player); + cur = collidings; + while (cur != NULL) { + handle_collision_mf(&player, cur->o); + cur = cur->next; + } int colliding_blocks[9]; int distance[9];