avancement, prototype fini, leaks et parsing

This commit is contained in:
Etienne Rey-bethbeder 2022-12-12 21:56:11 +01:00
parent 9aad31018e
commit 1186421e98
57 changed files with 331 additions and 263 deletions

BIN
.so_long.h.swo Normal file

Binary file not shown.

View file

@ -6,11 +6,12 @@
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
# Updated: 2022/12/10 15:43:34 by erey-bet ### ########.fr #
# Updated: 2022/12/12 17:21:15 by erey-bet ### ########.fr #
# #
# **************************************************************************** #
SRCS = so_long.c
GNL = get_next_line/get_next_line.c get_next_line/get_next_line_utils.c
SRCS = so_long.c ${GNL}
OBJS = ${SRCS:.c=.o}
LIBS = libft/libft.a minilibx-linux/libmlx.a
CC = clang

133
assets/exit.xpm Normal file
View file

@ -0,0 +1,133 @@
/* XPM */
static char * exit_xpm[] = {
"128 128 2 1",
" c #000000",
". c #3C00E2",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ............................................................................................................ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/15 23:42:35 by erey-bet #+# #+# */
/* Updated: 2022/11/07 17:11:17 by erey-bet ### ########.fr */
/* Updated: 2022/12/12 17:19:23 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@ static char *read_line(int fd)
char *buff;
int y;
buff = ft_calloc(BUFFER_SIZE + 1, 1);
buff = ft_calloc_gnl(BUFFER_SIZE + 1, 1);
if (buff == NULL)
return (NULL);
y = read(fd, buff, BUFFER_SIZE);
@ -36,8 +36,8 @@ static char *join_str(char *s1, char *s2)
int i;
int len;
len = ft_strlen(s1);
n_str = ft_calloc(len + ft_strlen(s2) + 1, 1);
len = ft_strlen_gnl(s1);
n_str = ft_calloc_gnl(len + ft_strlen_gnl(s2) + 1, 1);
if (n_str == NULL)
return (NULL);
i = -1;
@ -63,11 +63,11 @@ static char *get_text(char *save)
i++;
if (save[i] == '\n')
i++;
new_s = ft_calloc(i + 1, 1);
new_s = ft_calloc_gnl(i + 1, 1);
if (new_s == NULL)
return (NULL);
ft_strlcpy(new_s, save, i + 1);
ft_strlcpy(save, save + i, ft_strlen(save));
ft_strlcpy_gnl(new_s, save, i + 1);
ft_strlcpy_gnl(save, save + i, ft_strlen_gnl(save));
return (new_s);
}
@ -93,12 +93,13 @@ char *get_next_line(int fd)
static char *save;
buff = NULL;
while (buff == NULL || (ft_strchr(save, '\n') == -1))
while (buff == NULL || (ft_strchr_gnl(save, '\n') == -1))
{
buff = read_line(fd);
if (buff == NULL || (ft_strlen(buff) == 0 && ft_strlen(save) == 0))
if (buff == NULL
|| (ft_strlen_gnl(buff) == 0 && ft_strlen_gnl(save) == 0))
return (make_free(buff, &save, 1));
if (ft_strlen(buff) == 0)
if (ft_strlen_gnl(buff) == 0)
{
free(buff);
break ;
@ -108,7 +109,7 @@ char *get_next_line(int fd)
return (NULL);
}
str = get_text(save);
if (ft_strlen(save) == 0)
if (ft_strlen_gnl(save) == 0)
make_free(NULL, &save, 2);
return (str);
}

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/15 23:40:12 by erey-bet #+# #+# */
/* Updated: 2022/11/15 19:42:13 by erey-bet ### ########.fr */
/* Updated: 2022/12/12 17:16:43 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,9 +20,9 @@
# endif
char *get_next_line(int fd);
void *ft_calloc(size_t nitems, size_t size);
size_t ft_strlen(const char *str);
int ft_strchr(const char *str, int search);
void ft_strlcpy(char *dest, const char *src, size_t size);
void *ft_calloc_gnl(size_t nitems, size_t size);
size_t ft_strlen_gnl(const char *str);
int ft_strchr_gnl(const char *str, int search);
void ft_strlcpy_gnl(char *dest, const char *src, size_t size);
#endif

Binary file not shown.

View file

@ -1,116 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/15 23:42:35 by erey-bet #+# #+# */
/* Updated: 2022/11/16 13:20:26 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
static char *read_line(int fd)
{
char *buff;
int y;
buff = ft_calloc(BUFFER_SIZE + 1, 1);
if (buff == NULL)
return (NULL);
y = read(fd, buff, BUFFER_SIZE);
if (y == -1)
{
free(buff);
return (NULL);
}
buff[y] = '\0';
return (buff);
}
static char *join_str(char *s1, char *s2)
{
char *n_str;
int i;
int len;
len = ft_strlen(s1);
n_str = ft_calloc(len + ft_strlen(s2) + 1, 1);
if (n_str == NULL)
return (NULL);
i = -1;
if (s1 != NULL)
while (s1[++i])
n_str[i] = s1[i];
i = -1;
while (s2[++i])
n_str[i + len] = s2[i];
n_str[i + len] = '\0';
free(s1);
free(s2);
return (n_str);
}
static char *get_text(char *save)
{
int i;
char *new_s;
i = 0;
while (save[i] && save[i] != '\n')
i++;
if (save[i] == '\n')
i++;
new_s = ft_calloc(i + 1, 1);
if (new_s == NULL)
return (NULL);
ft_strlcpy(new_s, save, i + 1);
ft_strlcpy(save, save + i, ft_strlen(save));
return (new_s);
}
static void *make_free(char *buff, char **save, int choice)
{
if (choice == 1)
{
free(buff);
free(*save);
}
else
{
free(*save);
*save = NULL;
}
return (NULL);
}
char *get_next_line(int fd)
{
char *buff;
char *str;
static char *save[1024];
if (fd < 0 || fd >= 1024)
return (NULL);
buff = NULL;
while (buff == NULL || ft_strchr(save[fd], '\n') == -1)
{
buff = read_line(fd);
if (buff == NULL || (ft_strlen(buff) == 0 && ft_strlen(save[fd]) == 0))
return (make_free(buff, &save[fd], 1));
if (ft_strlen(buff) == 0)
{
free(buff);
break ;
}
save[fd] = join_str(save[fd], buff);
if (save[fd] == NULL)
return (NULL);
}
str = get_text(save[fd]);
if (ft_strlen(save[fd]) == 0)
make_free(NULL, &save[fd], 2);
return (str);
}

View file

@ -6,13 +6,13 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/07 17:19:41 by erey-bet #+# #+# */
/* Updated: 2022/11/07 17:19:42 by erey-bet ### ########.fr */
/* Updated: 2022/12/12 17:16:22 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *ft_calloc(size_t nitems, size_t size)
void *ft_calloc_gnl(size_t nitems, size_t size)
{
size_t i;
char *tmp;
@ -33,7 +33,7 @@ void *ft_calloc(size_t nitems, size_t size)
return (tmp);
}
size_t ft_strlen(const char *str)
size_t ft_strlen_gnl(const char *str)
{
int i;
@ -45,7 +45,7 @@ size_t ft_strlen(const char *str)
return (i);
}
int ft_strchr(const char *str, int search)
int ft_strchr_gnl(const char *str, int search)
{
int i;
@ -59,7 +59,7 @@ int ft_strchr(const char *str, int search)
return (-1);
}
void ft_strlcpy(char *dest, const char *src, size_t size)
void ft_strlcpy_gnl(char *dest, const char *src, size_t size)
{
size_t i;

Binary file not shown.

View file

@ -1,75 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/07 17:19:41 by erey-bet #+# #+# */
/* Updated: 2022/11/15 19:57:30 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *ft_calloc(size_t nitems, size_t size)
{
size_t i;
char *tmp;
if (nitems == 0 || size == 0)
return (malloc(0));
if (nitems * size < nitems)
return (NULL);
tmp = malloc(nitems * size);
if (tmp == NULL)
return (NULL);
i = 0;
while (i < nitems * size)
{
tmp[i] = '\0';
i++;
}
return (tmp);
}
size_t ft_strlen(const char *str)
{
int i;
if (str == NULL)
return (0);
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
int ft_strchr(const char *str, int search)
{
int i;
i = 0;
while (str[i] || str[i] == (unsigned char)search)
{
if (str[i] == (unsigned char)search)
return (i);
i++;
}
return (-1);
}
void ft_strlcpy(char *dest, const char *src, size_t size)
{
size_t i;
i = 0;
if (!size || !dest || !src)
return ;
while (i < size - 1 && src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
}

View file

@ -6,7 +6,7 @@
# By: erey-bet <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 04:19:30 by erey-bet #+# #+# #
# Updated: 2022/10/19 17:45:46 by erey-bet ### ########.fr #
# Updated: 2022/12/12 13:46:44 by erey-bet ### ########.fr #
# #
# **************************************************************************** #
@ -16,7 +16,7 @@ ft_strlcat.c ft_toupper.c ft_tolower.c ft_strchr.c ft_strrchr.c ft_strncmp.c \
ft_memchr.c ft_memcmp.c ft_strnstr.c ft_atoi.c ft_calloc.c ft_strdup.c \
ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \
ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \
ft_get_size.c ft_power.c ft_atoi_check.c
ft_get_size.c ft_power.c ft_atoi_check.c ft_strlen_double.c
OBJS = ${SRCS:.c=.o}
BONUS_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \
ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c

BIN
libft/ft_atoi.o Normal file

Binary file not shown.

BIN
libft/ft_atoi_check.o Normal file

Binary file not shown.

BIN
libft/ft_bzero.o Normal file

Binary file not shown.

BIN
libft/ft_calloc.o Normal file

Binary file not shown.

BIN
libft/ft_get_size.o Normal file

Binary file not shown.

BIN
libft/ft_isalnum.o Normal file

Binary file not shown.

BIN
libft/ft_isalpha.o Normal file

Binary file not shown.

BIN
libft/ft_isascii.o Normal file

Binary file not shown.

BIN
libft/ft_isdigit.o Normal file

Binary file not shown.

BIN
libft/ft_isprint.o Normal file

Binary file not shown.

BIN
libft/ft_itoa.o Normal file

Binary file not shown.

BIN
libft/ft_memchr.o Normal file

Binary file not shown.

BIN
libft/ft_memcmp.o Normal file

Binary file not shown.

BIN
libft/ft_memcpy.o Normal file

Binary file not shown.

BIN
libft/ft_memmove.o Normal file

Binary file not shown.

BIN
libft/ft_memset.o Normal file

Binary file not shown.

BIN
libft/ft_power.o Normal file

Binary file not shown.

BIN
libft/ft_putchar_fd.o Normal file

Binary file not shown.

BIN
libft/ft_putendl_fd.o Normal file

Binary file not shown.

BIN
libft/ft_putnbr_fd.o Normal file

Binary file not shown.

BIN
libft/ft_putstr_fd.o Normal file

Binary file not shown.

BIN
libft/ft_split.o Normal file

Binary file not shown.

BIN
libft/ft_strchr.o Normal file

Binary file not shown.

BIN
libft/ft_strdup.o Normal file

Binary file not shown.

BIN
libft/ft_striteri.o Normal file

Binary file not shown.

BIN
libft/ft_strjoin.o Normal file

Binary file not shown.

BIN
libft/ft_strlcat.o Normal file

Binary file not shown.

BIN
libft/ft_strlcpy.o Normal file

Binary file not shown.

BIN
libft/ft_strlen.o Normal file

Binary file not shown.

View file

@ -1,28 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.h :+: :+: :+: */
/* ft_strlen_double.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/15 23:40:12 by erey-bet #+# #+# */
/* Updated: 2022/11/15 20:00:55 by erey-bet ### ########.fr */
/* Created: 2022/12/12 13:45:14 by erey-bet #+# #+# */
/* Updated: 2022/12/12 13:46:16 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GET_NEXT_LINE_BONUS_H
# define GET_NEXT_LINE_BONUS_H
int ft_strlen_double(char **strs)
{
int i;
int y;
int count;
# include <unistd.h>
# include <stdlib.h>
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 41
# endif
char *get_next_line(int fd);
void *ft_calloc(size_t nitems, size_t size);
size_t ft_strlen(const char *str);
int ft_strchr(const char *str, int search);
void ft_strlcpy(char *dest, const char *src, size_t size);
#endif
i = 0;
while (strs[i])
{
y = 0;
while (strs[i][y])
{
count++;
}
i++;
}
return (count);
}

BIN
libft/ft_strlen_double.o Normal file

Binary file not shown.

BIN
libft/ft_strmapi.o Normal file

Binary file not shown.

BIN
libft/ft_strncmp.o Normal file

Binary file not shown.

BIN
libft/ft_strnstr.o Normal file

Binary file not shown.

BIN
libft/ft_strrchr.o Normal file

Binary file not shown.

BIN
libft/ft_strtrim.o Normal file

Binary file not shown.

BIN
libft/ft_substr.o Normal file

Binary file not shown.

BIN
libft/ft_tolower.o Normal file

Binary file not shown.

BIN
libft/ft_toupper.o Normal file

Binary file not shown.

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 16:31:10 by erey-bet #+# #+# */
/* Updated: 2022/10/18 17:32:25 by erey-bet ### ########.fr */
/* Updated: 2022/12/12 13:46:30 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -67,5 +67,5 @@ void ft_lstclear(t_list **lst, void (*del)(void*));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
int ft_atoi_check(const char *nptr);
int ft_strlen_double(char **strs);
#endif

5
map_test.txt Normal file
View file

@ -0,0 +1,5 @@
1111111111111
10010000000C1
1000011111001
1P0011E000001
1111111111111

BIN
so_long

Binary file not shown.

159
so_long.c
View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 14:18:18 by erey-bet #+# #+# */
/* Updated: 2022/12/11 18:48:15 by erey-bet ### ########.fr */
/* Updated: 2022/12/12 21:52:42 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,52 +21,129 @@ void free_img(t_data *data)
int quit(t_data *data)
{
if (data->mlx_img != NULL)
free_img(data);
free(data->mlx_win);
free(data->mlx);
(void)data;
exit(0);
return (0);
}
t_xy *get_position(t_data *data, char c)
{
int y;
t_xy *xy;
y = 0;
xy = NULL;
while (data->map[y])
{
if (ft_strchr_gnl(data->map[y], c) != -1)
{
xy = ft_calloc(1, sizeof(t_xy));
xy->x = ft_strchr_gnl(data->map[y], c);
xy->y = y;
break;
}
y++;
}
return (xy);
}
int get_new_element(t_data *data, int x, int y)
{
return(data->map[data->y_player + y][data->x_player + x]);
}
void set_new_element(t_data *data, int x, int y)
{
data->map[data->y_player + y][data->x_player + x] = '0';
}
int end(t_data *data)
{
if (get_position(data, 'C') == NULL)
quit(data);
return (1);
}
void set_position_player(t_data *data, t_xy *xy)
{
data->x_player = xy->x;
data->y_player = xy->y;
free(xy);
}
void move(t_data *data, int x, int y)
{
if (get_new_element(data, x, y) == '1')
return ;
if (get_new_element(data, x, y) == 'C')
set_new_element(data, x, y);
if (get_new_element(data, x, y) == 'E')
if (end(data))
return ;
data->x_player += x;
data->y_player += y;
}
int key_hook(int key, t_data *data)
{
if (key == K_ESC)
quit(data);
else if (key == K_LEFT)
data->x_player -= 128;
move(data, -1, 0);
else if (key == K_RIGHT)
data->x_player += 128;
move(data, 1, 0);
else if (key == K_UP)
data->y_player -= 128;
move(data, 0, -1);
else if (key == K_DOWN)
data->y_player += 128;
move(data, 0, 1);
data->update = 1;
return (0);
}
int render(t_data *data)
char *assets(char c)
{
if (c == '0')
return ("assets/background.xpm");
else if (c == '1')
return ("assets/wall.xpm");
else if (c == 'C')
return ("assets/collectible.xpm");
else if (c == 'E')
return ("assets/exit.xpm");
return (NULL);
}
void draw_map(t_data *data)
{
int x;
int y;
x = 0;
while (x < (data->w_screen / data->size))
{
y = 0;
while (y < (data->h_screen / data->size))
{
if (x != data->x_player || y != data->y_player)
{
data->mlx_img = mlx_xpm_file_to_image(data->mlx, assets(data->map[y][x]), &data->size, &data->size);
if (!data->mlx_img)
data->mlx_img = mlx_xpm_file_to_image(data->mlx, assets('0'), &data->size, &data->size);
mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, x * data->size, y * data->size);
}
y++;
}
x++;
}
}
int render(t_data *data)
{
if (data->update == 1)
{
x = -1;
while (++x < (data->w_screen / 128))
{
y = -1;
while (++y < (data->h_screen / 128))
{
if (x * 128 != data->x_player || y * 128 != data->y_player)
{
data->mlx_img = mlx_xpm_file_to_image(data->mlx, "assets/background.xpm", &data->size, &data->size);
mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, x * 128, y *128);
}
}
}
draw_map(data);
data->mlx_img = mlx_xpm_file_to_image(data->mlx, "assets/player.xpm", &data->size, &data->size);
mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, data->x_player, data->y_player);
mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, data->x_player * data->size, data->y_player * data->size);
data->update = 0;
}
return (0);
@ -81,7 +158,33 @@ void init_data(t_data *data)
data->h_screen = 768;
data->w_screen = 768;
data->mlx = mlx_init();
data->mlx_win = mlx_new_window(data->mlx, data->w_screen, data->h_screen, "lili meli");
}
void get_map(char *argv[], t_data *data)
{
char *tmp_map;
char *map;
int i;
int fd;
fd = open(argv[1], O_RDONLY);
if (fd == -1)
return ;
i = 0;
map = NULL;
tmp_map = NULL;
while (i == 0 || tmp_map != NULL)
{
tmp_map = get_next_line(fd);
if (tmp_map && map)
map = ft_strjoin(map, tmp_map);
else if (tmp_map)
map = tmp_map;
i++;
}
data->map = ft_split(map, '\n');
data->h_screen = (i - 1) * data->size;
data->w_screen = ft_strlen(*data->map) * data->size;
}
int main(int argc, char *argv[])
@ -90,8 +193,12 @@ int main(int argc, char *argv[])
(void)argc;
(void)argv;
map = get_map(argc, argv);
init_data(&data);
get_map(argv, &data);
if (data.map == NULL)
return (1);
set_position_player(&data, get_position(&data, 'P'));
data.mlx_win = mlx_new_window(data.mlx, data.w_screen, data.h_screen, "lili meli");
mlx_hook(data.mlx_win, 17, 0, quit, &data);
mlx_key_hook(data.mlx_win, key_hook, &data);
mlx_loop_hook(data.mlx, render, &data);

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/10 17:59:18 by erey-bet #+# #+# */
/* Updated: 2022/12/11 14:47:20 by erey-bet ### ########.fr */
/* Updated: 2022/12/12 20:53:26 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,12 +18,16 @@
# include "key.h"
# include <stdlib.h>
# include "libft/libft.h"
# include "get_next_line/get_next_line.h"
# include <fcntl.h>
typedef struct s_data
{
void *mlx;
void *mlx_win;
void *mlx_img;
char **map;
int update;
int size;
int x_player;
@ -32,4 +36,10 @@ typedef struct s_data
int w_screen;
} t_data;
typedef struct s_xy
{
int x;
int y;
} t_xy;
#endif

BIN
so_long.o Normal file

Binary file not shown.