diff --git a/games/enemy.c b/games/enemy.c index 56869c7..b8deef8 100644 --- a/games/enemy.c +++ b/games/enemy.c @@ -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) diff --git a/games/init.c b/games/init.c index 89c1f98..1f90d48 100644 --- a/games/init.c +++ b/games/init.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/games/init.o b/games/init.o new file mode 100644 index 0000000..8f57e51 Binary files /dev/null and b/games/init.o differ diff --git a/games/map.o b/games/map.o new file mode 100644 index 0000000..9ae2c0a Binary files /dev/null and b/games/map.o differ diff --git a/games/player.c b/games/player.c index 7f26039..741b09e 100644 --- a/games/player.c +++ b/games/player.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/games/player.o b/games/player.o new file mode 100644 index 0000000..d4be3f9 Binary files /dev/null and b/games/player.o differ diff --git a/games/position.c b/games/position.c index ba25158..f3b8e60 100644 --- a/games/position.c +++ b/games/position.c @@ -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; +} diff --git a/games/position.o b/games/position.o new file mode 100644 index 0000000..3f5029b Binary files /dev/null and b/games/position.o differ diff --git a/games/quit.o b/games/quit.o new file mode 100644 index 0000000..cf87526 Binary files /dev/null and b/games/quit.o differ diff --git a/games/render.c b/games/render.c index 57f37a2..1bc8d0d 100644 --- a/games/render.c +++ b/games/render.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/games/render.o b/games/render.o new file mode 100644 index 0000000..91f008f Binary files /dev/null and b/games/render.o differ diff --git a/get_next_line/get_next_line.o b/get_next_line/get_next_line.o new file mode 100644 index 0000000..efe4c00 Binary files /dev/null and b/get_next_line/get_next_line.o differ diff --git a/get_next_line/get_next_line_utils.o b/get_next_line/get_next_line_utils.o new file mode 100644 index 0000000..25251b9 Binary files /dev/null and b/get_next_line/get_next_line_utils.o differ diff --git a/libft/ft_atoi.o b/libft/ft_atoi.o new file mode 100644 index 0000000..09dcae9 Binary files /dev/null and b/libft/ft_atoi.o differ diff --git a/libft/ft_atoi_check.o b/libft/ft_atoi_check.o new file mode 100644 index 0000000..2e7a330 Binary files /dev/null and b/libft/ft_atoi_check.o differ diff --git a/libft/ft_bzero.o b/libft/ft_bzero.o new file mode 100644 index 0000000..3ca98c5 Binary files /dev/null and b/libft/ft_bzero.o differ diff --git a/libft/ft_calloc.o b/libft/ft_calloc.o new file mode 100644 index 0000000..2296eb8 Binary files /dev/null and b/libft/ft_calloc.o differ diff --git a/libft/ft_get_size.o b/libft/ft_get_size.o new file mode 100644 index 0000000..8a15881 Binary files /dev/null and b/libft/ft_get_size.o differ diff --git a/libft/ft_isalnum.o b/libft/ft_isalnum.o new file mode 100644 index 0000000..12210a8 Binary files /dev/null and b/libft/ft_isalnum.o differ diff --git a/libft/ft_isalpha.o b/libft/ft_isalpha.o new file mode 100644 index 0000000..2425dd6 Binary files /dev/null and b/libft/ft_isalpha.o differ diff --git a/libft/ft_isascii.o b/libft/ft_isascii.o new file mode 100644 index 0000000..0e5035b Binary files /dev/null and b/libft/ft_isascii.o differ diff --git a/libft/ft_isdigit.o b/libft/ft_isdigit.o new file mode 100644 index 0000000..545ee21 Binary files /dev/null and b/libft/ft_isdigit.o differ diff --git a/libft/ft_isprint.o b/libft/ft_isprint.o new file mode 100644 index 0000000..a8c2143 Binary files /dev/null and b/libft/ft_isprint.o differ diff --git a/libft/ft_itoa.o b/libft/ft_itoa.o new file mode 100644 index 0000000..9507baf Binary files /dev/null and b/libft/ft_itoa.o differ diff --git a/libft/ft_memchr.o b/libft/ft_memchr.o new file mode 100644 index 0000000..5b60a6e Binary files /dev/null and b/libft/ft_memchr.o differ diff --git a/libft/ft_memcmp.o b/libft/ft_memcmp.o new file mode 100644 index 0000000..472d702 Binary files /dev/null and b/libft/ft_memcmp.o differ diff --git a/libft/ft_memcpy.o b/libft/ft_memcpy.o new file mode 100644 index 0000000..64ef5a0 Binary files /dev/null and b/libft/ft_memcpy.o differ diff --git a/libft/ft_memmove.o b/libft/ft_memmove.o new file mode 100644 index 0000000..8a93ec8 Binary files /dev/null and b/libft/ft_memmove.o differ diff --git a/libft/ft_memset.o b/libft/ft_memset.o new file mode 100644 index 0000000..eb85a59 Binary files /dev/null and b/libft/ft_memset.o differ diff --git a/libft/ft_power.o b/libft/ft_power.o new file mode 100644 index 0000000..3450711 Binary files /dev/null and b/libft/ft_power.o differ diff --git a/libft/ft_putchar_fd.o b/libft/ft_putchar_fd.o new file mode 100644 index 0000000..525fbc3 Binary files /dev/null and b/libft/ft_putchar_fd.o differ diff --git a/libft/ft_putendl_fd.o b/libft/ft_putendl_fd.o new file mode 100644 index 0000000..9e9e284 Binary files /dev/null and b/libft/ft_putendl_fd.o differ diff --git a/libft/ft_putnbr_fd.o b/libft/ft_putnbr_fd.o new file mode 100644 index 0000000..3726826 Binary files /dev/null and b/libft/ft_putnbr_fd.o differ diff --git a/libft/ft_putstr_fd.o b/libft/ft_putstr_fd.o new file mode 100644 index 0000000..affd407 Binary files /dev/null and b/libft/ft_putstr_fd.o differ diff --git a/libft/ft_split.o b/libft/ft_split.o new file mode 100644 index 0000000..8b2b242 Binary files /dev/null and b/libft/ft_split.o differ diff --git a/libft/ft_strchr.o b/libft/ft_strchr.o new file mode 100644 index 0000000..19a1abc Binary files /dev/null and b/libft/ft_strchr.o differ diff --git a/libft/ft_strdup.o b/libft/ft_strdup.o new file mode 100644 index 0000000..c4aed59 Binary files /dev/null and b/libft/ft_strdup.o differ diff --git a/libft/ft_strdup_free.o b/libft/ft_strdup_free.o new file mode 100644 index 0000000..4c4fec1 Binary files /dev/null and b/libft/ft_strdup_free.o differ diff --git a/libft/ft_strdups.o b/libft/ft_strdups.o new file mode 100644 index 0000000..be4bff0 Binary files /dev/null and b/libft/ft_strdups.o differ diff --git a/libft/ft_striteri.o b/libft/ft_striteri.o new file mode 100644 index 0000000..46ace08 Binary files /dev/null and b/libft/ft_striteri.o differ diff --git a/libft/ft_strjoin.o b/libft/ft_strjoin.o new file mode 100644 index 0000000..10ed510 Binary files /dev/null and b/libft/ft_strjoin.o differ diff --git a/libft/ft_strjoin_free.o b/libft/ft_strjoin_free.o new file mode 100644 index 0000000..101a0da Binary files /dev/null and b/libft/ft_strjoin_free.o differ diff --git a/libft/ft_strlcat.o b/libft/ft_strlcat.o new file mode 100644 index 0000000..f780c32 Binary files /dev/null and b/libft/ft_strlcat.o differ diff --git a/libft/ft_strlcpy.o b/libft/ft_strlcpy.o new file mode 100644 index 0000000..8d45fa0 Binary files /dev/null and b/libft/ft_strlcpy.o differ diff --git a/libft/ft_strlen.o b/libft/ft_strlen.o new file mode 100644 index 0000000..2cbf4e3 Binary files /dev/null and b/libft/ft_strlen.o differ diff --git a/libft/ft_strlen_double.o b/libft/ft_strlen_double.o new file mode 100644 index 0000000..de681fa Binary files /dev/null and b/libft/ft_strlen_double.o differ diff --git a/libft/ft_strmapi.o b/libft/ft_strmapi.o new file mode 100644 index 0000000..d24f724 Binary files /dev/null and b/libft/ft_strmapi.o differ diff --git a/libft/ft_strncmp.o b/libft/ft_strncmp.o new file mode 100644 index 0000000..f98e33c Binary files /dev/null and b/libft/ft_strncmp.o differ diff --git a/libft/ft_strnstr.o b/libft/ft_strnstr.o new file mode 100644 index 0000000..763fd26 Binary files /dev/null and b/libft/ft_strnstr.o differ diff --git a/libft/ft_strrchr.o b/libft/ft_strrchr.o new file mode 100644 index 0000000..632d4a2 Binary files /dev/null and b/libft/ft_strrchr.o differ diff --git a/libft/ft_strtrim.o b/libft/ft_strtrim.o new file mode 100644 index 0000000..c50e2a3 Binary files /dev/null and b/libft/ft_strtrim.o differ diff --git a/libft/ft_substr.o b/libft/ft_substr.o new file mode 100644 index 0000000..4aea355 Binary files /dev/null and b/libft/ft_substr.o differ diff --git a/libft/ft_tolower.o b/libft/ft_tolower.o new file mode 100644 index 0000000..08b2bb2 Binary files /dev/null and b/libft/ft_tolower.o differ diff --git a/libft/ft_toupper.o b/libft/ft_toupper.o new file mode 100644 index 0000000..deb631e Binary files /dev/null and b/libft/ft_toupper.o differ diff --git a/libft/libft.a b/libft/libft.a new file mode 100644 index 0000000..f28b978 Binary files /dev/null and b/libft/libft.a differ diff --git a/so_long b/so_long new file mode 100755 index 0000000..da51600 Binary files /dev/null and b/so_long differ diff --git a/so_long.h b/so_long.h index 1caaf3d..4acb9a4 100644 --- a/so_long.h +++ b/so_long.h @@ -77,6 +77,7 @@ void *set_position_player(t_data *data, t_xy *xy); t_xy *get_position(char **map, char c); int has_element(char **map, char c); char get_element(t_data *data, t_xy xy); +void set_element(t_data *data, int x, int y, char element); // Quit int quit(t_data *data);