aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h1
-rw-r--r--src/ft_extra_keys.c52
-rw-r--r--src/ft_shoot.c66
4 files changed, 68 insertions, 52 deletions
diff --git a/Makefile b/Makefile
index 60c2e2d..71f7fc0 100644
--- a/Makefile
+++ b/Makefile
@@ -114,6 +114,7 @@ SRCS_NAME += ft_draw_weapons.c
SRCS_NAME += ft_draw_weapons_extra.c
SRCS_NAME += ft_draw_handweap.c
SRCS_NAME += ft_switch_weapons.c
+SRCS_NAME += ft_shoot.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 2465e48..d426bba 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -204,5 +204,6 @@ void ft_get_fps_count(clock_t delta_time, t_cub *cl);
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);
+void ft_shoot(t_cub *cl, uint16_t center);
# endif
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index 96636a8..f5a501a 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -70,58 +70,6 @@ int
return (0);
}
-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);
-}
-
int
ft_space_key(t_cub *clist)
{
diff --git a/src/ft_shoot.c b/src/ft_shoot.c
new file mode 100644
index 0000000..ab820e6
--- /dev/null
+++ b/src/ft_shoot.c
@@ -0,0 +1,66 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* 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>
+
+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);
+}