aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_check_map_line.c2
-rw-r--r--src/ft_draw_hud.c2
-rw-r--r--src/ft_draw_map.c4
-rw-r--r--src/ft_draw_scene.c20
-rw-r--r--src/ft_draw_traps.c110
-rw-r--r--src/ft_draw_traps_extra.c44
-rw-r--r--src/ft_exit.c8
-rw-r--r--src/ft_floor_cast.c52
-rw-r--r--src/ft_floor_cast_inits.c32
-rw-r--r--src/ft_get_player_spawn.c1
-rw-r--r--src/ft_get_traps.c70
-rw-r--r--src/ft_hex_to_rgb.c11
-rw-r--r--src/ft_init_funptr.c4
-rw-r--r--src/ft_init_lists.c4
-rw-r--r--src/ft_init_map.c4
-rw-r--r--src/ft_init_s_ray.c2
-rw-r--r--src/ft_key_loop.c31
-rw-r--r--src/ft_raycasting.c21
-rw-r--r--src/ft_save_to_bmp.c7
-rw-r--r--src/ft_select_get.c6
-rw-r--r--src/ft_suffer_animation.c46
-rw-r--r--src/ft_tex_init.c97
-rw-r--r--src/ft_treat_args.c9
-rw-r--r--src/ft_warp_level.c27
24 files changed, 470 insertions, 144 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c
index 7fa68b7..c88e1f5 100644
--- a/src/ft_check_map_line.c
+++ b/src/ft_check_map_line.c
@@ -37,6 +37,8 @@ static int8_t
ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL);
return (-1);
}
+ if (line[i] == 'T')
+ clist->mlist.istraps = 1;
return (0);
}
diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c
index 4ae497a..486112d 100644
--- a/src/ft_draw_hud.c
+++ b/src/ft_draw_hud.c
@@ -65,7 +65,7 @@ static void
while (y < clist->wlist.y_size - (clist->mlist.map_h * scl) - 20)
{
*(int*)(clist->img.ptr +
- ((uint8_t)x * 4 + (y * clist->img.sizeline))) = col;
+ ((uint16_t)x * 4 + (y * clist->img.sizeline))) = col;
y++;
}
y = clist->wlist.y_size - (clist->mlist.map_h * scl) - 45;
diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c
index 232891c..fc2613b 100644
--- a/src/ft_draw_map.c
+++ b/src/ft_draw_map.c
@@ -49,13 +49,13 @@ void
{
while (map[y][x])
{
- if (ft_ischarset("1D", map[y][x]))
+ if (ft_ischarset("1", map[y][x]))
ft_draw_square(scale + 9 + (x * (scale)),
ft_y_offset(clist) - 9 + (y * (scale)), 0x00ca5422, clist);
else if (map[y][x] == '2')
ft_draw_square(scale + 9 + (x * (scale)),
ft_y_offset(clist) - 9 + (y * (scale)), 0x0033ccff, clist);
- else if (ft_ischarset("0LNSEW", map[y][x]))
+ else if (ft_ischarset("0LNSEWT", map[y][x]))
ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist)
- 9 + (y * (scale)), 0x006afa6a, clist);
x++;
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index 2cfa3f4..80cd1bc 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -41,28 +41,19 @@ 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);
- ft_castray(clist);
+ if (clist->doicast)
+ ft_castray(clist);
+ else
+ clist->doicast = 1;
if (clist->ishud)
- {
ft_draw_hud(clist);
- }
if (clist->mlist.isskybox)
ft_draw_skybox(clist);
- ft_calc_sprite(clist);
mlx_put_image_to_window(clist->wlist.wlx,
- clist->wlist.winptr, clist->img.img, 0, 0);
+ clist->wlist.winptr, clist->img.img, 0, 0);
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
@@ -73,7 +64,6 @@ void
clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
&clist->img.sizeline, &clist->img.endian);
ft_castray(clist);
- ft_calc_sprite(clist);
if (ft_save_to_bmp(clist) < 0)
ft_error(FT_RET_BMP_ERR, FT_ERR_WR_BMP, clist);
mlx_destroy_image(clist->wlist.wlx, clist->img.img);
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_exit.c b/src/ft_exit.c
index 97c9e02..e0093da 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -33,6 +33,7 @@ static void
ft_memdel((void**)&clist->mlist.ce_tex_path);
ft_memdel((void**)&clist->mlist.nlevel_path);
ft_memdel((void**)&clist->mlist.skybox_path);
+ ft_memdel((void**)&clist->mlist.traps_path);
ft_memdel((void**)&clist->mlist.music_path);
ft_memdel((void**)&clist->mlist.music_cmd);
ft_memdel((void**)&clist->mlist.mapl);
@@ -57,6 +58,12 @@ static void
mlx_destroy_image(clist->wlist.wlx, clist->tlist[4].img);
if (clist->mlist.isnlvl && clist->tlist[5].img)
mlx_destroy_image(clist->wlist.wlx, clist->tlist[5].img);
+ if (clist->mlist.isftex && clist->tlist[6].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img);
+ if (clist->mlist.isctex && clist->tlist[7].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img);
+ if (clist->mlist.istraps && clist->tlist[15].img)
+ mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img);
}
int
@@ -66,6 +73,7 @@ int
ft_del_tex(clist);
if (clist->wlist.inited)
{
+ mlx_destroy_image(clist->wlist.wlx, clist->img.img);
mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr);
clist->wlist.winptr = NULL;
}
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index 384f699..2eda9d8 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_raycasting.c :+: :+: :+: */
+/* ft_floor_cast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -16,23 +16,15 @@
static void
ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x)
{
- if (cl->mlist.darklvl > 0)
- {
- *(int*)(cl->img.ptr +
- (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl);
- }
- else
- {
- *(int*)(cl->img.ptr +
- (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb);
- }
+ *(int*)(cl->img.ptr +
+ (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl);
}
static void
ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl)
{
- float dist;
- float calc;
+ float dist;
+ float calc;
if ((dist = cl->rlist.row_dist) <= 0)
dist = 0.0001;
@@ -78,8 +70,6 @@ static void
{
ft_set_tex_xy(7, rl, cl);
}
- rl->x_floor += cl->mlist.x_floor_step;
- rl->y_floor += cl->mlist.y_floor_step;
if (cl->mlist.isftex)
ft_draw_extra_tex(6, y, x, cl);
else
@@ -91,28 +81,26 @@ static void
}
void
- ft_floor_cast(uint16_t y, t_cub *cl)
+ ft_floor_cast(t_cub *cl)
{
t_ray *rl;
uint16_t x;
+ uint16_t y;
rl = &cl->rlist;
- rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x;
- rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y;
- rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x;
- rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y;
- rl->p = y - cl->wlist.y_size / 2;
- cl->plist.pos_z = 0.5 * cl->wlist.y_size;
- rl->row_dist = cl->plist.pos_z / rl->p;
- cl->mlist.x_floor_step = rl->row_dist *
- (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size;
- cl->mlist.y_floor_step = rl->row_dist *
- (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size;
- rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir;
- rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir;
- x = 0;
- while (++x < cl->wlist.x_size)
+ y = (cl->wlist.y_size / 2) + 1;
+ while (++y < cl->wlist.y_size)
{
- ft_floor_cast_loop(y, x, rl, cl);
+ ft_floor_cast_inits(y, rl, cl);
+ x = -1;
+ while (++x < cl->wlist.x_size)
+ {
+ if (cl->rlist.wall_bz[x] <= y)
+ {
+ ft_floor_cast_loop(y, x, rl, cl);
+ }
+ rl->x_floor += cl->mlist.x_floor_step;
+ rl->y_floor += cl->mlist.y_floor_step;
+ }
}
}
diff --git a/src/ft_floor_cast_inits.c b/src/ft_floor_cast_inits.c
new file mode 100644
index 0000000..591eb24
--- /dev/null
+++ b/src/ft_floor_cast_inits.c
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_floor_cast_inits.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+void
+ ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl)
+{
+ rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x;
+ rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y;
+ rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x;
+ rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y;
+ rl->p = y - cl->wlist.y_size / 2;
+ cl->plist.pos_z = 0.5 * cl->wlist.y_size;
+ rl->row_dist = cl->plist.pos_z / rl->p;
+ cl->mlist.x_floor_step = rl->row_dist *
+ (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size;
+ cl->mlist.y_floor_step = rl->row_dist *
+ (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size;
+ rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir;
+ rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir;
+}
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_get_traps.c b/src/ft_get_traps.c
new file mode 100644
index 0000000..0235bb5
--- /dev/null
+++ b/src/ft_get_traps.c
@@ -0,0 +1,70 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_get_tex_nl.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */
+/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+void
+ ft_get_trap_spawn(t_cub *clist)
+{
+ size_t x;
+ size_t y;
+ uint8_t i;
+
+ x = 1;
+ y = 1;
+ i = 0;
+ while (clist->mlist.map[y])
+ {
+ while (clist->mlist.map[y][x])
+ {
+ if (clist->mlist.map[y][x] == 'T')
+ {
+ clist->mlist.traps_nbr++;
+ clist->traps[i].s_pos_x = x;
+ clist->traps[i].s_pos_y = y;
+ i++;
+ }
+ x++;
+ }
+ x = 1;
+ y++;
+ }
+}
+
+int8_t
+ ft_get_traps(char **words, t_cub *clist)
+{
+ if (!(*words) || !(*(words + 1)) || (*(words + 2)))
+ {
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS);
+ return (-1);
+ }
+ if (ft_check_ext(*(words + 1), ".xpm") < 0)
+ {
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
+ return (-1);
+ }
+ ft_memdel((void**)&clist->mlist.traps_path);
+ if (!(clist->mlist.traps_path = ft_strdup(*(words + 1))))
+ {
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
+ return (-1);
+ }
+ if (ft_check_not_found(clist->mlist.traps_path) < 0)
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_RD_TRAP);
+ return (-1);
+ }
+ return (0);
+}
diff --git a/src/ft_hex_to_rgb.c b/src/ft_hex_to_rgb.c
index 30332cc..1732473 100644
--- a/src/ft_hex_to_rgb.c
+++ b/src/ft_hex_to_rgb.c
@@ -13,6 +13,17 @@
#include <cub3d.h>
#include <stdint.h>
+t_rgb
+ ft_hex_to_og_rgb(uint32_t color)
+{
+ t_rgb rgb;
+
+ rgb.r = (color >> 16) & 255;
+ rgb.g = (color >> 8) & 255;
+ rgb.b = color & 255;
+ return (rgb);
+}
+
t_bmp_rgb
ft_hex_to_rgb(uint32_t color)
{
diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c
index 6bfa3f7..c299336 100644
--- a/src/ft_init_funptr.c
+++ b/src/ft_init_funptr.c
@@ -29,7 +29,8 @@ void
ft_sprintf(clist->ref[10], "MU");
ft_sprintf(clist->ref[11], "SH");
ft_sprintf(clist->ref[12], "SB");
- ft_bzero(clist->ref[13], 3);
+ ft_sprintf(clist->ref[13], "T");
+ ft_bzero(clist->ref[14], 3);
}
void
@@ -54,4 +55,5 @@ void
clist->get_ptr[10] = ft_get_music;
clist->get_ptr[11] = ft_get_darkness;
clist->get_ptr[12] = ft_get_skybox;
+ clist->get_ptr[13] = ft_get_traps;
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index bd2ae74..d480912 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -28,7 +28,7 @@ t_rgb
return (rgb);
}
-static t_player
+t_player
ft_init_player(void)
{
t_player plist;
@@ -43,6 +43,7 @@ static t_player
plist.dir_y = 0;
plist.plane_x = 0;
plist.plane_y = 0.66;
+ plist.life = 100;
return (plist);
}
@@ -73,6 +74,7 @@ static int8_t
cl->key_input[i] = -1;
cl->ishud = 0;
cl->isoldmus = 0;
+ cl->doicast = 1;
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index 27b4a39..867a5b0 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -29,6 +29,7 @@ static int8_t
!(mlist->ce_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->nlevel_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->skybox_path = (char*)ft_calloc(1, sizeof(char))) ||
+ !(mlist->traps_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->music_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) ||
@@ -60,6 +61,9 @@ int8_t
mlist->isnlvl = 0;
mlist->ismusic = 0;
mlist->isskybox = 0;
+ mlist->istraps = 0;
+ mlist->sprite_nbr = 0;
+ mlist->traps_nbr = 0;
mlist->darklvl = 0;
mlist->scale = 0;
mlist->nlx = 0;
diff --git a/src/ft_init_s_ray.c b/src/ft_init_s_ray.c
index e890d68..0d4ba96 100644
--- a/src/ft_init_s_ray.c
+++ b/src/ft_init_s_ray.c
@@ -11,6 +11,8 @@
/* ************************************************************************** */
#include <cub3d.h>
+#include <stdlib.h>
+#include <stddef.h>
t_ray
ft_init_s_ray(void)
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index d40de34..45ed379 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -12,6 +12,7 @@
#include <libft.h>
#include <cub3d.h>
+#include <mlx.h>
#include <stdint.h>
#include <stddef.h>
@@ -26,7 +27,7 @@ static uint64_t
return (pl->pos_x - (pl->dir_y * FT_COLL_MULT));
else if (key == 3)
return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2)));
- return (1);
+ return ((uint64_t)pl->pos_x);
}
static uint64_t
@@ -40,7 +41,7 @@ static uint64_t
return (pl->pos_y - (pl->dir_x * FT_COLL_MULT));
else if (key == 3)
return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2)));
- return (1);
+ return ((uint64_t)pl->pos_y);
}
static void
@@ -53,12 +54,20 @@ static void
pl = &cl->plist;
x = ft_find_x(key, pl);
y = ft_find_y(key, pl);
- if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][x]) ||
- cl->mlist.map[y][x] == '\0')
+ if (cl->mlist.map[y][x] == 'T')
{
- pl->pos_y = old_y;
- pl->pos_x = old_x;
+ pl->pos_x = old_x + ((old_x - x) / 3);
+ pl->pos_y = old_y + ((old_y - y) / 3);
+ ft_suffer_animation(cl);
+ x = ft_find_x(key, pl);
+ y = ft_find_y(key, pl);
}
+ if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[(uint64_t)old_y][x]) ||
+ cl->mlist.map[(uint64_t)old_y][x] == '\0')
+ pl->pos_x = old_x;
+ if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][(uint64_t)old_x]) ||
+ cl->mlist.map[y][(uint64_t)old_x] == '\0')
+ pl->pos_y = old_y;
}
int
@@ -75,14 +84,16 @@ int
ft_collision(old_y, old_x, cl->key_input[i], cl);
if (cl->mlist.isnlvl)
{
- if (ft_warp_level(cl) < 0)
- return (ft_exit(FT_RET_FAILED_STRUCTS, cl));
+ if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
+ (uint32_t)cl->plist.pos_y == cl->mlist.nly)
+ {
+ return ((ft_warp_level(cl) < 0) ?
+ (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0));
+ }
}
i++;
}
if (cl->key_input[0] != -1)
- {
ft_draw_scene(cl);
- }
return (0);
}
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 3cbd368..a0720ea 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -76,8 +76,9 @@ static void
if (cl->rlist.wall_t < 0)
cl->rlist.wall_t = 0;
cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2;
- if (cl->rlist.wall_b >= (float)wl->y_size)
+ if (cl->rlist.wall_b >= (int16_t)wl->y_size)
cl->rlist.wall_b = wl->y_size - 1;
+ cl->rlist.wall_bz[i] = cl->rlist.wall_b;
}
void
@@ -85,15 +86,13 @@ void
{
uint16_t i;
t_win *wl;
- float *dist_tab;
wl = &cl->wlist;
- i = (wl->y_size / 2) + 1;
- while (++i < wl->y_size)
- ft_floor_cast(i, cl);
- if (!(dist_tab = malloc(sizeof(float) * cl->wlist.x_size)))
+ if (!(cl->rlist.wall_dist_tab =
+ (float*)malloc(sizeof(float) * cl->wlist.x_size)))
return ;
- if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist.x_size)))
+ if (!(cl->rlist.wall_bz =
+ (int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t))))
return ;
i = 0;
while (i < wl->x_size)
@@ -102,8 +101,12 @@ void
ft_choose_tex(cl);
ft_calc_tex(cl);
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
- dist_tab[i] = cl->rlist.wall_dist;
- cl->rlist.wall_dist_tab = dist_tab;
+ cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
i++;
}
+ 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_save_to_bmp.c b/src/ft_save_to_bmp.c
index 90bbb1f..ae3a2b6 100644
--- a/src/ft_save_to_bmp.c
+++ b/src/ft_save_to_bmp.c
@@ -93,9 +93,10 @@ static int8_t
bmp_info.size_image = size;
if (!(fd = open(fname, O_RDWR | O_CREAT, 0644)))
return (-1);
- write(fd, &bmp_file, sizeof(t_bmp_file));
- write(fd, &bmp_info, sizeof(t_bmp_info));
- write(fd, bmp, size);
+ if (!write(fd, &bmp_file, sizeof(t_bmp_file)) ||
+ !write(fd, &bmp_info, sizeof(t_bmp_info)) ||
+ !write(fd, bmp, size))
+ return (-1);
close(fd);
return (0);
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index fe6bb3e..f748721 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -53,6 +53,10 @@ static int8_t
return (-1);
if (ret == 10 && (clist->mlist.music_path[0]))
return (-1);
+ if (ret == 12 && (clist->mlist.skybox_path[0]))
+ return (-1);
+ if (ret == 13 && (clist->mlist.traps_path[0]))
+ return (-1);
return (ret);
}
@@ -66,7 +70,7 @@ static int8_t
ret = 0;
while (ft_strncmp(words[0], clist->ref[ret], 3) && clist->ref[ret][0])
ret++;
- if (ret == 13)
+ if (ret == 14)
ret = FT_PARSE_END_RET;
ret = ft_check_exists(ret, clist);
ret = ft_check_exists_two(ret, clist);
diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c
new file mode 100644
index 0000000..b800a39
--- /dev/null
+++ b/src/ft_suffer_animation.c
@@ -0,0 +1,46 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_key_loop.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */
+/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <mlx.h>
+#include <stdint.h>
+#include <unistd.h>
+
+void
+ ft_suffer_animation(t_cub *cl)
+{
+ int32_t x;
+ int32_t y;
+ t_rgb rgb;
+
+ y = -1;
+ while (++y < (int32_t)cl->wlist.y_size)
+ {
+ x = -1;
+ while (++x < (int32_t)cl->wlist.x_size)
+ {
+ rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr +
+ (x * 4 + (y * cl->img.sizeline))));
+ rgb.r += 150;
+ rgb.g += 20;
+ rgb.b += 20;
+ *(int*)(cl->img.ptr +
+ (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb);
+ }
+ }
+ cl->plist.life -= 20;
+ if (cl->plist.life <= 0)
+ ft_exit(0, cl);
+ /* TODO death screen here */
+ cl->doicast = 0;
+}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index e27ffbe..30b738e 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -16,68 +16,69 @@
#include <mlx.h>
/*
-** 0 : no
-** 1 : so
-** 2 : ea
-** 3 : we
-** 4 : sprite
-** 5 : new level door
-** 6 : floor
-** 7 : ceil
+** 0 : no
+** 1 : so
+** 2 : ea
+** 3 : we
+** 4 : sprite 1
+** 5 : new level door
+** 6 : floor
+** 7 : ceil / skybox
+** 8 : sprite 2
+** 9 : sprite 3
+** 10 : sprite 4
+** 11 : sprite 5
+** 12 : sprite 6
+** 13 : sprite 7
+** 14 : sprite 8
+** 15 : trap
*/
static void
- ft_get_nlvl_img(t_cub *cl)
+ ft_wall_tex_init_norme_bis(t_cub *cl)
{
- cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- cl->mlist.nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h);
- cl->tlist[5].ptr = mlx_get_data_addr(cl->tlist[5].img,
- &cl->tlist[5].bpp, &cl->tlist[5].sizeline, &cl->tlist[5].endian);
-}
-
-static void
- ft_get_floor_tex(t_cub *cl)
-{
- cl->tlist[6].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- cl->mlist.fl_tex_path, &cl->tlist[6].img_w, &cl->tlist[6].img_h);
- cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img,
- &cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian);
-}
-
-static void
- ft_get_ceil_tex(t_cub *cl)
-{
- cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ if (cl->mlist.isctex)
+ {
+ cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
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,
- "./media/img/hey.xpm", &cl->tlist[8].img_w, &cl->tlist[8].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);
- cl->tlist[9].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- "./media/img/crapaud.xpm", &cl->tlist[9].img_w, &cl->tlist[9].img_h);
- cl->tlist[9].ptr = mlx_get_data_addr(cl->tlist[9].img,
- &cl->tlist[9].bpp, &cl->tlist[9].sizeline, &cl->tlist[9].endian);
+ cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img,
+ &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian);
+ }
+ if (cl->mlist.isskybox)
+ {
+ cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.skybox_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->walltexgood = 1;
}
static void
ft_wall_tex_init_norme(t_cub *cl)
{
if (cl->mlist.isnlvl)
- ft_get_nlvl_img(cl);
+ {
+ cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h);
+ cl->tlist[5].ptr = mlx_get_data_addr(cl->tlist[5].img,
+ &cl->tlist[5].bpp, &cl->tlist[5].sizeline, &cl->tlist[5].endian);
+ }
if (cl->mlist.isftex)
- ft_get_floor_tex(cl);
- if (cl->mlist.isctex)
- ft_get_ceil_tex(cl);
- if (cl->mlist.isskybox)
{
- cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- cl->mlist.skybox_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[6].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.fl_tex_path, &cl->tlist[6].img_w, &cl->tlist[6].img_h);
+ cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img,
+ &cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian);
}
- cl->walltexgood = 1;
+ if (cl->mlist.istraps)
+ {
+ cl->tlist[15].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.traps_path, &cl->tlist[15].img_w, &cl->tlist[15].img_h);
+ cl->tlist[15].ptr = mlx_get_data_addr(cl->tlist[15].img,
+ &cl->tlist[15].bpp, &cl->tlist[15].sizeline, &cl->tlist[15].endian);
+ }
+ ft_wall_tex_init_norme_bis(cl);
}
void
diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c
index a47f9f7..fe794d8 100644
--- a/src/ft_treat_args.c
+++ b/src/ft_treat_args.c
@@ -12,6 +12,7 @@
#include <libft.h>
#include <cub3d.h>
+#include <mlx.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
@@ -35,14 +36,14 @@ uint8_t
if (argc < 3)
{
if (ft_init_winptr(clist) < 0)
- {
return (ft_exit(FT_RET_FAILED_MLX, 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);
ft_draw_scene(clist);
if (clist->mlist.ismusic)
- {
ft_enable_music(clist);
- }
ft_hooks_and_loops(&clist->wlist, clist);
}
else if (argc == 3 && !ft_strncmp("--save", argv[2], 7))
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 4a02c2b..faaf322 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -34,6 +34,7 @@ static void
ft_memdel((void**)&ml->ce_tex_path);
ft_memdel((void**)&ml->nlevel_path);
ft_memdel((void**)&ml->skybox_path);
+ ft_memdel((void**)&ml->traps_path);
ft_memdel((void**)&ml->music_path);
ft_memdel((void**)&ml->music_cmd);
ft_memdel((void**)&ml->mapl);
@@ -46,26 +47,22 @@ static void
{
uint8_t i;
- cl->plist.pos_x = 0;
- cl->plist.pos_y = 0;
- cl->plist.pos_z = 0;
- cl->plist.start_x = 0;
- cl->plist.start_y = 0;
- cl->plist.cam_x = 0;
- cl->plist.dir_x = -1;
- cl->plist.dir_y = 0;
- cl->plist.plane_x = 0;
- cl->plist.plane_y = 0.66;
+ cl->plist = ft_init_player();
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
- i = 0;
- while (i <= 5)
+ i = -1;
+ while (++i <= 5)
{
mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img);
cl->tlist[i].img = NULL;
- i++;
}
+ if (cl->mlist.isftex && cl->tlist[6].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img);
+ if (cl->mlist.isctex && cl->tlist[7].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img);
+ if (cl->mlist.istraps && cl->tlist[15].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img);
}
static void
@@ -96,9 +93,6 @@ int8_t
char *tmp_mup;
uint8_t isoldmus;
- if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
- (uint32_t)cl->plist.pos_y == cl->mlist.nly)
- {
if (!(next_path = (char *)malloc((ft_strlen(
cl->mlist.nlevel_path) + 1) * sizeof(char))))
return (-1);
@@ -115,6 +109,5 @@ int8_t
ft_memdel((void**)&tmp_mup);
ft_wall_tex_init(cl);
ft_memdel((void**)&next_path);
- }
return (0);
}