42_cube3D/game/manage_keys.c

48 lines
1.6 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* manage_keys.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
2023-05-03 06:45:40 -04:00
/* Updated: 2023/05/03 12:44:41 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "game.h"
2023-05-02 09:39:16 -04:00
int movement(t_ply *ply, int key)
{
2023-05-03 06:45:40 -04:00
if (key == MLX_KEY_W)
2023-05-02 09:39:16 -04:00
ply->pos_y -= 0.1;
else if (key == MLX_KEY_S)
ply->pos_y += 0.1;
else if (key == MLX_KEY_D)
ply->pos_x += 0.1;
else if (key == MLX_KEY_A)
ply->pos_x -= 0.1;
return (1);
}
int manage_keys(mlx_key_data_t keys, t_game *game)
{
int is_moving;
is_moving = 0;
if (keys.key == MLX_KEY_ESCAPE)
mlx_close_window(game->mlx);
2023-05-02 09:39:16 -04:00
else if (keys.key == MLX_KEY_W
|| keys.key == MLX_KEY_S
|| keys.key == MLX_KEY_D
|| keys.key == MLX_KEY_A)
is_moving = movement(game->ply, keys.key);
/*else if (key.key == MLX_KEY_RIGHT)
game->ply->direc += 0.1;
else if (key.key == MLX_KEY_LEFT)
game->ply->direc -= 0.1;*/
if (is_moving)
return (1);
return (0);
}