diff options
-rw-r--r-- | inc/cub3d_structs.h | 4 | ||||
-rw-r--r-- | map/map_one.cub | 19 | ||||
-rw-r--r-- | map/map_two.cub | 70 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 45 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 46 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 36 |
6 files changed, 119 insertions, 101 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 7a30d09..8fba623 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; @@ -182,6 +183,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[4096]; int32_t traps_nbr; int32_t traps_order[512]; @@ -227,7 +229,7 @@ typedef struct s_cub struct s_rgb f_rgb; struct s_rgb c_rgb; struct s_img tlist[16]; - struct s_sprite sprites[4096]; + struct s_sprite sprites[8][4096]; struct s_sprite traps[512]; } t_cub; diff --git a/map/map_one.cub b/map/map_one.cub index a774b0a..b0eedb0 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -1,21 +1,28 @@ R 1400 900 -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 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 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.c b/src/ft_draw_sprite.c index faeec2b..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[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)); - 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 73b8959..f695896 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -13,6 +13,7 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <math.h> @@ -45,24 +46,33 @@ 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 < 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++; + } + 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++; } |