aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_extra_keys.c
diff options
context:
space:
mode:
authorsalaaad2 <arthudurant263@gmail.com>2020-03-20 20:30:35 +0100
committersalaaad2 <arthudurant263@gmail.com>2020-03-20 20:30:35 +0100
commit14d4e44cb54758a2e9c045bddbe74479adef9f1d (patch)
treec0cc354238bb5b8008ad62ba4f00d25535211cf0 /src/ft_extra_keys.c
parentBetter bounce (diff)
download42-cub3d-14d4e44cb54758a2e9c045bddbe74479adef9f1d.tar.gz
42-cub3d-14d4e44cb54758a2e9c045bddbe74479adef9f1d.tar.bz2
42-cub3d-14d4e44cb54758a2e9c045bddbe74479adef9f1d.tar.xz
42-cub3d-14d4e44cb54758a2e9c045bddbe74479adef9f1d.tar.zst
42-cub3d-14d4e44cb54758a2e9c045bddbe74479adef9f1d.zip
R E A L I S T I C S H O O T I N G
Diffstat (limited to 'src/ft_extra_keys.c')
-rw-r--r--src/ft_extra_keys.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index a78f821..a801dee 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
@@ -68,6 +70,63 @@ int
return (0);
}
+void
+ft_hitscan(t_cub *cl)
+{
+ uint8_t hit;
+
+ hit = 0;
+ 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("234567",
+ cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ {
+ hit = 1;
+ puts("hit");
+ }
+ else if (ft_ischarset("1",
+ cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ {
+ hit = 1;
+ puts("wall (you missed retard)");
+ }
+ }
+}
+
+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);
+}
+
int
ft_space_key(t_cub *clist)
{
@@ -75,6 +134,7 @@ int
{
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);
}