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

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

static void
	ft_check_bad_boy_shoot(t_cub *cl)
{
	int8_t	i;

	i = 0;
	while (i < cl->mlist.sprite_nbr[13])
	{
		if (cl->bad_boy[i].does == 2)
		{
			cl->sfx[11].sfx_play(cl->sfx);
			if (FT_OS == 1)
				ft_macos_suffer_animation(FT_ENMY_DAMAGE_AMOUNT, cl);
			else
				ft_linux_suffer_animation(FT_ENMY_DAMAGE_AMOUNT, cl);
		}
		i++;
	}
}

int
	ft_key_loop(t_cub *cl)
{
	uint8_t			i;
	const float		old_y = cl->plist.pos_y;
	const float		old_x = cl->plist.pos_x;
	clock_t			begin_frame;

	i = 0;
	while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5)
	{
		ft_handle_keys(i, old_y, old_x, cl);
		i++;
	}
	ft_check_bad_boy_shoot(cl);
	cl->moves = (cl->key_input[0] == -1) ? (0) : (cl->moves);
	begin_frame = clock();
	ft_draw_scene(cl);
	ft_timings(begin_frame, cl);
	return (0);
}