1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_draw_handweap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */
/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <cub3d.h>
#include <stdint.h>
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);
}
|