aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_loop.c
blob: a59a80c84c935729c5bf2fa9b2a4ba6c79167745 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   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>
#include <unistd.h>

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++;
	}
	 /* TODO: Don't kill me so fast */
	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);
	ft_get_fps_count(begin_frame, cl);
	return (0);
}