From 02955219fd0a1bd42e3009f77911f5f258d59d34 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 9 Mar 2020 21:03:16 +0100 Subject: get next sprite --- inc/cub3d_structs.h | 3 ++- src/ft_draw_sprite.c | 8 ++++---- src/ft_draw_sprite_extra.c | 43 +++++++++++++++++++++++++------------------ src/ft_get_sprite.c | 35 +++++++++++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 25 deletions(-) diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index d650110..13f81fa 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -177,6 +177,7 @@ typedef struct s_map size_t map_w; size_t map_h; size_t mapl_len; + uint8_t sprite_var; int32_t sprite_nbr; int32_t sprite_order[12]; size_t line_chk; @@ -217,7 +218,7 @@ typedef struct s_cub struct s_rgb f_rgb; struct s_rgb c_rgb; struct s_img tlist[8]; - struct s_sprite sprites[12]; + struct s_sprite sprites[12][12]; } t_cub; # endif diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index faeec2b..fcb2166 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -43,10 +43,10 @@ void it = 0; while (it < cl->mlist.sprite_nbr) { - dist_tab[it] = ((cl->plist.pos_x - cl->sprites[it].s_pos_x) * - (cl->plist.pos_x - cl->sprites[it].s_pos_x) + - (cl->plist.pos_y - cl->sprites[it].s_pos_y) * - (cl->plist.pos_y - cl->sprites[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++; } diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 73b8959..f3cdf08 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -45,24 +45,31 @@ void { t_sprite sprite; int32_t i; + int32_t j; i = 0; - while (i < cl->mlist.sprite_nbr) - { - sprite = cl->sprites[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_height(cl, &sprite); - ft_sprite_width(cl, &sprite); - ft_draw_sprite(cl, &sprite); - i++; - } + j = 0; + while (j < cl->mlist.sprite_var) + { + while (i < cl->mlist.sprite_nbr) + { + sprite = cl->sprites[j][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_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_sprite(cl, &sprite); + i++; + } + i = 0; + j++; + } } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 10c6bdd..8174cae 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -14,6 +14,36 @@ #include #include + +void + ft_get_next_sprite(t_cub *clist, int s_n, char c) +{ + 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] == c) + { + clist->mlist.sprite_nbr++; + clist->sprites[s_n][i].s_pos_x = x; + clist->sprites[s_n][i].s_pos_y = y; + i++; + ft_get_next_sprite(clist, s_n++, c + 1); + } + x++; + } + x = 1; + y++; + } +} + void ft_get_sprite_spawn(t_cub *clist) { @@ -31,9 +61,10 @@ void if (ft_ischarset("2", clist->mlist.map[y][x])) { clist->mlist.sprite_nbr++; - clist->sprites[i].s_pos_x = x; - clist->sprites[i].s_pos_y = y; + clist->sprites[0][i].s_pos_x = x; + clist->sprites[0][i].s_pos_y = y; i++; + ft_get_next_sprite(clist, 1, '3'); } x++; } -- cgit v1.2.3 From b780107eb1fdf57b65d9bd664613de6835f9b962 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 9 Mar 2020 21:11:08 +0100 Subject: small changez, supposed to work, TODO --- src/ft_get_sprite.c | 1 + src/ft_tex_init.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 8174cae..c288b67 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -25,6 +25,7 @@ void x = 1; y = 1; i = 0; + clist->mlist.sprite_var++; while (clist->mlist.map[y]) { while (clist->mlist.map[y][x]) diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 38e4c77..9daa20d 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -51,6 +51,10 @@ static void cl->mlist.ce_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); + cl->tlist[8].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h); + cl->tlist[8].ptr = mlx_get_data_addr(cl->tlist[8].img, + &cl->tlist[8].bpp, &cl->tlist[8].sizeline, &cl->tlist[8].endian); } static void -- cgit v1.2.3 From 44387601203a68b359f80d2a0be9bf63179b41ef Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 9 Mar 2020 21:12:13 +0100 Subject: still retard --- inc/cub3d_structs.h | 2 +- map/map_one.cub | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 13f81fa..a2cf5b5 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -177,8 +177,8 @@ typedef struct s_map size_t map_w; size_t map_h; size_t mapl_len; - uint8_t sprite_var; int32_t sprite_nbr; + uint8_t sprite_var; int32_t sprite_order[12]; size_t line_chk; size_t map_start; diff --git a/map/map_one.cub b/map/map_one.cub index f4f9e91..212db65 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -12,7 +12,7 @@ F 50,190,124 SH 6 111111111111111111 -120000000011000001 +120003000011000001 10010E000000000201 101100000111000001 111111111111110011 -- cgit v1.2.3 From b252f8d58790381d5fbece9748e188d42e769aa5 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 10 Mar 2020 17:46:21 +0100 Subject: 2 sprites max ??? --- inc/cub3d_defines.h | 2 +- inc/cub3d_structs.h | 5 +++-- map/map_one.cub | 19 ++++++++++--------- src/ft_draw_sprite.c | 45 ++++++++++++++++++++++++++------------------- src/ft_draw_sprite_extra.c | 5 ++++- src/ft_tex_init.c | 6 +++++- 6 files changed, 49 insertions(+), 33 deletions(-) diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index edc3dec..b348a1c 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -115,7 +115,7 @@ enum */ # define FT_CHRST_VALID_PARSE "RNSEWFCLM" -# define FT_CHRST_MAP_ENTRY "012NSEWL " +# define FT_CHRST_MAP_ENTRY "01234NSEWL " # define FT_CHRST_SPAWN "NSEW" # define FT_CHRST_MAP_NON_WALL "02NESWL" # define FT_CHRST_COLLISION "12 " diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 20b64b5..1aaa1d5 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -87,6 +87,7 @@ typedef struct s_rgb typedef struct s_sprite { int32_t spritescreenx; + int32_t current_sprite; int32_t x; int32_t y; int32_t tex_x; @@ -180,7 +181,7 @@ typedef struct s_map size_t mapl_len; int32_t sprite_nbr; uint8_t sprite_var; - int32_t sprite_order[12]; + int32_t sprite_order[4096]; size_t line_chk; size_t map_start; uint8_t isspawn; @@ -219,7 +220,7 @@ typedef struct s_cub struct s_img img; struct s_rgb f_rgb; struct s_rgb c_rgb; - struct s_img tlist[8]; + struct s_img tlist[12]; struct s_sprite sprites[12][12]; } t_cub; diff --git a/map/map_one.cub b/map/map_one.cub index 212db65..724de7d 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -1,20 +1,21 @@ R 1000 700 -NO ./media/img/segfot_small.xpm -SO ./media/img/segfot_small.xpm -EA ./media/img/segfot_small.xpm -WE ./media/img/segfot_small.xpm +NO ./media/img/BRIQUASSES.xpm +SO ./media/img/BRIQUASSES_2.xpm +EA ./media/img/BRIQUASSE_3.xpm +WE ./media/img/MURLOL.xpm S ./media/img/pillar.xpm -C 50,100,200 -F 50,190,124 +C ./media/img/arrow1.xpm +F ./media/img/arrow2.xpm SH 6 111111111111111111 -120003000011000001 -10010E000000000201 -101100000111000001 +100000000002000001 +100000000003000001 +100100000004000201 +1011000N0111000001 111111111111110011 1000001 100001 1001001 100001 diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index fcb2166..fbe7961 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -39,17 +39,24 @@ void { float dist_tab[4096]; int32_t it; + int32_t jt; it = 0; - 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++; - } + jt = 0; + while (jt < cl->mlist.sprite_var) + { + 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)); + cl->mlist.sprite_order[it] = it; + it++; + } + it = 0; + jt++; + } it = 0; while (it < cl->mlist.sprite_nbr) { @@ -69,14 +76,14 @@ static void 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[4].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[4].img_h * sprite->tex_y] / calc; + (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc; cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = - (uint8_t)cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[4].img_h * sprite->tex_y + 1] / calc; + (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc; cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = - (uint8_t)cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[4].img_h * sprite->tex_y + 2] / calc; + (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc; cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0; } @@ -89,16 +96,16 @@ void while (sprite->x < sprite->drawendx) { sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + - sprite->spritescreenx)) * cl->tlist[4].img_w / sprite->spritewidth); + sprite->spritescreenx)) * cl->tlist[sprite->current_sprite].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[4].img_h / 2) / + sprite->tex_y = ((d * cl->tlist[sprite->current_sprite].img_h / 2) / sprite->spriteheight) / 128; - if (sprite->transformy > 0 && cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[4].img_h * sprite->tex_y] + if (sprite->transformy > 0 && cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) { ft_put_sprite(sprite, cl); diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index f3cdf08..45f0dd5 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -49,11 +50,13 @@ void i = 0; j = 0; - while (j < cl->mlist.sprite_var) + while (j < 4) { while (i < cl->mlist.sprite_nbr) { sprite = cl->sprites[j][i]; + sprite.current_sprite = (j == 0) ? 4 : j + 7; + printf("%d\n", j); 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 diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 6c9edce..e27ffbe 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -52,9 +52,13 @@ static void cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); cl->tlist[8].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h); + "./media/img/hey.xpm", &cl->tlist[8].img_w, &cl->tlist[8].img_h); cl->tlist[8].ptr = mlx_get_data_addr(cl->tlist[8].img, &cl->tlist[8].bpp, &cl->tlist[8].sizeline, &cl->tlist[8].endian); + cl->tlist[9].img = mlx_xpm_file_to_image(cl->wlist.wlx, + "./media/img/crapaud.xpm", &cl->tlist[9].img_w, &cl->tlist[9].img_h); + cl->tlist[9].ptr = mlx_get_data_addr(cl->tlist[9].img, + &cl->tlist[9].bpp, &cl->tlist[9].sizeline, &cl->tlist[9].endian); } static void -- cgit v1.2.3 From 7d7a0484dbd4b3c65b6c6d37f09337b13d69bc99 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 11 Mar 2020 18:53:10 +0100 Subject: close but no cigar --- map/map_one.cub | 2 +- map/map_two.cub | 70 ++++++++++------------------------------------ src/ft_draw_sprite_extra.c | 2 +- 3 files changed, 17 insertions(+), 57 deletions(-) diff --git a/map/map_one.cub b/map/map_one.cub index 724de7d..680f4f8 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -13,7 +13,7 @@ SH 6 111111111111111111 100000000002000001 -100000000003000001 +100000030002000001 100100000004000201 1011000N0111000001 111111111111110011 diff --git a/map/map_two.cub b/map/map_two.cub index 085b681..309485b 100644 --- a/map/map_two.cub +++ b/map/map_two.cub @@ -1,63 +1,23 @@ -R 1920 1024 +R 1280 800 NO ./media/img/linuz.xpm SO ./media/img/linuz.xpm EA ./media/img/linuz.xpm WE ./media/img/linuz.xpm -S ./media/img/linuz.xpm +S ./media/img/pillar.xpm SH 5 -C 50,100,200 -F 150,150,124 +C ./media/img/arrow1.xpm +F ./media/img/arrow2.xpm -111111111111111111111111111111111111111111111111111111 -1E0000000000001100000011000000110000001100000011000001 -100100000000000000000000000000000000000000000000000001 -101100000000010000000000000000000000000000000000000001 -111111111111111110000000000000000001111111111111110011 -100000000000001100000011000000110000001100000011000001 -100100000000000000000000000000000000000000000000000001 -101100000000011100000111000001110000011100000111000001 -100000000000000000000000000000000000000000000000000001 -100002000200020002000200020002000200020002000200020001 -100000000000000000000000000000000000000000000000000001 -110000000000110101001101010001000000000000000000010111 -100020000000000000000000000001111111111111111110000011 -100000000000000000000000000000000000000000000000000011 -110000000000110101001101010011010100110101001101010111 -111101100011111101111111011111110111111101111111010111 -101100000000010000000000000000000000000000000000000001 -101100000000010000000000000000000000000000000000000001 -101100011000010011001100110011001100110011001100110001 -101100000000010011001100110011001100110011001100110001 -101100011000110000000000000000000000000000000000000001 -101100000000100000000000000000000000000000000000000001 -101100011000100011001100110011001100110011001100110001 -101100000000100011001100110011001100110011001100110001 -101100011000100000000000000000000000000000000000000001 -101100000000100000000000000000000000000000000000000001 -101100011000100011001100110011001100110011001100110001 -101100000000100011001100110011001100110011001100110001 -101100011000100000000000000000000000000000000000000001 -101100000000100000000000000000000000000000000000000001 -101100011000100011001100110011001100110011001100110001 -101100000000100011001100110011001100110011001100110001 -101100011000100000000000000000000000000000000000000001 -101100000000100000000000000000000000000000000000000001 -101100011000100011001100110011001100110011001100110001 -101100000000100011001100110011001100110011001100110001 -101100011000100000000000000000000000000000000000000001 -101100000000010000000000000000000000000000000000000001 -101100011000010011001100110011001100110011001100110001 -101100000000010011001100110011001100110011001100110001 -101102020202010000000000000000000000000000000000000001 -101100000000010000000000000000000000000000000000000001 -101100002000010011001100110011001100110011001100110001 -101100000000010011001100110011001100110011001100110001 -101100002000010000000000000000000000000000000000000001 -101100000000010000000000000000000000000000000000000001 -101100002000010011001100110011001100110011001100010101 -101100000000010011001100110011001100110011001100010101 -101100000000010000000000000000000000000000000000000001 -101100000000010000000000000000000000000000000000000001 -111111111111111111111111111111111111111111111111111111 +111111111111111111111111111111111111 +100000000000000000000000000000000001 +100000000000030000000000000000000001 +100000000000000000000000000000000001 +10000000000002222222200W000000000001 +100000000000000000000000000000000001 +100000000000040000000000000000000001 +100000000000000000000000000000000001 +100000000000000000000000000000000001 +100000000000000000000000000000000001 +111111111111111111111111111111111111 diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 45f0dd5..f695896 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -50,7 +50,7 @@ void i = 0; j = 0; - while (j < 4) + while (j < 3) { while (i < cl->mlist.sprite_nbr) { -- cgit v1.2.3 From ca5b3689894013365f617cb5513372e6031e8ae7 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 11 Mar 2020 20:42:12 +0100 Subject: gang_gang --- inc/cub3d_defines.h | 2 +- map/map_one.cub | 6 ------ map/map_two.cub | 2 +- src/ft_draw_sprite_extra.c | 44 ++++++++++++++++++++++---------------------- src/ft_get_sprite.c | 2 +- src/ft_tex_init.c | 27 +++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 31 deletions(-) diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 6ab05c2..457f121 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -115,7 +115,7 @@ enum */ # define FT_CHRST_VALID_PARSE "RNSEWFCLMT" -# define FT_CHRST_MAP_ENTRY "012NSEWLT " +# define FT_CHRST_MAP_ENTRY "01234NSEWLT " # define FT_CHRST_SPAWN "NSEW" # define FT_CHRST_MAP_NON_WALL "02NESWLT" # define FT_CHRST_COLLISION "12 " diff --git a/map/map_one.cub b/map/map_one.cub index b0eedb0..29315e3 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -13,16 +13,10 @@ T ./media/img/spikes.xpm SH 4 111111111111111111 -<<<<<<< HEAD 100000000002000001 100000030002000001 100100000004000201 -1011000N0111000001 -======= -120000000011000001 -100100000000000201 101100000111000001 ->>>>>>> master 111111111111110011 1000001 100001 1001001 100001 diff --git a/map/map_two.cub b/map/map_two.cub index 309485b..8e4607f 100644 --- a/map/map_two.cub +++ b/map/map_two.cub @@ -14,7 +14,7 @@ F ./media/img/arrow2.xpm 100000000000000000000000000000000001 100000000000030000000000000000000001 100000000000000000000000000000000001 -10000000000002222222200W000000000001 +10000000000002020202000W000000000001 100000000000000000000000000000000001 100000000000040000000000000000000001 100000000000000000000000000000000001 diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index f695896..c1fa4aa 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -51,28 +51,28 @@ void i = 0; j = 0; while (j < 3) - { - while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][i]; - sprite.current_sprite = (j == 0) ? 4 : j + 7; - printf("%d\n", j); - 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_height(cl, &sprite); - ft_sprite_width(cl, &sprite); - ft_draw_sprite(cl, &sprite); - i++; + while (i < cl->mlist.sprite_nbr) + { + sprite = cl->sprites[j][i]; + sprite.current_sprite = (j == 0) ? 4 : j + 7; + /* printf("%d\n", sprite.current_sprite); */ + 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_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_sprite(cl, &sprite); + i++; + } + i = 0; + j++; } - i = 0; - j++; - } } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index c288b67..68c4f75 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -25,7 +25,6 @@ void x = 1; y = 1; i = 0; - clist->mlist.sprite_var++; while (clist->mlist.map[y]) { while (clist->mlist.map[y][x]) @@ -43,6 +42,7 @@ void x = 1; y++; } + clist->mlist.sprite_var += (clist->sprites[s_n][i].s_pos_x != 0); } void diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 30b738e..1a2ac76 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -13,6 +13,7 @@ #include #include #include +#include #include /* @@ -34,6 +35,28 @@ ** 15 : trap */ +static void + ft_next_sprite_init(t_cub *cl) +{ + uint16_t i; + + i = 8; + while (i < cl->mlist.sprite_var + 7) + { + cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, + "./media/img/hey.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); + cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, + &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); + i++; + printf("%d\n", i ); + cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, + "./media/img/crapaud.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); + cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, + &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); + i++; + } +} + static void ft_wall_tex_init_norme_bis(t_cub *cl) { @@ -52,6 +75,10 @@ static void &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); } cl->walltexgood = 1; + if (cl->mlist.sprite_var > 1) + { + ft_next_sprite_init(cl); + } } static void -- cgit v1.2.3 From 176c86dde0c19ffed0d4845003dbcace3f00b9d2 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Thu, 12 Mar 2020 15:08:06 +0100 Subject: 3 sprites but gns needs work :^) --- map/map_one.cub | 8 ++--- "src/\\" | 84 ++++++++++++++++++++++++++++++++++++++++++++++ src/ft_draw_sprite.c | 24 ++++++------- src/ft_draw_sprite_extra.c | 10 ++++-- src/ft_get_sprite.c | 22 ++++++------ src/ft_tex_init.c | 23 +++++-------- 6 files changed, 128 insertions(+), 43 deletions(-) create mode 100644 "src/\\" diff --git a/map/map_one.cub b/map/map_one.cub index 29315e3..990c27d 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -13,9 +13,9 @@ T ./media/img/spikes.xpm SH 4 111111111111111111 -100000000002000001 -100000030002000001 -100100000004000201 +123400000000000001 +1000E0000000000001 +100100000000000001 101100000111000001 111111111111110011 1000001 100001 @@ -24,7 +24,7 @@ SH 4 111101111111110111 110000001101010111 100020T00000000011 -100000T00000W00011 +100000T00000000011 110000T01101010111 111101111111010111 11111 1 1111 diff --git "a/src/\\" "b/src/\\" new file mode 100644 index 0000000..9e403c1 --- /dev/null +++ "b/src/\\" @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_sprite_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 +#include + +void + ft_sprite_height(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; + if (sprite->drawstarty < 0) + sprite->drawstarty = 0; + 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) + sprite->drawstartx = 0; + sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx; + if (sprite->drawendx >= (int)cl->wlist.x_size) + sprite->drawendx = cl->wlist.x_size - 1; +} + +void + ft_calc_sprite(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + int32_t j; + + i = 0; + j = 0; + printf("%d\n", cl->sprites[0][0].s_pos_x); + printf("%d\n", cl->sprites[1][0].s_pos_x); + printf("%d\n", cl->sprites[2][0].s_pos_x); + printf("%d\n", cl->sprites[3][0].s_pos_x); + cl->sprites[2][0].s_pos_x = 4; + cl->sprites[2][0].s_pos_y = 3; + while (j < cl->mlist.sprite_var) + { + while (i < cl->mlist.sprite_nbr) + { + sprite = cl->sprites[j][i]; + sprite.current_sprite = (j == 0) ? 4 : j + 7; + /* printf("j :%d curr : %d\n", j, sprite.current_sprite); */ + 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_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_sprite(cl, &sprite); + i++; + } + i = 0; + j++; + } +} diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index fbe7961..effaf78 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -43,20 +43,20 @@ void it = 0; jt = 0; - while (jt < cl->mlist.sprite_var) - { - while (it < cl->mlist.sprite_nbr) + while (jt < cl->mlist.sprite_var) { - 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)); - cl->mlist.sprite_order[it] = it; - it++; + 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)); + cl->mlist.sprite_order[it] = it; + it++; + } + it = 0; + jt++; } - it = 0; - jt++; - } it = 0; while (it < cl->mlist.sprite_nbr) { diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index c1fa4aa..0f923e7 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -50,13 +50,19 @@ void i = 0; j = 0; - while (j < 3) + printf("%d\n", cl->sprites[0][0].s_pos_x); + printf("%d\n", cl->sprites[1][0].s_pos_x); + printf("%d\n", cl->sprites[2][0].s_pos_x); + /* printf("%d\n", cl->sprites[3][0].s_pos_x); */ + /* cl->sprites[2][0].s_pos_x = 4; */ + /* cl->sprites[2][0].s_pos_y = 2; */ + while (j <= cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) { sprite = cl->sprites[j][i]; sprite.current_sprite = (j == 0) ? 4 : j + 7; - /* printf("%d\n", sprite.current_sprite); */ + /* printf("j :%d curr : %d\n", j, sprite.current_sprite); */ 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 diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 68c4f75..8e22075 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -13,7 +13,7 @@ #include #include #include - +#include void ft_get_next_sprite(t_cub *clist, int s_n, char c) @@ -28,17 +28,17 @@ void while (clist->mlist.map[y]) { while (clist->mlist.map[y][x]) + { + if (clist->mlist.map[y][x] == c) { - if (clist->mlist.map[y][x] == c) - { - clist->mlist.sprite_nbr++; - clist->sprites[s_n][i].s_pos_x = x; - clist->sprites[s_n][i].s_pos_y = y; - i++; - ft_get_next_sprite(clist, s_n++, c + 1); - } - x++; + clist->mlist.sprite_nbr++; + clist->sprites[s_n][i].s_pos_x = x; + clist->sprites[s_n][i].s_pos_y = y; + i++; + ft_get_next_sprite(clist, s_n++, c + 1); } + x++; + } x = 1; y++; } @@ -65,7 +65,7 @@ void clist->sprites[0][i].s_pos_x = x; clist->sprites[0][i].s_pos_y = y; i++; - ft_get_next_sprite(clist, 1, '3'); + ft_get_next_sprite(clist, 1, '3'); } x++; } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 1a2ac76..0290a0c 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -41,20 +41,15 @@ static void uint16_t i; i = 8; - while (i < cl->mlist.sprite_var + 7) - { - cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, - "./media/img/hey.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); - cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, - &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); - i++; - printf("%d\n", i ); - cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, - "./media/img/crapaud.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); - cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, - &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); - i++; - } + cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, + "./media/img/larry.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); + cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, + &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); + i++; + cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, + "./media/img/crapaud.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); + cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, + &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); } static void -- cgit v1.2.3 From 71d55e5448007f90239a65279d8dbb07ee7b092a Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Thu, 12 Mar 2020 16:26:46 +0100 Subject: NORMED AND FIXED .......!!! --- map/map_one.cub | 6 +++--- src/ft_draw_sprite_extra.c | 31 +++++++++++++++---------------- src/ft_get_sprite.c | 19 ++++++++++--------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/map/map_one.cub b/map/map_one.cub index 990c27d..a158afa 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -13,9 +13,9 @@ T ./media/img/spikes.xpm SH 4 111111111111111111 -123400000000000001 -1000E0000000000001 -100100000000000001 +100000002200000001 +1000E0003300000001 +100100004400000001 101100000111000001 111111111111110011 1000001 100001 diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 0f923e7..f6a148c 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -41,6 +41,19 @@ void sprite->drawendx = cl->wlist.x_size - 1; } +static void + ft_init_sprite(t_cub *cl, t_sprite *sprite) +{ + 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); +} + void ft_calc_sprite(t_cub *cl) { @@ -50,29 +63,15 @@ void i = 0; j = 0; - printf("%d\n", cl->sprites[0][0].s_pos_x); - printf("%d\n", cl->sprites[1][0].s_pos_x); - printf("%d\n", cl->sprites[2][0].s_pos_x); - /* printf("%d\n", cl->sprites[3][0].s_pos_x); */ - /* cl->sprites[2][0].s_pos_x = 4; */ - /* cl->sprites[2][0].s_pos_y = 2; */ - while (j <= cl->mlist.sprite_var) + while (j < cl->mlist.sprite_var - 1) { while (i < cl->mlist.sprite_nbr) { sprite = cl->sprites[j][i]; sprite.current_sprite = (j == 0) ? 4 : j + 7; - /* printf("j :%d curr : %d\n", j, sprite.current_sprite); */ 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_init_sprite(cl, &sprite); ft_sprite_height(cl, &sprite); ft_sprite_width(cl, &sprite); ft_draw_sprite(cl, &sprite); diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 8e22075..a158940 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -22,12 +22,12 @@ void size_t y; uint8_t i; - x = 1; - y = 1; + x = 0; + y = 0; i = 0; - while (clist->mlist.map[y]) + while (clist->mlist.map[++y]) { - while (clist->mlist.map[y][x]) + while (clist->mlist.map[y][++x]) { if (clist->mlist.map[y][x] == c) { @@ -35,14 +35,15 @@ void clist->sprites[s_n][i].s_pos_x = x; clist->sprites[s_n][i].s_pos_y = y; i++; - ft_get_next_sprite(clist, s_n++, c + 1); } - x++; } - x = 1; - y++; + x = 0; + } + if (clist->sprites[s_n][i - 1].s_pos_x != 0) + { + ft_get_next_sprite(clist, s_n + 1, c + 1); + clist->mlist.sprite_var++; } - clist->mlist.sprite_var += (clist->sprites[s_n][i].s_pos_x != 0); } void -- cgit v1.2.3