40 lines
1.5 KiB
C
40 lines
1.5 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* manage_keys.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */
|
||
|
/* Updated: 2023/04/27 14:35:39 by erey-bet ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "game.h"
|
||
|
|
||
|
int movement(double *to_add, double add)
|
||
|
{
|
||
|
*to_add += add;
|
||
|
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);
|
||
|
else if (keys.key == MLX_KEY_W)
|
||
|
is_moving = movement(&game->ply->pos_y, -0.1);
|
||
|
else if (keys.key == MLX_KEY_S)
|
||
|
is_moving = movement(&game->ply->pos_y, 0.1);
|
||
|
else if (keys.key == MLX_KEY_D)
|
||
|
is_moving = movement(&game->ply->pos_x, 0.1);
|
||
|
else if (keys.key == MLX_KEY_A)
|
||
|
is_moving = movement(&game->ply->pos_x, -0.1);
|
||
|
if (is_moving)
|
||
|
return (1);
|
||
|
return (0);
|
||
|
}
|