diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_detect.c | 4 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 60 |
2 files changed, 62 insertions, 2 deletions
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); } |