aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_suffer_animation.c
blob: 106537061c70deadcceb1b83ff28aa62b184e8de (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_key_loop.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: joelecle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/17 20:06:26 by joelecle          #+#    #+#             */
/*   Updated: 2020/02/17 20:06:29 by joelecle         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <mlx.h>
#include <stdint.h>

static void
	ft_get_damaged(uint16_t dmg, t_cub *cl)
{
	cl->plist.life -= dmg;
	if (cl->plist.life <= 0)
	{
		cl->isdead = 1;
		cl->sfx[0].sfx_play(cl->sfx);
		ft_death_screen(cl);
	}
	else
	{
		cl->sfx[3].sfx_play(cl->sfx);
	}
}

void
	ft_linux_suffer_animation(uint16_t dmg, t_cub *cl)
{
	int32_t	x;
	int32_t	y;

	y = -1;
	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);
	while (++y < (int32_t)cl->wlist.y_size)
	{
		x = -1;
		while (++x < (int32_t)cl->wlist.x_size)
			*(int*)(cl->img.ptr +
				(x * 4 + (y * cl->img.sizeline))) = 0x00880404;
	}
	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);
	ft_get_damaged(dmg, cl);
}

void
	ft_macos_suffer_animation(uint16_t dmg, t_cub *cl)
{
	int32_t	x;
	int32_t	y;
	t_rgb	rgb;

	y = -1;
	while (++y < (int32_t)cl->wlist.y_size)
	{
		x = -1;
		while (++x < (int32_t)cl->wlist.x_size)
		{
			rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr +
				(x * 4 + (y * cl->img.sizeline))));
			rgb.r += 150;
			rgb.g += 20;
			rgb.b += 20;
			*(int*)(cl->img.ptr +
				(x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(0, rgb, cl);
		}
	}
	ft_get_damaged(dmg, cl);
	cl->doicast = 0;
}