aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_draw_scene.c5
-rw-r--r--src/ft_draw_traps.c110
-rw-r--r--src/ft_draw_traps_extra.c44
-rw-r--r--src/ft_get_player_spawn.c1
-rw-r--r--src/ft_raycasting.c1
-rw-r--r--src/ft_suffer_animation.c14
6 files changed, 163 insertions, 12 deletions
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index 39cdadc..80cd1bc 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -41,10 +41,6 @@ static int8_t
void
ft_draw_scene(t_cub *clist)
{
- /* clist->img.img = mlx_new_image(clist->wlist.wlx, */
- /* clist->wlist.x_size, clist->wlist.y_size); */
- /* clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, */
- /* &clist->img.sizeline, &clist->img.endian); */
if (clist->doicast)
ft_castray(clist);
else
@@ -58,7 +54,6 @@ void
if (clist->ishud && clist->mlist.isnlvl)
if (ft_put_stage(clist) < 0)
ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist);
- /* mlx_destroy_image(clist->wlist.wlx, clist->img.img); */
}
void
diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c
new file mode 100644
index 0000000..42f837b
--- /dev/null
+++ b/src/ft_draw_traps.c
@@ -0,0 +1,110 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_traps.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 <stdlib.h>
+#include <math.h>
+
+static void
+ ft_sort_traps_norme(float *dist_tab, int32_t it, t_cub *cl)
+{
+ uint32_t tmp;
+
+ tmp = 0;
+ if (dist_tab[it] > dist_tab[it + 1])
+ {
+ tmp = dist_tab[it];
+ dist_tab[it] = dist_tab[it + 1];
+ dist_tab[it + 1] = tmp;
+ tmp = cl->mlist.traps_order[it];
+ cl->mlist.traps_order[it] = cl->mlist.traps_order[it + 1];
+ cl->mlist.traps_order[it + 1] = tmp;
+ it = 0;
+ }
+}
+
+void
+ ft_sort_traps(t_cub *cl)
+{
+ float dist_tab[4096];
+ int32_t it;
+
+ it = 0;
+ while (it < cl->mlist.sprite_nbr)
+ {
+ dist_tab[it] = ((cl->plist.pos_x - cl->traps[it].s_pos_x) *
+ (cl->plist.pos_x - cl->traps[it].s_pos_x) +
+ (cl->plist.pos_y - cl->traps[it].s_pos_y) *
+ (cl->plist.pos_y - cl->traps[it].s_pos_y));
+ cl->mlist.traps_order[it] = it;
+ it++;
+ }
+ it = 0;
+ while (it < cl->mlist.traps_nbr)
+ {
+ ft_sort_traps_norme(dist_tab, it, cl);
+ }
+}
+
+static void
+ ft_put_trap(t_sprite *sprite, t_cub *cl)
+{
+ float dist;
+ float calc;
+
+ if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0)
+ dist = 0.0001;
+ calc = (dist * 0.1 * cl->mlist.darklvl);
+ 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[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y] / calc;
+ cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] =
+ (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y + 1] / calc;
+ cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] =
+ (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y + 2] / calc;
+ cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0;
+}
+
+void
+ ft_draw_traps(t_cub *cl, t_sprite *sprite)
+{
+ int32_t d;
+
+ sprite->x = sprite->drawstartx;
+ while (sprite->x < sprite->drawendx)
+ {
+ sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 +
+ sprite->spritescreenx)) * cl->tlist[15].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[15].img_h / 2) /
+ sprite->spriteheight) / 128;
+ if (sprite->transformy > 0 && cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y]
+ && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy)
+ {
+ ft_put_trap(sprite, cl);
+ }
+ sprite->y++;
+ }
+ sprite->x++;
+ }
+}
diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c
new file mode 100644
index 0000000..a2fd0ab
--- /dev/null
+++ b/src/ft_draw_traps_extra.c
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_traps_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 <stdlib.h>
+#include <math.h>
+
+void
+ ft_calc_trap(t_cub *cl)
+{
+ t_sprite sprite;
+ int32_t i;
+
+ i = 0;
+ while (i < cl->mlist.traps_nbr)
+ {
+ sprite = cl->traps[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_traps(cl, &sprite);
+ i++;
+ }
+}
diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c
index 6853313..ef2edd9 100644
--- a/src/ft_get_player_spawn.c
+++ b/src/ft_get_player_spawn.c
@@ -83,6 +83,7 @@ void
plist->start_y = plist->pos_y;
ft_get_start_side(clist->mlist.map[y][x], plist);
ft_get_sprite_spawn(clist);
+ ft_get_trap_spawn(clist);
return ;
}
x++;
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 2d6d197..a0720ea 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -106,6 +106,7 @@ void
}
ft_floor_cast(cl);
ft_calc_sprite(cl);
+ ft_calc_trap(cl);
ft_memdel((void**)&cl->rlist.wall_dist_tab);
ft_memdel((void**)&cl->rlist.wall_bz);
}
diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c
index 1a9b51a..b800a39 100644
--- a/src/ft_suffer_animation.c
+++ b/src/ft_suffer_animation.c
@@ -21,11 +21,9 @@ void
{
int32_t x;
int32_t y;
- int32_t col;
t_rgb rgb;
y = -1;
- col = 0x00880000;
while (++y < (int32_t)cl->wlist.y_size)
{
x = -1;
@@ -33,14 +31,16 @@ void
{
rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr +
(x * 4 + (y * cl->img.sizeline))));
- rgb.r += 120;
+ rgb.r += 150;
+ rgb.g += 20;
+ rgb.b += 20;
*(int*)(cl->img.ptr +
(x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb);
}
- /* if (y < (int32_t)cl->wlist.y_size / 2) */
- /* col += 0x00000000; */
- /* else */
- /* col -= 0x00000000; */
}
+ cl->plist.life -= 20;
+ if (cl->plist.life <= 0)
+ ft_exit(0, cl);
+ /* TODO death screen here */
cl->doicast = 0;
}