/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_draw_handweap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */ /* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include static void ft_put_weapon_image(int8_t w_id, int16_t y, int16_t x, t_cub *cl) { *(cl->img.ptr + x * 4 + (cl->img.sizeline * y)) = *(cl->tweap[w_id].ptr + cl->tweap[w_id].tex_x * 4 + 4 * cl->tweap[w_id].img_w * cl->tweap[w_id].tex_y); *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 1) = *(cl->tweap[w_id].ptr + cl->tweap[w_id].tex_x * 4 + 4 * cl->tweap[w_id].img_w * cl->tweap[w_id].tex_y + 1); *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 2) = *(cl->tweap[w_id].ptr + cl->tweap[w_id].tex_x * 4 + 4 * cl->tweap[w_id].img_w * cl->tweap[w_id].tex_y + 2); } static int16_t ft_set_move(t_cub *cl) { static int8_t more = 0; static int8_t less = 39; if (more < 38) { if (!cl->moves) return (more); more += FT_BOUNCE_FACTOR; return (more); } else { if (!cl->moves) return (less); less -= FT_BOUNCE_FACTOR; if (less < 1) { more = 0; less = 39; return (more); } return (less); } } static void ft_put_handweap(int8_t w_id, int32_t y_ratio, int32_t x_ratio, t_cub *cl) { int16_t x; int16_t y; int16_t move; y = 0; move = (cl->plist.fire == 1) ? (0) : (ft_set_move(cl)); while (y < (int16_t)cl->wlist.y_size) { cl->tweap[w_id].tex_y = ((y * y_ratio) >> 16); cl->tweap[w_id].tex_y += move; x = 0; while (x < (int16_t)cl->wlist.x_size) { cl->tweap[w_id].tex_x = ((x * x_ratio) >> 16); cl->tweap[w_id].tex_x += move / 4; if (cl->tweap[w_id].ptr[cl->tweap[w_id].tex_x * 4 + 4 * cl->tweap[w_id].img_h * cl->tweap[w_id].tex_y]) ft_put_weapon_image(w_id, y, x, cl); x++; } y++; } } void ft_draw_handweap(t_cub *cl) { int32_t x_ratio; int32_t y_ratio; int8_t w_id; w_id = cl->plist.handles_weapon; w_id += (cl->plist.fire == 1) ? (1) : (0); x_ratio = (int32_t)(((cl->tweap[w_id].img_w - 50) << 16) / cl->wlist.x_size) + 1; y_ratio = (int32_t)(((cl->tweap[w_id].img_h - 50) << 16) / cl->wlist.y_size) + 1; ft_put_handweap(w_id, y_ratio, x_ratio, cl); }