58 lines
1.8 KiB
C
58 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* key.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/01/09 18:35:27 by cchauvet #+# #+# */
|
|
/* Updated: 2023/01/09 20:38:31 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "solong.h"
|
|
|
|
static void ft_case_update(char *new_pos, char *player_pos)
|
|
{
|
|
*new_pos = 'P';
|
|
*player_pos = '0';
|
|
}
|
|
|
|
void ft_move(t_data *data, char direction)
|
|
{
|
|
size_t x;
|
|
size_t y;
|
|
char *new_pos;
|
|
|
|
x = data->map->player_pos[0];
|
|
y = data->map->player_pos[1];
|
|
if (direction == 'L')
|
|
new_pos = &data->map->patern[x - 1][y];
|
|
if (direction == 'U')
|
|
new_pos = &data->map->patern[x][y + 1];
|
|
if (direction == 'D')
|
|
new_pos = &data->map->patern[x][y - 1];
|
|
if (direction == 'R')
|
|
new_pos = &data->map->patern[x + 1][y];
|
|
if (*new_pos == 'C')
|
|
data->map->nb_collectable++;
|
|
if (*new_pos == '0' || *new_pos == 'C')
|
|
ft_case_update(new_pos, &data->map->patern[y][x]);
|
|
ft_draw_map(data);
|
|
}
|
|
|
|
int ft_key(int keycode, t_data *data)
|
|
{
|
|
ft_printf("%d\n", keycode);
|
|
if (keycode == 65361)
|
|
ft_move(data, 'L');
|
|
else if (keycode == 65363)
|
|
ft_move(data, 'R');
|
|
else if (keycode == 65362)
|
|
ft_move(data, 'U');
|
|
else if (keycode == 65364)
|
|
ft_move(data, 'D');
|
|
return (0);
|
|
}
|
|
|