aboutsummaryrefslogtreecommitdiffstats
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
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 '')
-rw-r--r--inc/cub3d.h2
-rw-r--r--map/map_one.cub10
-rw-r--r--src/ft_detect.c4
-rw-r--r--src/ft_extra_keys.c60
4 files changed, 69 insertions, 7 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index ee2da75..2465e48 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -152,6 +152,8 @@ uint8_t ft_use_args(int argc, const char *argv[],
void ft_castray(t_cub *cl);
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);
diff --git a/map/map_one.cub b/map/map_one.cub
index 1690c81..511492f 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,4 +1,4 @@
-R 1600 1000
+R 800 800
NO ./media/img/tex/wood_wall_1.xpm
SO ./media/img/tex/wood_wall_1.xpm
@@ -19,8 +19,8 @@ SH 2
1111111
111111111111000001
100000000+00222201
-10000E000T00333301
-100000000000444401
+1@000E000T00333301
+1!0000000000444401
100100000+00000001
101100000111000001
111111111111110011
@@ -30,8 +30,8 @@ SH 2
111101111111110111
100000001101010111
120202020200000011
-1@0000000000000011
-1!0000000000000011
+100000000000000011
+100000000000000011
120202020200000011
110000001101000111
111101111111010111
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 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);
}