aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_death_hooks.c
blob: d856addc02708e9d7b9ace2a30e28449d96dcdf6 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_death_hooks.c                                   :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: joelecle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:28:52 by joelecle          #+#    #+#             */
/*   Updated: 2020/02/14 17:28:52 by joelecle         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

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

static int
	ft_death_key_event(int keycode, t_cub *clist)
{
	const int32_t	tmp_code = keycode;

	keycode = ft_convert_keycode(tmp_code);
	if (keycode == FT_ESC_KEY)
		return (ft_exit(0, (clist)));
	if (keycode == FT_RET_KEY)
	{
		if (ft_warp_level(clist->mlist.filename, clist) < 0)
			return (ft_alloc_error(clist));
		ft_draw_scene(clist);
		ft_hooks_and_loops(&clist->wlist, clist);
		return (0);
	}
	return (0);
}

static int
	ft_death_key_loop(t_cub *cl)
{
	(void)cl;
	return (0);
}

void
	ft_death_hooks(t_win *wl, t_cub *cl)
{
	mlx_hook(wl->winptr, 2, (1L << 0), ft_death_key_event, cl);
	mlx_loop_hook(wl->wlx, ft_death_key_loop, cl);
	mlx_loop(wl->wlx);
}