aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-23 18:48:21 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-23 18:48:21 +0100
commit093e84b76c597015e89dddae8e51faae16feaf62 (patch)
tree66587b79153af48fb2aa8729ba8ca2c8d2d011e1
parentFixed sprite shadows (diff)
parentGonna merge (diff)
download42-cub3d-093e84b76c597015e89dddae8e51faae16feaf62.tar.gz
42-cub3d-093e84b76c597015e89dddae8e51faae16feaf62.tar.bz2
42-cub3d-093e84b76c597015e89dddae8e51faae16feaf62.tar.xz
42-cub3d-093e84b76c597015e89dddae8e51faae16feaf62.tar.zst
42-cub3d-093e84b76c597015e89dddae8e51faae16feaf62.zip
Merge branch 'hitscan'
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h3
-rw-r--r--src/ft_detect.c4
-rw-r--r--src/ft_extra_keys.c3
-rw-r--r--src/ft_get_sprite_spawns.c4
-rw-r--r--src/ft_shoot.c67
6 files changed, 79 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 5eb7f84..02e9b07 100644
--- a/Makefile
+++ b/Makefile
@@ -128,6 +128,7 @@ SRCS_NAME += ft_draw_ammo_caption.c
SRCS_NAME += ft_draw_map_back.c
SRCS_NAME += ft_draw_ammo_back.c
SRCS_NAME += ft_draw_ammo_bar.c
+SRCS_NAME += ft_shoot.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index faf990b..25b80ee 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -162,6 +162,8 @@ uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist);
void ft_castray(t_cub *cl);
void ft_choose_tex(t_cub *clist);
void ft_detect(t_cub *cl);
+void ft_detection_init_x(t_cub *cl);
+void ft_detection_init_y(t_cub *cl);
void ft_floor_cast(t_cub *cl);
void ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl);
@@ -227,5 +229,6 @@ void ft_find_item(t_player *pl, t_map *ml, t_cub *cl);
int8_t ft_switch_weap_one(t_cub *cl);
int8_t ft_switch_weap_two(t_cub *cl);
int8_t ft_switch_weap_three(t_cub *cl);
+void ft_shoot(t_cub *cl, uint16_t center);
# endif
diff --git a/src/ft_detect.c b/src/ft_detect.c
index 7ec0473..0ef8831 100644
--- a/src/ft_detect.c
+++ b/src/ft_detect.c
@@ -14,7 +14,7 @@
#include <cub3d.h>
#include <math.h>
-static void
+void
ft_detection_init_y(t_cub *cl)
{
cl->rlist.y_delta_dist = sqrt(1 + (cl->rlist.x_ray_dir *
@@ -34,7 +34,7 @@ static void
}
}
-static void
+void
ft_detection_init_x(t_cub *cl)
{
cl->rlist.x_delta_dist = sqrt(1 + (cl->rlist.y_ray_dir *
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index 0ccf3fc..f8a6db8 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -12,8 +12,10 @@
#include <cub3d.h>
#include <stdint.h>
+#include <stdio.h>
#include <math.h>
#include <time.h>
+#include <libft.h>
#include <pthread.h>
int
@@ -82,6 +84,7 @@ int
clist->plist.ammo[w_id] -= w_id;
clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx);
clist->plist.fire = 1;
+ ft_shoot(clist, clist->wlist.x_size / 2);
return (0);
}
else if (clist->plist.fire == 0 && clist->plist.ammo[w_id] <= 0)
diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c
index c24ba85..f4d7e1e 100644
--- a/src/ft_get_sprite_spawns.c
+++ b/src/ft_get_sprite_spawns.c
@@ -22,6 +22,7 @@ void
y = 0;
i = 0;
+ clist->mlist.sprite_nbr[s_n] = 0;
while (clist->mlist.map[++y])
{
while (clist->mlist.map[y][++x])
@@ -37,7 +38,7 @@ void
x = 0;
}
if (clist->sprites[s_n][(i - 1 < 0) ? (0) : (i - 1)].s_pos_x != 0
- && s_n + 1 < 7)
+ && s_n + 1 < 7)
{
ft_get_next_sprite(clist, s_n + 1, c + 1, 0);
}
@@ -53,6 +54,7 @@ void
x = 1;
y = 1;
i = 0;
+ clist->mlist.sprite_nbr[0] = 0;
while (clist->mlist.map[y])
{
while (clist->mlist.map[y][x])
diff --git a/src/ft_shoot.c b/src/ft_shoot.c
new file mode 100644
index 0000000..084d8d2
--- /dev/null
+++ b/src/ft_shoot.c
@@ -0,0 +1,67 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_extra_keys.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:22:32 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <libft.h>
+#include <stdio.h>
+
+static void
+ ft_hitscan(t_cub *cl, uint16_t hit)
+{
+ while (hit == 0)
+ {
+ if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
+ {
+ cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
+ cl->rlist.sqx += cl->mlist.x_step;
+ cl->rlist.side = 0;
+ }
+ else
+ {
+ cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
+ cl->rlist.sqy += cl->mlist.y_step;
+ cl->rlist.side = 1;
+ }
+ if (ft_ischarset("23456",
+ cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ {
+ hit = 1;
+ cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] = '0';
+ ft_get_sprite_spawn(cl);
+ }
+ else if (ft_ischarset("1",
+ cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ hit = 1;
+ }
+}
+
+void
+ ft_shoot(t_cub *cl, uint16_t i)
+{
+ t_win *wl;
+ t_player *pl;
+
+ wl = &cl->wlist;
+ pl = &cl->plist;
+ pl->cam_x = 2 * i / (float)(wl->x_size) - 1;
+ cl->rlist.x_ray_pos = pl->pos_y;
+ cl->rlist.y_ray_pos = pl->pos_x;
+ cl->rlist.x_ray_dir = pl->dir_x + pl->plane_x *
+ pl->cam_x;
+ cl->rlist.y_ray_dir = pl->dir_y + pl->plane_y *
+ pl->cam_x;
+ cl->rlist.sqx = (int16_t)cl->rlist.x_ray_pos;
+ cl->rlist.sqy = (int16_t)cl->rlist.y_ray_pos;
+ ft_detection_init_x(cl);
+ ft_detection_init_y(cl);
+ ft_hitscan(cl, 0);
+}