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

static void
	ft_collision(float old_y, float old_x, t_player *pl, t_map *ml)
{
	const size_t	x = pl->pos_x;
	const size_t	y = pl->pos_y;

	if (ml->map[y][x] == '1')
	{
		pl->pos_y = old_y;
		pl->pos_x = old_x;
	}
}

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;

	i = 0;
	while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5)
	{
		cl->key_ptr[cl->key_input[i]](cl);
		ft_collision(old_y, old_x, cl->plist, cl->mlist);
		i++;
	}
	ft_draw_scene(cl);
	return (0);
}