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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_death_screen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: joelecle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:20:05 by joelecle #+# #+# */
/* Updated: 2020/02/14 17:20:06 by joelecle ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <cub3d.h>
#include <mlx.h>
#include <stdlib.h>
#include <unistd.h>
static void
ft_draw_death_screen(int32_t x_ratio, int32_t y_ratio, t_cub *cl)
{
int32_t x;
int32_t y;
y = 0;
while (y < (int32_t)cl->wlist.y_size)
{
x = 0;
cl->death_screen.tex_y = ((y * y_ratio) >> 16);
while (x < (int32_t)cl->wlist.x_size)
{
cl->death_screen.tex_x = ((x * x_ratio) >> 16);
cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
(uint8_t)cl->death_screen.ptr[cl->death_screen.tex_x * 4 + 4 *
cl->death_screen.img_w * cl->death_screen.tex_y];
cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
(uint8_t)cl->death_screen.ptr[cl->death_screen.tex_x * 4 + 4 *
cl->death_screen.img_w * cl->death_screen.tex_y + 1];
cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
(uint8_t)cl->death_screen.ptr[cl->death_screen.tex_x * 4 + 4 *
cl->death_screen.img_w * cl->death_screen.tex_y + 2];
x++;
}
y++;
}
}
static void
ft_calc_death_screen(t_cub *cl)
{
int32_t x_ratio;
int32_t y_ratio;
x_ratio = (int)((cl->death_screen.img_w << 16) / cl->wlist.x_size) + 1;
y_ratio = (int)((cl->death_screen.img_h << 16) / cl->wlist.y_size) + 1;
ft_draw_death_screen(x_ratio, y_ratio, cl);
}
void
ft_death_screen(t_cub *cl)
{
cl->death_screen.img = mlx_xpm_file_to_image(cl->wlist.wlx,
FT_DEATH_SCREEN_PATH, &cl->death_screen.img_w, &cl->death_screen.img_h);
cl->death_screen.ptr = mlx_get_data_addr(cl->death_screen.img,
&cl->death_screen.bpp, &cl->death_screen.sizeline,
&cl->death_screen.endian);
cl->img.img = mlx_new_image(cl->wlist.wlx,
cl->wlist.x_size, cl->wlist.y_size);
cl->img.ptr = mlx_get_data_addr(cl->img.img, &cl->img.bpp,
&cl->img.sizeline, &cl->img.endian);
ft_calc_death_screen(cl);
mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr,
cl->img.img, 0, 0);
mlx_destroy_image(cl->wlist.wlx, cl->img.img);
mlx_destroy_image(cl->wlist.wlx, cl->death_screen.img);
ft_death_hooks(&cl->wlist, cl);
}
|