aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/\84
-rw-r--r--src/ft_draw_sprite.c45
-rw-r--r--src/ft_draw_sprite_extra.c51
-rw-r--r--src/ft_get_sprite.c37
-rw-r--r--src/ft_tex_init.c22
5 files changed, 200 insertions, 39 deletions
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 <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 faeec2b..effaf78 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..f6a148c 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>
@@ -40,29 +41,43 @@ 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)
{
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 - 1)
+ {
+ while (i < cl->mlist.sprite_nbr)
+ {
+ sprite = cl->sprites[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);
+ ft_init_sprite(cl, &sprite);
+ 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..a158940 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -13,6 +13,38 @@
#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)
+{
+ size_t x;
+ size_t y;
+ uint8_t i;
+
+ x = 0;
+ y = 0;
+ 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++;
+ }
+ }
+ 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++;
+ }
+}
void
ft_get_sprite_spawn(t_cub *clist)
@@ -31,9 +63,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 30b738e..0290a0c 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -13,6 +13,7 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
+#include <stdio.h>
#include <mlx.h>
/*
@@ -35,6 +36,23 @@
*/
static void
+ ft_next_sprite_init(t_cub *cl)
+{
+ uint16_t i;
+
+ i = 8;
+ 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
ft_wall_tex_init_norme_bis(t_cub *cl)
{
if (cl->mlist.isctex)
@@ -52,6 +70,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