From 575990647d8ee677ff9515ecb0c17da9fe66312f Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 18:57:40 +0100 Subject: fatfingered solution to the sprites problem, changes needed --- src/ft_draw_sprite.c | 60 ++++++++++++++++++++++++++++++---------------- src/ft_draw_sprite_extra.c | 3 ++- 2 files changed, 41 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 73f277a..ca38fcd 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -13,26 +13,30 @@ #include #include #include +#include #include #include -static void - ft_sort_sprites_norme(float *dist_tab, int32_t it, t_cub *cl) -{ - uint32_t tmp; +/* static void */ +/* ft_sort_sprites_norme(float *dist_tab, int32_t *i, t_cub *cl) */ +/* { */ +/* uint32_t tmp; */ +/* uint32_t it; */ - tmp = 0; - if (dist_tab[it] > dist_tab[it + 1]) - { - tmp = dist_tab[it]; - dist_tab[it] = dist_tab[it + 1]; - dist_tab[it + 1] = tmp; - tmp = cl->mlist.sprite_order[it]; - cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; - cl->mlist.sprite_order[it + 1] = tmp; - it = 0; - } -} +/* it = *i; */ +/* tmp = 0; */ +/* if (dist_tab[it] > dist_tab[it + 1]) */ +/* { */ +/* puts("qwe"); */ +/* tmp = dist_tab[it]; */ +/* dist_tab[it] = dist_tab[it + 1]; */ +/* dist_tab[it + 1] = tmp; */ +/* tmp = cl->mlist.sprite_order[it]; */ +/* cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; */ +/* cl->mlist.sprite_order[it + 1] = tmp; */ +/* it = 0; */ +/* } */ +/* } */ void ft_sort_sprites(t_cub *cl) @@ -40,6 +44,7 @@ void float dist_tab[4096]; int32_t it; int32_t jt; + int32_t tmp; it = 0; jt = 0; @@ -47,10 +52,11 @@ void { while (it < cl->mlist.sprite_nbr) { - dist_tab[it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * - (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + - (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * - (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); + dist_tab[it] = + ((cl->plist.pos_x - cl->sprites[0][it].s_pos_x) * + (cl->plist.pos_x - cl->sprites[0][it].s_pos_x) + + (cl->plist.pos_y - cl->sprites[0][it].s_pos_y) * + (cl->plist.pos_y - cl->sprites[0][it].s_pos_y)); cl->mlist.sprite_order[it] = it; it++; } @@ -60,8 +66,20 @@ void it = 0; while (it < cl->mlist.sprite_nbr) { - ft_sort_sprites_norme(dist_tab, it, cl); + if (dist_tab[it] < dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.sprite_order[it]; + cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; + cl->mlist.sprite_order[it + 1] = tmp; + it = 0; + } + it++; } + for (int i = 0; i < 4; i++) + printf("%d\n", cl->mlist.sprite_order[i]); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 2545ec0..696bdff 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -63,11 +63,12 @@ void i = 0; j = 0; + ft_sort_sprites(cl); while (j < cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][i]; + sprite = cl->sprites[j][cl->mlist.sprite_order[i]]; sprite.current_sprite = (j == 0) ? 4 : j + 7; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); -- cgit v1.2.3 From 8ca4c9563629c60122ba998ad64ad2d999d0902a Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:14:11 +0100 Subject: it just works (unpeu) --- src/ft_draw_sprite.c | 90 +++++++++++++++++++--------------------------- src/ft_draw_sprite_extra.c | 2 +- 2 files changed, 38 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index ca38fcd..c4e305e 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -17,69 +17,53 @@ #include #include -/* static void */ -/* ft_sort_sprites_norme(float *dist_tab, int32_t *i, t_cub *cl) */ -/* { */ -/* uint32_t tmp; */ -/* uint32_t it; */ +static void + ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) +{ + uint32_t tmp; + uint32_t it; -/* it = *i; */ -/* tmp = 0; */ -/* if (dist_tab[it] > dist_tab[it + 1]) */ -/* { */ -/* puts("qwe"); */ -/* tmp = dist_tab[it]; */ -/* dist_tab[it] = dist_tab[it + 1]; */ -/* dist_tab[it + 1] = tmp; */ -/* tmp = cl->mlist.sprite_order[it]; */ -/* cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; */ -/* cl->mlist.sprite_order[it + 1] = tmp; */ -/* it = 0; */ -/* } */ -/* } */ + it = *i; + tmp = 0; + if (dist_tab[it] < dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.sprite_order[j][it]; + cl->mlist.sprite_order[j][it] = cl->mlist.sprite_order[j][it + 1]; + cl->mlist.sprite_order[j][it + 1] = tmp; + it = 0; + } +} void ft_sort_sprites(t_cub *cl) { - float dist_tab[4096]; - int32_t it; - int32_t jt; - int32_t tmp; + float dist_tab[8][4096]; + uint16_t it; + uint16_t jt; - it = 0; - jt = 0; - while (jt < cl->mlist.sprite_var) + it = -1; + jt = -1; + while (++jt < cl->mlist.sprite_var) { - while (it < cl->mlist.sprite_nbr) + while (++it < cl->mlist.sprite_nbr) { - dist_tab[it] = - ((cl->plist.pos_x - cl->sprites[0][it].s_pos_x) * - (cl->plist.pos_x - cl->sprites[0][it].s_pos_x) + - (cl->plist.pos_y - cl->sprites[0][it].s_pos_y) * - (cl->plist.pos_y - cl->sprites[0][it].s_pos_y)); - cl->mlist.sprite_order[it] = it; - it++; + dist_tab[jt][it] = + ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * + (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); + cl->mlist.sprite_order[jt][it] = it; } - it = 0; - jt++; - } - it = 0; - while (it < cl->mlist.sprite_nbr) - { - if (dist_tab[it] < dist_tab[it + 1]) - { - tmp = dist_tab[it]; - dist_tab[it] = dist_tab[it + 1]; - dist_tab[it + 1] = tmp; - tmp = cl->mlist.sprite_order[it]; - cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; - cl->mlist.sprite_order[it + 1] = tmp; - it = 0; - } - it++; + it = -1; } - for (int i = 0; i < 4; i++) - printf("%d\n", cl->mlist.sprite_order[i]); + it = -1; + jt = -1; + while (++jt < cl->mlist.sprite_var) + while (++it < cl->mlist.sprite_nbr) + ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 696bdff..25c9c7a 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -68,7 +68,7 @@ void { while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][cl->mlist.sprite_order[i]]; + sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; sprite.current_sprite = (j == 0) ? 4 : j + 7; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); -- cgit v1.2.3 From 322f3191c5a76cf702d4ddd7b1122219be3f5779 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:24:29 +0100 Subject: fix norme --- src/ft_draw_sprite.c | 8 ++++---- src/ft_draw_sprite_extra.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index c4e305e..1294738 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -23,7 +23,7 @@ static void uint32_t tmp; uint32_t it; - it = *i; + it = *i; tmp = 0; if (dist_tab[it] < dist_tab[it + 1]) { @@ -61,9 +61,9 @@ void } it = -1; jt = -1; - while (++jt < cl->mlist.sprite_var) - while (++it < cl->mlist.sprite_nbr) - ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); + while (++jt < cl->mlist.sprite_var) + while (++it < cl->mlist.sprite_nbr) + ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 25c9c7a..d81913c 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -68,7 +68,7 @@ void { while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; + sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; sprite.current_sprite = (j == 0) ? 4 : j + 7; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); -- cgit v1.2.3 From b4bee5505af7e0cfb3681ed9b866d51bbc3f2690 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:26:15 +0100 Subject: fix norme2 --- src/ft_draw_sprite.c | 8 ++++---- src/ft_draw_sprite_extra.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 1294738..a196d96 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -18,10 +18,10 @@ #include static void - ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) + ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) { uint32_t tmp; - uint32_t it; + uint32_t it; it = *i; tmp = 0; @@ -51,7 +51,7 @@ void while (++it < cl->mlist.sprite_nbr) { dist_tab[jt][it] = - ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * + ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); @@ -60,7 +60,7 @@ void it = -1; } it = -1; - jt = -1; + jt = -1; while (++jt < cl->mlist.sprite_var) while (++it < cl->mlist.sprite_nbr) ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index d81913c..523bf3d 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -63,7 +63,7 @@ void i = 0; j = 0; - ft_sort_sprites(cl); + ft_sort_sprites(cl); while (j < cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) -- cgit v1.2.3 From 0cde149ec5e478c3d6283136065ff0129231c25d Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:43:16 +0100 Subject: bunchoshit --- src/ft_draw_sprite_extra.c | 2 +- src/ft_sort_s_t.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/ft_sort_s_t.c (limited to 'src') diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 523bf3d..6096522 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -64,6 +63,7 @@ void i = 0; j = 0; ft_sort_sprites(cl); + ft_sort_s_t(cl, cl->sprites); while (j < cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c new file mode 100644 index 0000000..f91804b --- /dev/null +++ b/src/ft_sort_s_t.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_s_t.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +void + ft_sort_s_t(cl, t_sprite *s[4096]) +{ + uint16_t i; + uint16_t j; + t_sprite tmp_s; + + i = 0; + j = 0; + while (i < cl->sprite_var) + { + if (s[i][0].) + { + + } + i++; + } +} -- cgit v1.2.3 From 0036fe1e23be842e8baa48162bcdb3bf632b02de Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 18 Mar 2020 18:59:59 +0100 Subject: gng --- src/ft_draw_sprite_extra.c | 12 +++--------- src/ft_draw_traps_extra.c | 3 +-- src/ft_sort_s_t.c | 24 ++++++++++++++++-------- 3 files changed, 20 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 6096522..9198e8d 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -17,7 +17,7 @@ #include void - ft_sprite_height(t_cub *cl, t_sprite *sprite) + ft_sprite_h_w(t_cub *cl, t_sprite *sprite) { sprite->spriteheight = abs((int)(cl->wlist.y_size / (sprite->transformy))); sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist.y_size / 2; @@ -26,11 +26,6 @@ void sprite->drawendy = sprite->spriteheight / 2 + cl->wlist.y_size / 2; if (sprite->drawendy >= (int)cl->wlist.y_size) sprite->drawendy = cl->wlist.y_size - 1; -} - -void - ft_sprite_width(t_cub *cl, t_sprite *sprite) -{ sprite->spritewidth = abs((int)(cl->wlist.x_size / (sprite->transformy))); sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; if (sprite->drawstartx < 0) @@ -40,6 +35,7 @@ void sprite->drawendx = cl->wlist.x_size - 1; } + static void ft_init_sprite(t_cub *cl, t_sprite *sprite) { @@ -63,7 +59,6 @@ void i = 0; j = 0; ft_sort_sprites(cl); - ft_sort_s_t(cl, cl->sprites); while (j < cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) @@ -73,8 +68,7 @@ void sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); ft_init_sprite(cl, &sprite); - ft_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); + ft_sprite_h_w(cl, &sprite); ft_draw_sprite(cl, &sprite); i++; } diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c index a2fd0ab..c524190 100644 --- a/src/ft_draw_traps_extra.c +++ b/src/ft_draw_traps_extra.c @@ -36,8 +36,7 @@ void + cl->plist.plane_x * sprite.spritey); sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * (1 + sprite.transformx / sprite.transformy); - ft_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); + ft_sprite_h_w(cl, &sprite); ft_draw_traps(cl, &sprite); i++; } diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index f91804b..270c974 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -13,24 +13,32 @@ #include #include #include +#include #include #include void - ft_sort_s_t(cl, t_sprite *s[4096]) + ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) { uint16_t i; - uint16_t j; - t_sprite tmp_s; + int32_t tmp; + t_sprite *tmp_s; i = 0; - j = 0; - while (i < cl->sprite_var) + tmp_s = ft_calloc(sizeof(t_sprite), 4096); + while (i < cl->mlist.sprite_var) { - if (s[i][0].) - { - + if (dist_tab[i][0] < dist_tab[i + 1][0]) + { + ft_memcpy(tmp_s, cl->sprites[i], 4096); + ft_memcpy(cl->sprites[i], cl->sprites[i + 1], 4096); + ft_memcpy(cl->sprites[i + 1], tmp_s, 4096); + tmp = dist_tab[i][0]; + dist_tab[i][0] = dist_tab[i + 1][0]; + dist_tab[i + 1][0] = tmp; + i = 0; } i++; + printf("qwe%d\n", i); } } -- cgit v1.2.3 From 967a795b455c97937504c2014184452637c0ec85 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 18 Mar 2020 19:02:35 +0100 Subject: ? --- src/ft_sort_s_t.c | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 src/ft_sort_s_t.c (limited to 'src') diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c deleted file mode 100644 index 270c974..0000000 --- a/src/ft_sort_s_t.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_sort_s_t.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ -/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include -#include -#include -#include -#include - -void - ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) -{ - uint16_t i; - int32_t tmp; - t_sprite *tmp_s; - - i = 0; - tmp_s = ft_calloc(sizeof(t_sprite), 4096); - while (i < cl->mlist.sprite_var) - { - if (dist_tab[i][0] < dist_tab[i + 1][0]) - { - ft_memcpy(tmp_s, cl->sprites[i], 4096); - ft_memcpy(cl->sprites[i], cl->sprites[i + 1], 4096); - ft_memcpy(cl->sprites[i + 1], tmp_s, 4096); - tmp = dist_tab[i][0]; - dist_tab[i][0] = dist_tab[i + 1][0]; - dist_tab[i + 1][0] = tmp; - i = 0; - } - i++; - printf("qwe%d\n", i); - } -} -- cgit v1.2.3 From 96c7c712f2cffeff9a4bae604715e0edfd6f758e Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 18 Mar 2020 19:10:35 +0100 Subject: cangelog, norme --- src/ft_draw_sprite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index a196d96..66d69e5 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -40,7 +40,7 @@ static void void ft_sort_sprites(t_cub *cl) { - float dist_tab[8][4096]; + float dist_tab[8][4096]; uint16_t it; uint16_t jt; -- cgit v1.2.3 From d114d2571a3808eba1f0a5038ad862b790a96074 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 21:35:54 +0100 Subject: In progress --- src/ft_check_map_line.c | 4 +- src/ft_check_missing.c | 3 ++ src/ft_draw_heals.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ src/ft_draw_heals_extra.c | 43 ++++++++++++++++++ src/ft_exit.c | 2 + src/ft_get_heal_spawn.c | 45 +++++++++++++++++++ src/ft_get_player_spawn.c | 1 + src/ft_get_traps.c | 4 +- src/ft_init_map.c | 2 + src/ft_raycasting.c | 1 + src/ft_tex_init.c | 10 ++++- src/ft_warp_level.c | 4 ++ 12 files changed, 224 insertions(+), 5 deletions(-) create mode 100644 src/ft_draw_heals.c create mode 100644 src/ft_draw_heals_extra.c create mode 100644 src/ft_get_heal_spawn.c (limited to 'src') diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index b9fd636..79e0297 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -37,8 +37,8 @@ static int8_t ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } - if (line[i] == 'T') - clist->mlist.istraps = 1; + clist->mlist.istraps = (line[i] == 'T') ? (1) : (0); + clist->mlist.isheals = (line[i] == '+') ? (1) : (0); ft_get_topsp(line[i], clist); return (0); } diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 4d06276..6bf41ab 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -59,6 +59,9 @@ static int if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 || ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0) return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist)); + if (ft_check_not_found(FT_HEAL_PACK_PATH) < 0 || + ft_check_ext(FT_HEAL_PACK_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_HEAL_PACK, clist)); return (ft_check_missing_sprites(clist)); } diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c new file mode 100644 index 0000000..8e2c842 --- /dev/null +++ b/src/ft_draw_heals.c @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +static void + ft_sort_heals_norme(float *dist_tab, int32_t it, t_cub *cl) +{ + uint32_t tmp; + + tmp = 0; + if (dist_tab[it] > dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.heals_order[it]; + cl->mlist.heals_order[it] = cl->mlist.heals_order[it + 1]; + cl->mlist.heals_order[it + 1] = tmp; + it = 0; + } +} + +void + ft_sort_heals(t_cub *cl) +{ + float dist_tab[4096]; + int32_t it; + + it = 0; + while (it < cl->mlist.sprite_nbr) + { + dist_tab[it] = ((cl->plist.pos_x - cl->heals[it].s_pos_x) * + (cl->plist.pos_x - cl->heals[it].s_pos_x) + + (cl->plist.pos_y - cl->heals[it].s_pos_y) * + (cl->plist.pos_y - cl->heals[it].s_pos_y)); + cl->mlist.heals_order[it] = it; + it++; + } + it = 0; + while (it < cl->mlist.heals_nbr) + { + ft_sort_heals_norme(dist_tab, it, cl); + } +} + +static void + ft_put_heal(t_sprite *sprite, t_cub *cl) +{ + float dist; + float calc; + + if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + dist = 0.0001; + calc = (dist * 0.1 * cl->mlist.darklvl); + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 1] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 2] / calc; +} + +void + ft_draw_heals(t_cub *cl, t_sprite *sprite) +{ + int32_t d; + + sprite->x = sprite->drawstartx; + while (sprite->x < sprite->drawendx) + { + sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + + sprite->spritescreenx)) + * cl->tlist[17].img_w / sprite->spritewidth); + sprite->y = sprite->drawstarty; + while (sprite->y < sprite->drawendy) + { + d = sprite->y * 256 - cl->wlist.y_size * 128 + + sprite->spriteheight * 128; + sprite->tex_y = ((d * cl->tlist[17].img_h / 2) / + sprite->spriteheight) / 128; + ft_printf("isheals %d\n", cl->mlist.isheals); + if (sprite->transformy > 0 + && cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) + ft_put_heal(sprite, cl); + sprite->y++; + } + sprite->x++; + } +} diff --git a/src/ft_draw_heals_extra.c b/src/ft_draw_heals_extra.c new file mode 100644 index 0000000..05ff830 --- /dev/null +++ b/src/ft_draw_heals_extra.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +void + ft_calc_heal(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + + i = 0; + while (i < cl->mlist.traps_nbr) + { + sprite = cl->heals[i]; + sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); + sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y + - cl->plist.dir_x * cl->plist.plane_y); + sprite.transformx = sprite.invdet * (cl->plist.dir_y * sprite.spritex + - cl->plist.dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * (-cl->plist.plane_y * sprite.spritex + + cl->plist.plane_x * sprite.spritey); + sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * + (1 + sprite.transformx / sprite.transformy); + ft_sprite_h_w(cl, &sprite); + ft_draw_heals(cl, &sprite); + i++; + } +} diff --git a/src/ft_exit.c b/src/ft_exit.c index 78b6d0a..390f234 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -86,6 +86,8 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img); if (clist->tlist[16].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img); + if (clist->mlist.isheals && clist->tlist[17].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img); ft_del_extra_sprites(clist); } diff --git a/src/ft_get_heal_spawn.c b/src/ft_get_heal_spawn.c new file mode 100644 index 0000000..142709b --- /dev/null +++ b/src/ft_get_heal_spawn.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_traps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */ +/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +void + ft_get_heal_spawn(t_cub *clist) +{ + size_t x; + size_t y; + uint8_t i; + + x = 1; + y = 1; + i = 0; + while (clist->mlist.map[y]) + { + while (clist->mlist.map[y][x]) + { + if (clist->mlist.map[y][x] == '+') + { + clist->mlist.heals_nbr++; + if (clist->mlist.heals_nbr > 64) + ft_map_error(FT_ERR_TOO_MUCH_HEALS, clist); + clist->heals[i].s_pos_x = x; + clist->heals[i].s_pos_y = y; + i++; + } + x++; + } + x = 1; + y++; + } +} diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index ef2edd9..1ba6437 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -84,6 +84,7 @@ void ft_get_start_side(clist->mlist.map[y][x], plist); ft_get_sprite_spawn(clist); ft_get_trap_spawn(clist); + ft_get_heal_spawn(clist); return ; } x++; diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c index b7d12e1..2d652f8 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_get_tex_nl.c :+: :+: :+: */ +/* ft_get_traps.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -31,6 +31,8 @@ void if (clist->mlist.map[y][x] == 'T') { clist->mlist.traps_nbr++; + if (clist->mlist.traps_nbr > 512) + ft_map_error(FT_ERR_TOO_MUCH_TRAPS, clist); clist->traps[i].s_pos_x = x; clist->traps[i].s_pos_y = y; i++; diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 8b97906..d610fac 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -89,8 +89,10 @@ int8_t mlist->ismusic = 0; mlist->isskybox = 0; mlist->istraps = 0; + mlist->isheals = 0; mlist->sprite_nbr = 0; mlist->traps_nbr = 0; + mlist->heals_nbr = 0; mlist->darklvl = 0; return (ft_init_map_norme(mlist)); } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index aa050c5..d805cdf 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -107,6 +107,7 @@ void ft_floor_cast(cl); ft_calc_sprite(cl); ft_calc_trap(cl); + ft_calc_heal(cl); ft_memdel((void*)&cl->rlist.wall_dist_tab); ft_memdel((void*)&cl->rlist.wall_bz); } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index fe8aadd..6486e87 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -36,6 +36,7 @@ ** 14 : sprite 9 ** 15 : trap ** 16 : HUD back +** 17 : heal pack */ static void @@ -79,9 +80,7 @@ static void &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) - { ft_next_sprite_init(cl); - } } static void @@ -108,6 +107,13 @@ static void cl->tlist[15].ptr = mlx_get_data_addr(cl->tlist[15].img, &cl->tlist[15].bpp, &cl->tlist[15].sizeline, &cl->tlist[15].endian); } + if (cl->mlist.isheals) + { + cl->tlist[17].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_HEAL_PACK_PATH, &cl->tlist[17].img_w, &cl->tlist[17].img_h); + cl->tlist[17].ptr = mlx_get_data_addr(cl->tlist[17].img, + &cl->tlist[17].bpp, &cl->tlist[17].sizeline, &cl->tlist[17].endian); + } ft_wall_tex_init_norme_bis(cl); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index fadbb2a..a2b6006 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -61,6 +61,10 @@ static void mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img); if (cl->mlist.istraps && cl->tlist[15].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); + if (cl->tlist[16].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[16].img); + if (cl->mlist.isheals && cl->tlist[17].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[17].img); ft_del_extra_sprites(cl); i = -1; while (++i < 8) -- cgit v1.2.3 From 8998478510fba3fd77bdc19a0b503643362d332c Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 21:38:00 +0100 Subject: Works fine --- src/ft_check_map_line.c | 4 ++-- src/ft_draw_heals.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 79e0297..50464a9 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -37,8 +37,8 @@ static int8_t ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } - clist->mlist.istraps = (line[i] == 'T') ? (1) : (0); - clist->mlist.isheals = (line[i] == '+') ? (1) : (0); + clist->mlist.istraps = (line[i] == 'T') ? (1) : (clist->mlist.istraps); + clist->mlist.isheals = (line[i] == '+') ? (1) : (clist->mlist.isheals); ft_get_topsp(line[i], clist); return (0); } diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c index 8e2c842..d51ae97 100644 --- a/src/ft_draw_heals.c +++ b/src/ft_draw_heals.c @@ -97,7 +97,6 @@ void sprite->spriteheight * 128; sprite->tex_y = ((d * cl->tlist[17].img_h / 2) / sprite->spriteheight) / 128; - ft_printf("isheals %d\n", cl->mlist.isheals); if (sprite->transformy > 0 && cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * cl->tlist[17].img_h * sprite->tex_y] -- cgit v1.2.3 From 8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 22:21:29 +0100 Subject: ok bav --- src/ft_find_item.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ft_get_traps.c | 2 +- src/ft_key_loop.c | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/ft_find_item.c (limited to 'src') diff --git a/src/ft_find_item.c b/src/ft_find_item.c new file mode 100644 index 0000000..782a24a --- /dev/null +++ b/src/ft_find_item.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_item.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +static uint16_t + ft_fetch_heals_id(uint64_t pos_y, uint64_t pos_x, t_cub *cl) +{ + uint16_t id; + + id = 0; + while (id <= 64) + { + if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x) + return (id); + id++; + } + return (0); +} + +void + ft_find_item(t_player *pl, t_map *ml, t_cub *cl) +{ + uint16_t id; + if (ft_ischarset(FT_CHRST_ITEM, + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) + { + if (ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] == '+' + && pl->life < 100) + { + pl->life += FT_HEAL_PACK_AMOUNT; + pl->life = (pl->life > 100) ? (100) : (pl->life); + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; + id = ft_fetch_heals_id((uint64_t)pl->pos_y, + (uint64_t)pl->pos_x, cl); + cl->heals[id].s_pos_x = 0; + cl->heals[id].s_pos_y = 0; + /* TODO: ft_sfx_heal(3) */ + } + } +} diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c index 2d652f8..fef3179 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -19,7 +19,7 @@ void { size_t x; size_t y; - uint8_t i; + uint16_t i; x = 1; y = 1; diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 0108202..e0177e2 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -89,6 +89,7 @@ int { ft_sfx_footstep(cl); ft_collision(old_y, old_x, cl->key_input[i], cl); + ft_find_item(&cl->plist, &cl->mlist, cl); if (cl->mlist.isnlvl) { if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && -- cgit v1.2.3 From 5be59b518283b4737949bcbea597068df43487dc Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 22:34:45 +0100 Subject: Bug fix --- src/ft_draw_heals_extra.c | 2 +- src/ft_find_item.c | 3 ++- src/ft_raycasting.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ft_draw_heals_extra.c b/src/ft_draw_heals_extra.c index 05ff830..62c64b0 100644 --- a/src/ft_draw_heals_extra.c +++ b/src/ft_draw_heals_extra.c @@ -23,7 +23,7 @@ void int32_t i; i = 0; - while (i < cl->mlist.traps_nbr) + while (i < cl->mlist.heals_nbr) { sprite = cl->heals[i]; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); diff --git a/src/ft_find_item.c b/src/ft_find_item.c index 782a24a..d00b62d 100644 --- a/src/ft_find_item.c +++ b/src/ft_find_item.c @@ -33,6 +33,7 @@ void ft_find_item(t_player *pl, t_map *ml, t_cub *cl) { uint16_t id; + if (ft_ischarset(FT_CHRST_ITEM, ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) { @@ -43,7 +44,7 @@ void pl->life = (pl->life > 100) ? (100) : (pl->life); ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; id = ft_fetch_heals_id((uint64_t)pl->pos_y, - (uint64_t)pl->pos_x, cl); + (uint64_t)pl->pos_x, cl); cl->heals[id].s_pos_x = 0; cl->heals[id].s_pos_y = 0; /* TODO: ft_sfx_heal(3) */ diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index d805cdf..2d7df79 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -106,8 +106,8 @@ void } ft_floor_cast(cl); ft_calc_sprite(cl); - ft_calc_trap(cl); ft_calc_heal(cl); + ft_calc_trap(cl); ft_memdel((void*)&cl->rlist.wall_dist_tab); ft_memdel((void*)&cl->rlist.wall_bz); } -- cgit v1.2.3