This commit is contained in:
kinou-p 2022-02-13 22:28:48 +01:00
parent bee17fcc1b
commit 2e17e4a4d9
3 changed files with 87 additions and 55 deletions

63
main.c
View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */ /* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
/* Updated: 2022/02/13 22:02:38 by apommier ### ########.fr */ /* Updated: 2022/02/13 22:26:17 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,15 +20,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
typedef struct s_data {
void *mlx;
void *mlx_win;
char **map_tab;
int item;
int move;
int bear;
} t_data;
size_t ft_strlen_double(char **s) size_t ft_strlen_double(char **s)
{ {
size_t i; size_t i;
@ -65,13 +56,17 @@ int *choose_bear(t_data *img)
buffer = 0; buffer = 0;
if (img->bear == 119) if (img->bear == 119)
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/back_bear.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/back_bear.xpm",
&img_width, &img_height);
else if (img->bear == 97) else if (img->bear == 97)
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/left_bear.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/left_bear.xpm",
&img_width, &img_height);
else if (img->bear == 100) else if (img->bear == 100)
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/right_bear.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/right_bear.xpm",
&img_width, &img_height);
else else
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/front_bear.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/front_bear.xpm",
&img_width, &img_height);
if (buffer == 0) if (buffer == 0)
return (0); return (0);
return (buffer); return (buffer);
@ -84,15 +79,19 @@ void print_case(char type, t_data *img, int y, int x)
int img_height; int img_height;
if (type == '1') if (type == '1')
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/snow_tree.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/snow_tree.xpm",
&img_width, &img_height);
else if (type == 'P') else if (type == 'P')
buffer = choose_bear(img); buffer = choose_bear(img);
else if (type == 'C') else if (type == 'C')
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/honey.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/honey.xpm",
&img_width, &img_height);
else if (type == 'E') else if (type == 'E')
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/exit.XPM", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/exit.XPM",
&img_width, &img_height);
else else
buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/back.xpm", &img_width, &img_height); buffer = mlx_xpm_file_to_image(img->mlx, "./sprite/back.xpm",
&img_width, &img_height);
mlx_put_image_to_window(img->mlx, img->mlx_win, buffer, x * 32, y * 32); mlx_put_image_to_window(img->mlx, img->mlx_win, buffer, x * 32, y * 32);
mlx_destroy_image(img->mlx, buffer); mlx_destroy_image(img->mlx, buffer);
} }
@ -181,14 +180,36 @@ int key_press(int code, t_data *img)
return (1); return (1);
} }
char **set_map(char **argv)
{
char **map;
char *map_line;
char *del;
char *swap;
int fd;
fd = open(argv[1], O_RDONLY);
swap = get_next_line(fd);
while (swap)
{
del = map;
map = ft_strjoin(map, swap);
free(swap);
swap = get_next_line(fd);
free(del);
}
return (map);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
t_data img; t_data img;
char *map = 0; char *map;
int fd = 0; int fd;
char *swap = 0; char *swap;
char *del; char *del;
map = 0;
(void)argc; (void)argc;
img.bear = 0; img.bear = 0;
img.move = 0; img.move = 0;

View File

@ -3,18 +3,15 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* parsing.c :+: :+: :+: */ /* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: apommier <apommier@student.4map.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: map0map/0map/13 16:map1:43 by apommier #+# #+# */ /* Created: 2022/02/13 22:26:34 by apommier #+# #+# */
/* Updated: map0map/0map/13 map1:map4:44 by apommier ### ########.fr */ /* Updated: 2022/02/13 22:28:18 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "so_long.h" #include "so_long.h"
#include "./libft/libft.h" #include "./libft/libft.h"
#include <stdio.h>
int is_player(char **map) int is_player(char **map)
{ {
@ -62,7 +59,6 @@ int is_exit(char **map)
if (exit > 0) if (exit > 0)
return (1); return (1);
return (0); return (0);
} }
int is_item(char **map) int is_item(char **map)
@ -99,7 +95,8 @@ int is_rectangle(char **map)
i = 1; i = 1;
while (map[j][i]) while (map[j][i])
{ {
if (map[j][i] != '0' && map[j][i] != '1' && map[j][i] != 'P' && map[j][i] != 'E' && map[j][i] != 'C') if (map[j][i] != '0' && map[j][i] != '1' && map[j][i] != 'P'
&& map[j][i] != 'E' && map[j][i] != 'C')
return (0); return (0);
i++; i++;
} }

View File

@ -6,8 +6,22 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */ /* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
/* Updated: 2022/02/13 19:14:29 by apommier ### ########.fr */ /* Updated: 2022/02/13 22:12:14 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef SO_LONG_H
# define SO_LONG_H
typedef struct s_data {
void *mlx;
void *mlx_win;
char **map_tab;
int item;
int move;
int bear;
} t_data;
int check_map(char **map); int check_map(char **map);
#endif