xlib_playground

Xlib playground for experiments.
Log | Files | Refs

commit 1398210a51b1df8735d22050a81fb28e39ef4447
parent 145f0b2a5d747f1aced705f45215b66b8bab5793
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 30 Dec 2022 19:57:44 +0900

draw linked listed objects

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

diff --git a/ex8/main.c b/ex8/main.c @@ -121,15 +121,13 @@ game_play(void) struct ObjectList *blc[WORLD_WIDTH] = {0}; // block list cursor int bi[WORLD_WIDTH] = {0}; - for (int xi = 0; xi < WORLD_WIDTH; xi++) { - blh[xi] = (struct ObjectList *) malloc(sizeof(struct ObjectList)); - blc[xi] = blh[xi]; - } - for (int i = 0; i < WORLD_WIDTH * WORLD_HEIGHT; i++) { if (world_map[i] == 'b') { int xi = i % WORLD_WIDTH; - if (bi[xi] > 0) { + if (bi[xi] == 0) { + blh[xi] = (struct ObjectList *) malloc(sizeof(struct ObjectList)); + blc[xi] = blh[xi]; + } else { blc[xi]->next = (struct ObjectList *)malloc(sizeof(struct ObjectList)); blc[xi] = blc[xi]->next; @@ -145,13 +143,12 @@ game_play(void) } else if (world_map[i] == 'p') { player = *create_object(i % WORLD_WIDTH * BLOCK_SIZE, i / WORLD_WIDTH * BLOCK_SIZE, - 0, 0, 0, 0, + 0, 0, 0, GRAVITY, BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE * BLOCK_SIZE); } } - while (next_menu == GAME_PLAY){ clock_gettime(CLOCK_MONOTONIC, &ts); t0 = ts.tv_nsec; @@ -163,11 +160,6 @@ game_play(void) t0 = ts.tv_nsec; for (int k = 0; k < SUB_TICK; k++) { - player_is_falling = object_is_falling(&player, block, NUM_BLOCK); - if (player_is_falling) - player.a.y = GRAVITY; - else - player.a.y = 0; next_tick(&player, 1e9 / FPS / SUB_TICK); // game over when fall out of the screen @@ -225,11 +217,15 @@ game_play(void) #endif x_clear_area(); - for (int i = 0; i < NUM_BLOCK; i++) { - x_draw_rectangle(0x00FF00, - block[i].p.x, block[i].p.y, // position - block[i].body.rectangle.w, - block[i].body.rectangle.h); + for (int xi = 0; xi < WORLD_WIDTH; xi++) { + blc[xi] = blh[xi]; + while (blc[xi] != NULL) { + x_draw_rectangle(0x00FF00, + blc[xi]->o->p.x, blc[xi]->o->p.y, // position + blc[xi]->o->body.rectangle.w, + blc[xi]->o->body.rectangle.h); + blc[xi] = blc[xi]->next; + } } x_draw_rectangle(0x009FFF, player.p.x, player.p.y, // position