Avancement
This commit is contained in:
parent
191fba3a12
commit
5e57f44071
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ SRCS = games/init.c games/map.c games/player.c games/position.c games/quit.c gam
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
LIBS = libft/libft.a minilibx-linux/libmlx.a
|
LIBS = libft/libft.a minilibx-linux/libmlx.a
|
||||||
CC = clang
|
CC = clang
|
||||||
CFLAGS = -gdwarf-4 -g -Wall -Wextra -Werror
|
CFLAGS = -g -Wall -Wextra -Werror
|
||||||
NAME = so_long
|
NAME = so_long
|
||||||
|
|
||||||
# PENSER ENLEVER -G
|
# PENSER ENLEVER -G
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
int pathfinding(char **map, char **map_cpy, int x, int y, int *check)
|
int path_finding(char **map_cpy, t_xy cur, t_xy ply, int nbr)
|
||||||
{
|
{
|
||||||
if (map[x][y] == 'E')
|
if (cur.x == ply.x && cur.y == ply.y)
|
||||||
return (1);
|
return (nbr);
|
||||||
map_cpy[x][y] = 'x';
|
map_cpy[x][y] = 'x';
|
||||||
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
|
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
|
||||||
if (is_possible(map, map_cpy, x, y + 1, check))
|
if (is_possible(map, map_cpy, x, y + 1, nbr++))
|
||||||
*check = 1;
|
|
||||||
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
|
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
|
||||||
if (is_possible(map, map_cpy, x + 1, y, check))
|
if (is_possible(map, map_cpy, x + 1, y, nbr))
|
||||||
*check = 1;
|
|
||||||
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
|
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
|
||||||
if (is_possible(map, map_cpy, x - 1, y, check))
|
if (is_possible(map, map_cpy, x - 1, y, nbr))
|
||||||
*check = 1;
|
*check =
|
||||||
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
|
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
|
||||||
if (is_possible(map, map_cpy, x, y - 1, check))
|
if (is_possible(map, map_cpy, x, y - 1, nbr))
|
||||||
*check = 1;
|
*check = 1;
|
||||||
if (!has_element(map_cpy, 'C') && *check)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
games/init.c
29
games/init.c
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* init.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../so_long.h"
|
#include "../so_long.h"
|
||||||
|
|
||||||
int key_hook(int key, t_data *data)
|
int key_hook(int key, t_data *data)
|
||||||
|
@ -61,18 +73,28 @@ int trgb(int t, int r, int g, int b)
|
||||||
|
|
||||||
int render(t_data *data)
|
int render(t_data *data)
|
||||||
{
|
{
|
||||||
|
char *str_move;
|
||||||
|
t_xy pos;
|
||||||
|
|
||||||
/*if (data->tick >= 5 && data->x_ene != -1)
|
/*if (data->tick >= 5 && data->x_ene != -1)
|
||||||
{
|
{
|
||||||
data->tick = 0;
|
data->tick = 0;
|
||||||
move_enemy(data);
|
move_enemy(data);
|
||||||
}
|
}
|
||||||
else
|
else if (data->x_ene != -1)
|
||||||
data->tick++;*/
|
data->tick++;*/
|
||||||
if (data->update == 1)
|
if (data->update == 1)
|
||||||
{
|
{
|
||||||
|
if (has_element(data->map, '3'))
|
||||||
|
{
|
||||||
|
pos = get_position(data->map, '3');
|
||||||
|
|
||||||
|
}
|
||||||
draw(data);
|
draw(data);
|
||||||
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.bg, 0, 0);
|
mlx_put_image_to_window(data->mlx, data->mlx_win, data->imgs.bg, 0, 0);
|
||||||
mlx_string_put(data->mlx, data->mlx_win, 100, 100, trgb(0, 150, 0, 0), ft_itoa(data->move));
|
str_move = ft_itoa(data->move);
|
||||||
|
mlx_string_put(data->mlx, data->mlx_win, 100, 100, trgb(0, 150, 0, 0), str_move);
|
||||||
|
free(str_move);
|
||||||
data->update = 0;
|
data->update = 0;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -117,7 +139,8 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
t_data data;
|
t_data data;
|
||||||
|
|
||||||
(void)argc;
|
if (argc != 2)
|
||||||
|
return (0);
|
||||||
(void)argv;
|
(void)argv;
|
||||||
init_data(&data);
|
init_data(&data);
|
||||||
if (get_map(argv, &data) == NULL)
|
if (get_map(argv, &data) == NULL)
|
||||||
|
|
19
games/map.c
19
games/map.c
|
@ -7,6 +7,11 @@ void *read_map(char *argv[], t_data *data)
|
||||||
int i;
|
int i;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
if (argv[1][ft_strlen(argv[1]) - 1] != 'r' ||
|
||||||
|
argv[1][ft_strlen(argv[1]) - 2] != 'e' ||
|
||||||
|
argv[1][ft_strlen(argv[1]) - 3] != 'b' ||
|
||||||
|
argv[1][ft_strlen(argv[1]) - 4] != '.')
|
||||||
|
return (NULL);
|
||||||
fd = open(argv[1], O_RDONLY);
|
fd = open(argv[1], O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -83,22 +88,22 @@ int is_surrounded_by_wall(char **map, int h_map)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_possible(char **map, char **map_cpy, int x, int y, int *check)
|
int is_possible(char **map_cpy, int x, int y, int *check)
|
||||||
{
|
{
|
||||||
if (map[x][y] == 'E')
|
if (map_cpy[x][y] == 'E')
|
||||||
return (1);
|
return (1);
|
||||||
map_cpy[x][y] = 'x';
|
map_cpy[x][y] = 'x';
|
||||||
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
|
if (map_cpy[x][y + 1] != '1' && map_cpy[x][y + 1] != 'x')
|
||||||
if (is_possible(map, map_cpy, x, y + 1, check))
|
if (is_possible(map_cpy, x, y + 1, check))
|
||||||
*check = 1;
|
*check = 1;
|
||||||
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
|
if (map_cpy[x + 1][y] != '1' && map_cpy[x + 1][y] != 'x')
|
||||||
if (is_possible(map, map_cpy, x + 1, y, check))
|
if (is_possible(map_cpy, x + 1, y, check))
|
||||||
*check = 1;
|
*check = 1;
|
||||||
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
|
if (map_cpy[x - 1][y] != '1' && map_cpy[x - 1][y] != 'x')
|
||||||
if (is_possible(map, map_cpy, x - 1, y, check))
|
if (is_possible(map_cpy, x - 1, y, check))
|
||||||
*check = 1;
|
*check = 1;
|
||||||
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
|
if (map_cpy[x][y - 1] != '1' && map_cpy[x][y - 1] != 'x')
|
||||||
if (is_possible(map, map_cpy, x, y - 1, check))
|
if (is_possible(map_cpy, x, y - 1, check))
|
||||||
*check = 1;
|
*check = 1;
|
||||||
if (!has_element(map_cpy, 'C') && *check)
|
if (!has_element(map_cpy, 'C') && *check)
|
||||||
return (1);
|
return (1);
|
||||||
|
@ -156,7 +161,7 @@ void *get_map(char *argv[], t_data *data)
|
||||||
data = set_position_player(data, get_position(data->map, 'P'));
|
data = set_position_player(data, get_position(data->map, 'P'));
|
||||||
i = 0;
|
i = 0;
|
||||||
map_cpy = ft_strdups(data->map);
|
map_cpy = ft_strdups(data->map);
|
||||||
if (!is_possible(data->map, map_cpy, data->y_player, data->x_player, &i))
|
if (!is_possible(map_cpy, data->y_player, data->x_player, &i))
|
||||||
{
|
{
|
||||||
write(1, "Error\nLa carte est impossible a faire", 37);
|
write(1, "Error\nLa carte est impossible a faire", 37);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* player.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../so_long.h"
|
#include "../so_long.h"
|
||||||
|
|
||||||
static int get_new_element(t_data *data, int x, int y)
|
static int get_new_element(t_data *data, int x, int y)
|
||||||
|
@ -8,6 +20,9 @@ static int get_new_element(t_data *data, int x, int y)
|
||||||
static void set_new_element(t_data *data, int x, int y)
|
static void set_new_element(t_data *data, int x, int y)
|
||||||
{
|
{
|
||||||
data->map[data->y_player + y][data->x_player + x] = '0';
|
data->map[data->y_player + y][data->x_player + x] = '0';
|
||||||
|
if (!has_element(data->map, 'C'))
|
||||||
|
data->map[data->y_player + y][data->x_player + x] = '3';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *set_position_player(t_data *data, t_xy *xy)
|
void *set_position_player(t_data *data, t_xy *xy)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* position.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/12/29 18:06:59 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/12/29 18:07:01 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../so_long.h"
|
#include "../so_long.h"
|
||||||
|
|
||||||
t_xy *get_position(char **map, char c)
|
t_xy *get_position(char **map, char c)
|
||||||
|
|
12
games/quit.c
12
games/quit.c
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* quit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/12/29 18:06:50 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/12/29 18:06:53 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../so_long.h"
|
#include "../so_long.h"
|
||||||
|
|
||||||
int end(t_data *data)
|
int end(t_data *data)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* render.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../so_long.h"
|
#include "../so_long.h"
|
||||||
|
|
||||||
static void *assets(t_data *data, int x, int y)
|
static void *assets(t_data *data, int x, int y)
|
||||||
|
@ -9,15 +21,13 @@ static void *assets(t_data *data, int x, int y)
|
||||||
dist = sqrt(pow(x - data->x_player, 2) + pow(y - data->y_player, 2)) - 1;
|
dist = sqrt(pow(x - data->x_player, 2) + pow(y - data->y_player, 2)) - 1;
|
||||||
if (dist > 2)
|
if (dist > 2)
|
||||||
dist = 2;
|
dist = 2;
|
||||||
if (c == '0' || c == 'P')
|
|
||||||
return (data->imgs.bg);
|
|
||||||
else if (c == '1')
|
else if (c == '1')
|
||||||
return (data->imgs.wall[dist]);
|
return (data->imgs.wall[dist]);
|
||||||
else if (c == 'C')
|
else if (c == 'C')
|
||||||
return (data->imgs.col[dist]);
|
return (data->imgs.col[dist]);
|
||||||
else if (c == 'E')
|
else if (c == 'E')
|
||||||
return (data->imgs.exit[dist]);
|
return (data->imgs.exit[dist]);
|
||||||
return (NULL);
|
return (data->imgs.bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(t_data *data)
|
void draw(t_data *data)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_strdups.c :+: :+: :+: */
|
/* ft_strdups.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */
|
/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */
|
||||||
/* Updated: 2022/09/28 16:32:55 by erey-bet ### ########.fr */
|
/* Updated: 2022/12/29 18:05:24 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
size_t ft_strlcat(char *dest, const char *src, size_t size);
|
size_t ft_strlcat(char *dest, const char *src, size_t size);
|
||||||
char *ft_strdup(const char *src);
|
char *ft_strdup(const char *src);
|
||||||
char *ft_strdup_free(char *src);
|
char *ft_strdup_free(char *src);
|
||||||
char **ft_strdups(char **src);
|
char **ft_strdups(char **src);
|
||||||
int ft_atoi(const char *nptr);
|
int ft_atoi(const char *nptr);
|
||||||
char **ft_split(char const *s, char c);
|
char **ft_split(char const *s, char c);
|
||||||
void *ft_calloc(size_t nitems, size_t size);
|
void *ft_calloc(size_t nitems, size_t size);
|
||||||
|
@ -69,6 +69,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*));
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void*));
|
void ft_lstclear(t_list **lst, void (*del)(void*));
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
int ft_atoi_check(const char *nptr);
|
int ft_atoi_check(const char *nptr);
|
||||||
int ft_strlen_double(char **strs);
|
int ft_strlen_double(char **strs);
|
||||||
#endif
|
#endif
|
||||||
|
|
14
so_long.c
14
so_long.c
|
@ -1,14 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* so_long.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/12/09 14:18:18 by erey-bet #+# #+# */
|
|
||||||
/* Updated: 2022/12/14 17:15:45 by erey-bet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "so_long.h"
|
|
||||||
#include <stdio.h>
|
|
Loading…
Reference in a new issue