avancement
This commit is contained in:
parent
5e57f44071
commit
8c14fce5ee
|
@ -1,21 +1,27 @@
|
|||
int path_finding(char **map_cpy, t_xy cur, t_xy ply, int nbr)
|
||||
void distance_player(char **map, int x, int y, int nbr)
|
||||
{
|
||||
map[x][y] = nbr + '0';
|
||||
if (map[x][y + 1] != '1' && map[x][y + 1] == '0')
|
||||
distance_player(map, x, y + 1, nbr + 1)
|
||||
if (map[x + 1][y] != '1' && map[x + 1][y] == '0')
|
||||
distance_player(map, x + 1, y, nbr + 1)
|
||||
if (map[x - 1][y] != '1' && map[x + 1][y] == '0')
|
||||
distance_player(map, x - 1, y, nbr + 1)
|
||||
if (map[x][y - 1] != '1' && map[x][y - 1] == '0')
|
||||
distance_player(map, x, y - 1, nbr + 1)
|
||||
}
|
||||
|
||||
t_xy path_finding(t_data *data, int x, int y)
|
||||
{
|
||||
t_xy new_pos;
|
||||
char **map_cpy;
|
||||
|
||||
if (cur.x == ply.x && cur.y == ply.y)
|
||||
return (nbr);
|
||||
map_cpy[x][y] = 'x';
|
||||
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
|
||||
if (is_possible(map, map_cpy, x, y + 1, nbr++))
|
||||
|
||||
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
|
||||
if (is_possible(map, map_cpy, x + 1, y, nbr))
|
||||
|
||||
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
|
||||
if (is_possible(map, map_cpy, x - 1, y, nbr))
|
||||
*check =
|
||||
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
|
||||
if (is_possible(map, map_cpy, x, y - 1, nbr))
|
||||
*check = 1;
|
||||
return (0);
|
||||
return (0);
|
||||
map_cpy = ft_strdups(data->map);
|
||||
distance_player(map_cpy, x, y, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void move_enemy(t_data *data)
|
||||
|
|
16
games/init.c
16
games/init.c
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:18 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/01 19:49:56 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/01/02 16:28:52 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -74,9 +74,9 @@ int trgb(int t, int r, int g, int b)
|
|||
int render(t_data *data)
|
||||
{
|
||||
char *str_move;
|
||||
t_xy pos;
|
||||
t_xy *pos;
|
||||
|
||||
/*if (data->tick >= 5 && data->x_ene != -1)
|
||||
/*if (data->tick >= 20 && data->x_ene != -1)
|
||||
{
|
||||
data->tick = 0;
|
||||
move_enemy(data);
|
||||
|
@ -85,10 +85,16 @@ int render(t_data *data)
|
|||
data->tick++;*/
|
||||
if (data->update == 1)
|
||||
{
|
||||
if (has_element(data->map, '3'))
|
||||
if (data->x_ene != -1 && has_element(data->map, '3'))
|
||||
{
|
||||
pos = get_position(data->map, '3');
|
||||
|
||||
if (data->x_player != pos->x || data->y_player != pos->y)
|
||||
{
|
||||
set_element(data, pos->x, pos->y, 'e');
|
||||
data->x_ene = pos->x;
|
||||
data->y_ene = pos->y;
|
||||
}
|
||||
free(pos);
|
||||
}
|
||||
draw(data);
|
||||
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.bg, 0, 0);
|
||||
|
|
BIN
games/init.o
Normal file
BIN
games/init.o
Normal file
Binary file not shown.
BIN
games/map.o
Normal file
BIN
games/map.o
Normal file
Binary file not shown.
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:32 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/01 19:39:28 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/01/02 16:30:35 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -39,7 +39,7 @@ void move(t_data *data, int x, int y)
|
|||
return ;
|
||||
if (get_new_element(data, x, y) == 'C')
|
||||
set_new_element(data, x, y);
|
||||
if (get_new_element(data, x, y) == 'E')
|
||||
if (get_new_element(data, x, y) == 'E' || get_new_element(data, x, y) == 'e')
|
||||
if (end(data))
|
||||
return ;
|
||||
data->x_player += x;
|
||||
|
|
BIN
games/player.o
Normal file
BIN
games/player.o
Normal file
Binary file not shown.
|
@ -54,3 +54,8 @@ char get_element(t_data *data, t_xy xy)
|
|||
{
|
||||
return (data->map[xy.y][xy.x]);
|
||||
}
|
||||
|
||||
void set_element(t_data *data, int x, int y, char element)
|
||||
{
|
||||
data->map[y][x] = element;
|
||||
}
|
||||
|
|
BIN
games/position.o
Normal file
BIN
games/position.o
Normal file
Binary file not shown.
BIN
games/quit.o
Normal file
BIN
games/quit.o
Normal file
Binary file not shown.
|
@ -6,7 +6,7 @@
|
|||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/29 18:06:42 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/01/01 19:39:55 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/01/02 16:24:06 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -27,6 +27,8 @@ static void *assets(t_data *data, int x, int y)
|
|||
return (data->imgs.col[dist]);
|
||||
else if (c == 'E')
|
||||
return (data->imgs.exit[dist]);
|
||||
else if (c == 'e')
|
||||
return (data->imgs.ene);
|
||||
return (data->imgs.bg);
|
||||
}
|
||||
|
||||
|
|
BIN
games/render.o
Normal file
BIN
games/render.o
Normal file
Binary file not shown.
BIN
get_next_line/get_next_line.o
Normal file
BIN
get_next_line/get_next_line.o
Normal file
Binary file not shown.
BIN
get_next_line/get_next_line_utils.o
Normal file
BIN
get_next_line/get_next_line_utils.o
Normal file
Binary file not shown.
BIN
libft/ft_atoi.o
Normal file
BIN
libft/ft_atoi.o
Normal file
Binary file not shown.
BIN
libft/ft_atoi_check.o
Normal file
BIN
libft/ft_atoi_check.o
Normal file
Binary file not shown.
BIN
libft/ft_bzero.o
Normal file
BIN
libft/ft_bzero.o
Normal file
Binary file not shown.
BIN
libft/ft_calloc.o
Normal file
BIN
libft/ft_calloc.o
Normal file
Binary file not shown.
BIN
libft/ft_get_size.o
Normal file
BIN
libft/ft_get_size.o
Normal file
Binary file not shown.
BIN
libft/ft_isalnum.o
Normal file
BIN
libft/ft_isalnum.o
Normal file
Binary file not shown.
BIN
libft/ft_isalpha.o
Normal file
BIN
libft/ft_isalpha.o
Normal file
Binary file not shown.
BIN
libft/ft_isascii.o
Normal file
BIN
libft/ft_isascii.o
Normal file
Binary file not shown.
BIN
libft/ft_isdigit.o
Normal file
BIN
libft/ft_isdigit.o
Normal file
Binary file not shown.
BIN
libft/ft_isprint.o
Normal file
BIN
libft/ft_isprint.o
Normal file
Binary file not shown.
BIN
libft/ft_itoa.o
Normal file
BIN
libft/ft_itoa.o
Normal file
Binary file not shown.
BIN
libft/ft_memchr.o
Normal file
BIN
libft/ft_memchr.o
Normal file
Binary file not shown.
BIN
libft/ft_memcmp.o
Normal file
BIN
libft/ft_memcmp.o
Normal file
Binary file not shown.
BIN
libft/ft_memcpy.o
Normal file
BIN
libft/ft_memcpy.o
Normal file
Binary file not shown.
BIN
libft/ft_memmove.o
Normal file
BIN
libft/ft_memmove.o
Normal file
Binary file not shown.
BIN
libft/ft_memset.o
Normal file
BIN
libft/ft_memset.o
Normal file
Binary file not shown.
BIN
libft/ft_power.o
Normal file
BIN
libft/ft_power.o
Normal file
Binary file not shown.
BIN
libft/ft_putchar_fd.o
Normal file
BIN
libft/ft_putchar_fd.o
Normal file
Binary file not shown.
BIN
libft/ft_putendl_fd.o
Normal file
BIN
libft/ft_putendl_fd.o
Normal file
Binary file not shown.
BIN
libft/ft_putnbr_fd.o
Normal file
BIN
libft/ft_putnbr_fd.o
Normal file
Binary file not shown.
BIN
libft/ft_putstr_fd.o
Normal file
BIN
libft/ft_putstr_fd.o
Normal file
Binary file not shown.
BIN
libft/ft_split.o
Normal file
BIN
libft/ft_split.o
Normal file
Binary file not shown.
BIN
libft/ft_strchr.o
Normal file
BIN
libft/ft_strchr.o
Normal file
Binary file not shown.
BIN
libft/ft_strdup.o
Normal file
BIN
libft/ft_strdup.o
Normal file
Binary file not shown.
BIN
libft/ft_strdup_free.o
Normal file
BIN
libft/ft_strdup_free.o
Normal file
Binary file not shown.
BIN
libft/ft_strdups.o
Normal file
BIN
libft/ft_strdups.o
Normal file
Binary file not shown.
BIN
libft/ft_striteri.o
Normal file
BIN
libft/ft_striteri.o
Normal file
Binary file not shown.
BIN
libft/ft_strjoin.o
Normal file
BIN
libft/ft_strjoin.o
Normal file
Binary file not shown.
BIN
libft/ft_strjoin_free.o
Normal file
BIN
libft/ft_strjoin_free.o
Normal file
Binary file not shown.
BIN
libft/ft_strlcat.o
Normal file
BIN
libft/ft_strlcat.o
Normal file
Binary file not shown.
BIN
libft/ft_strlcpy.o
Normal file
BIN
libft/ft_strlcpy.o
Normal file
Binary file not shown.
BIN
libft/ft_strlen.o
Normal file
BIN
libft/ft_strlen.o
Normal file
Binary file not shown.
BIN
libft/ft_strlen_double.o
Normal file
BIN
libft/ft_strlen_double.o
Normal file
Binary file not shown.
BIN
libft/ft_strmapi.o
Normal file
BIN
libft/ft_strmapi.o
Normal file
Binary file not shown.
BIN
libft/ft_strncmp.o
Normal file
BIN
libft/ft_strncmp.o
Normal file
Binary file not shown.
BIN
libft/ft_strnstr.o
Normal file
BIN
libft/ft_strnstr.o
Normal file
Binary file not shown.
BIN
libft/ft_strrchr.o
Normal file
BIN
libft/ft_strrchr.o
Normal file
Binary file not shown.
BIN
libft/ft_strtrim.o
Normal file
BIN
libft/ft_strtrim.o
Normal file
Binary file not shown.
BIN
libft/ft_substr.o
Normal file
BIN
libft/ft_substr.o
Normal file
Binary file not shown.
BIN
libft/ft_tolower.o
Normal file
BIN
libft/ft_tolower.o
Normal file
Binary file not shown.
BIN
libft/ft_toupper.o
Normal file
BIN
libft/ft_toupper.o
Normal file
Binary file not shown.
BIN
libft/libft.a
Normal file
BIN
libft/libft.a
Normal file
Binary file not shown.
Loading…
Reference in a new issue