/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_shoot.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: joelecle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:22:32 by joelecle #+# #+# */ /* Updated: 2020/02/14 17:23:42 by joelecle ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include static void ft_hide_sprite(t_cub *cl) { int64_t i; int64_t j; uint8_t stop; i = -1; j = -1; stop = 0; while (++i < FT_TOTAL_SPRT - 5) { while (++j < 4096) { if (cl->sprites[i][j].s_pos_x == cl->rlist.sqx && cl->sprites[i][j].s_pos_y == cl->rlist.sqy) { stop = 1; break ; } } if (stop == 1) break ; j = -1; } cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] = '0'; cl->sprites[i][j].s_pos_x = 0; cl->sprites[i][j].s_pos_y = 0; } static int8_t ft_weap_range(t_cub *cl) { if (cl->plist.handles_weapon == 0 && sqrtf(powf(cl->plist.pos_x - cl->rlist.sqx, 2) + powf(cl->plist.pos_y - cl->rlist.sqy, 2)) > 1.6) return (0); return (1); } static void ft_set_sq(t_cub *cl) { if (cl->rlist.x_side_dist < cl->rlist.y_side_dist) { cl->rlist.x_side_dist += cl->rlist.x_delta_dist; cl->rlist.sqy += cl->mlist.x_step; cl->rlist.side = 0; } else { cl->rlist.y_side_dist += cl->rlist.y_delta_dist; cl->rlist.sqx += cl->mlist.y_step; cl->rlist.side = 1; } } static void ft_hitscan(t_cub *cl, uint16_t hit) { while (hit == 0) { ft_set_sq(cl); if (ft_ischarset(FT_CHRST_SPRITES, cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx]) && ft_weap_range(cl)) { hit = 1; ft_hide_sprite(cl); } else if (cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] == 'e' && ft_weap_range(cl)) { hit = 1; ft_damage_bad_boy(cl); } else if (cl->mlist.map[cl->rlist.sqy][cl->rlist.sqx] == '1') hit = 1; } } void ft_shoot(t_cub *cl) { t_player *pl; pl = &cl->plist; cl->rlist.y_ray_pos = pl->pos_y; cl->rlist.x_ray_pos = pl->pos_x; cl->rlist.y_ray_dir = -pl->dir_y; cl->rlist.x_ray_dir = pl->dir_x; cl->rlist.sqy = (uint64_t)cl->rlist.y_ray_pos; cl->rlist.sqx = (uint64_t)cl->rlist.x_ray_pos; ft_detection_init_x(cl); ft_detection_init_y(cl); ft_hitscan(cl, 0); }