Archived
1
0

print map

This commit is contained in:
Adam Joly
2024-01-09 17:11:35 +01:00
parent 0dc9dcf954
commit 5b4c8866b8
5 changed files with 20 additions and 20 deletions

2
main.c
View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 16:18:56 by adjoly #+# #+# */ /* Created: 2024/01/06 16:18:56 by adjoly #+# #+# */
/* Updated: 2024/01/09 16:06:47 by adjoly ### ########.fr */ /* Updated: 2024/01/09 16:13:17 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,23 +6,25 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 15:30:06 by adjoly #+# #+# */ /* Created: 2024/01/09 15:30:06 by adjoly #+# #+# */
/* Updated: 2024/01/09 16:08:20 by adjoly ### ########.fr */ /* Updated: 2024/01/09 16:52:59 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "MacroLibX/includes/mlx.h"
#include "libft/libft.h" #include "libft/libft.h"
#include "so_long.h" #include "so_long.h"
#include <stddef.h>
int ft_putimg(int x, int y, void *param, char *file_path) void ft_putimg(int x, int y, t_window *win, char *file_path)
{ {
t_window *win; int img_x;
int img_y;
win = (t_window *)param; img_x = 0;
img_y = 0;
win->img = mlx_png_file_to_image(win->mlx, file_path, &x, &y); ft_putstr_fd(file_path, 1);
mlx_put_image_to_window(win->mlx, win->win, win->img, x * TEXTURE_SIZE, y * TEXTURE_SIZE); ft_putchar_fd('\n', 1);
return (0); win->img = mlx_png_file_to_image(win->mlx, file_path, &img_x, &img_y);
mlx_put_image_to_window(win->mlx, win->win, win->img, x * img_x, y * img_y);
} }
int ft_printmap(char **map, void *param) int ft_printmap(char **map, void *param)
@ -38,17 +40,16 @@ int ft_printmap(char **map, void *param)
x = 0; x = 0;
while (map[y][x]) while (map[y][x])
{ {
ft_putstr_fd("??", 1);
if (map[y][x] == '1') if (map[y][x] == '1')
ft_putimg(x, y, param, "assets/wall.png"); ft_putimg(x, y, win, "assets/wall.png");
else if (map[y][x] == '0') else if (map[y][x] == '0')
ft_putimg(x, y, param, "assets/ground.png"); ft_putimg(x, y, win, "assets/ground.png");
else if (map[y][x] == 'C') else if (map[y][x] == 'C')
ft_putimg(x, y, param, "assets/obj.png"); ft_putimg(x, y, win, "assets/obj.png");
else if (map[y][x] == 'E') else if (map[y][x] == 'E')
ft_putimg(x, y, param, "assets/exit.png"); ft_putimg(x, y, win, "assets/exit.png");
else if (map[y][x] == 'P') else if (map[y][x] == 'P')
ft_putimg(x, y, param, "assets/player.png"); ft_putimg(x, y, win, "assets/player.png");
x++; x++;
} }
y++; y++;

Binary file not shown.

BIN
so_long

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */ /* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */
/* Updated: 2024/01/09 16:09:17 by adjoly ### ########.fr */ /* Updated: 2024/01/09 16:17:27 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,7 +35,6 @@ int key_close(int key, void *param);
int ft_countline_fd(int fd); int ft_countline_fd(int fd);
char **ft_read_map(char *file_name); char **ft_read_map(char *file_name);
int ft_putimg(int x, int y, void *param, char *file_path);
int ft_printmap(char **map, void *param); int ft_printmap(char **map, void *param);
#endif #endif