Cub3D
Loading...
Searching...
No Matches
find_player_and_set.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* find_player_and_set.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: hnagasak <hnagasak@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/11/16 03:27:33 by kamitsui #+# #+# */
9/* Updated: 2024/12/18 02:12:48 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
21static void set_position_and_direction(
22 t_player *player, t_point grid, char direction)
23{
24 player->view_point.x = grid.x + 0.5;
25 player->view_point.y = grid.y + 0.5;
26 set_direction(direction, player);
27}
28
32static bool is_player_position(char map_point)
33{
34 return (map_point == 'N' || map_point == 'S'
35 || map_point == 'W' || map_point == 'E');
36}
37
38bool is_valid_char(char map_point)
39{
40 return (map_point == '1' || map_point == '0' || map_point == ' ');
41}
42
43int find_player_and_set(
44 char **data, t_point grid, t_parse *parse, t_player *player)
45{
46 if (is_player_position(data[grid.y][grid.x]) == true)
47 {
48 if ((parse->flag & BIT_PLAYER) > 0x00)
49 {
50 ft_eprintf("%s%s",
51 ERR_PROMPT, EMSG_MAP_PLAYER_MULTI);
52 return (EXIT_FAILURE);
53 }
54 parse->flag |= BIT_PLAYER;
55 parse->player_grid = grid;
56 set_position_and_direction(player, grid, data[grid.y][grid.x]);
57 data[grid.y][grid.x] = '0';
58 }
59 else
60 {
61 if (is_valid_char(data[grid.y][grid.x]) != true)
62 {
63 ft_eprintf("%s%s", ERR_PROMPT, EMSG_MAP_CHAR);
64 ft_eprintf(": \"%c\"\n", data[grid.y][grid.x]);
65 return (EXIT_FAILURE);
66 }
67 }
68 return (EXIT_SUCCESS);
69}
keyboard event flag
Definition type_cub3d.h:226