diff options
-rw-r--r-- | inc/cub3d_structs.h | 3 | ||||
-rw-r--r-- | map/map_one.cub | 2 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 8 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 43 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 36 | ||||
-rw-r--r-- | src/ft_tex_init.c | 4 |
6 files changed, 70 insertions, 26 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index f1dfdfc..20b64b5 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -179,6 +179,7 @@ typedef struct s_map size_t map_h; size_t mapl_len; int32_t sprite_nbr; + uint8_t sprite_var; int32_t sprite_order[12]; size_t line_chk; size_t map_start; @@ -219,7 +220,7 @@ typedef struct s_cub struct s_rgb f_rgb; struct s_rgb c_rgb; struct s_img tlist[8]; - struct s_sprite sprites[4096]; + struct s_sprite sprites[12][12]; } t_cub; # endif 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 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..c288b67 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -14,6 +14,37 @@ #include <cub3d.h> #include <stdint.h> + +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; + clist->mlist.sprite_var++; + 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 +62,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++; } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 4cbdf73..6c9edce 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 |