Browse Source

exit when X ask to close window

master
nicolas-arnaud 2 years ago
parent
commit
18ac9ca03c
  1. 4
      Makefile
  2. 1
      includes/cub3d.h
  3. 1
      src/mlx/mlx_1.c
  4. 8
      src/mlx/mlx_2.c

4
Makefile

@ -29,13 +29,16 @@ all: $(NAME)
$(VERBOSE).SILENT:
$(LIBFT):
echo "Downloading narnaud/libft and making library"
bash -c "if [[ ! -d "libft" ]]; then git clone \
https://git.narnaud.net/nicolas-arnaud/Libft.git libft; fi"
${MAKE} -C libft/
cp libft/libft.a lib/
cp libft/libft.h includes/
echo
$(MLX):
echo "Downloading 42Paris/minilibx and making library"
bash -c "if [[ ! -d "mlx" ]]; then git clone \
https://github.com/42Paris/minilibx-linux.git mlx; fi"
${MAKE} -C mlx/
@ -46,6 +49,7 @@ ifeq ($(UNAME_S), Darwin)
cp mlx/libmlx.a lib/
endif
cp mlx/mlx.h includes/
echo
$(NAME): $(LIBFT) $(MLX) $(OBJS)
echo Making Cub3D...

1
includes/cub3d.h

@ -114,6 +114,7 @@ int mouse_move_hook(int x, int y, t_env *env);
int mouse_up_hook(int buton, int x, int y, t_env *env);
int update_hook(t_env *env);
void init_window(t_env *nv);
int exit_game(t_env *env);
int init_game(t_env *env);
// Utils

1
src/mlx/mlx_1.c

@ -92,5 +92,6 @@ int init_game(t_env *env)
mlx_hook(env->win, 2, 1L << 0, key_press_hook, env);
mlx_hook(env->win, 3, 1L << 1, key_release_hook, env);
mlx_hook(env->win, 6, 0L, mouse_move_hook, env);
mlx_hook(env->win, 17, 0L, exit_game, env);
return (EXIT_SUCCESS);
}

8
src/mlx/mlx_2.c

@ -12,12 +12,18 @@
#include "../../includes/cub3d.h"
int exit_game(t_env *env)
{
(void)env;
exit(EXIT_SUCCESS);
}
int key_press_hook(int keycode, t_env *env)
{
if (keycode == KEY_M)
env->minimap = !env->minimap;
else if (keycode == KEY_ECHAP)
exit(EXIT_SUCCESS);
exit_game(env);
else
env->controls[keycode] = 1;
return (1);

Loading…
Cancel
Save