diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2020-03-12 15:08:06 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2020-03-12 15:08:06 +0100 |
commit | 176c86dde0c19ffed0d4845003dbcace3f00b9d2 (patch) | |
tree | 516524a2d00ec35f223de73a6c1c852a53ee858d | |
parent | gang_gang (diff) | |
download | 42-cub3d-176c86dde0c19ffed0d4845003dbcace3f00b9d2.tar.gz 42-cub3d-176c86dde0c19ffed0d4845003dbcace3f00b9d2.tar.bz2 42-cub3d-176c86dde0c19ffed0d4845003dbcace3f00b9d2.tar.xz 42-cub3d-176c86dde0c19ffed0d4845003dbcace3f00b9d2.tar.zst 42-cub3d-176c86dde0c19ffed0d4845003dbcace3f00b9d2.zip |
3 sprites but gns needs work :^)
Diffstat (limited to '')
-rw-r--r-- | map/map_one.cub | 8 | ||||
-rw-r--r-- | src/\ | 84 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 24 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 10 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 22 | ||||
-rw-r--r-- | src/ft_tex_init.c | 23 |
6 files changed, 128 insertions, 43 deletions
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 @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_sprite_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +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 <libft.h> #include <cub3d.h> #include <stdint.h> - +#include <stdio.h> 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 |