2024-01-09 16:12:58 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* print_map.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2024/01/09 15:30:06 by adjoly #+# #+# */
|
2024-01-13 19:04:22 +01:00
|
|
|
/* Updated: 2024/01/13 17:56:32 by adjoly ### ########.fr */
|
2024-01-09 16:12:58 +01:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2024-01-09 17:11:35 +01:00
|
|
|
#include "MacroLibX/includes/mlx.h"
|
2024-01-09 16:12:58 +01:00
|
|
|
#include "libft/libft.h"
|
2024-01-13 19:04:22 +01:00
|
|
|
#include "printf/ft_printf.h"
|
2024-01-09 16:12:58 +01:00
|
|
|
#include "so_long.h"
|
2024-01-13 17:17:22 +01:00
|
|
|
#include <stdio.h>
|
2024-01-10 15:14:24 +01:00
|
|
|
#include <stddef.h>
|
2024-01-09 16:12:58 +01:00
|
|
|
|
2024-01-13 17:17:22 +01:00
|
|
|
void ft_putimg(size_t x, size_t y, t_window *win, char *file_path)
|
2024-01-09 16:12:58 +01:00
|
|
|
{
|
2024-01-09 17:11:35 +01:00
|
|
|
int img_x;
|
|
|
|
int img_y;
|
2024-01-10 10:46:24 +01:00
|
|
|
|
2024-01-09 17:11:35 +01:00
|
|
|
img_x = 0;
|
|
|
|
img_y = 0;
|
|
|
|
ft_putstr_fd(file_path, 1);
|
|
|
|
ft_putchar_fd('\n', 1);
|
|
|
|
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);
|
2024-01-09 16:12:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-10 15:14:24 +01:00
|
|
|
void ft_printmap(char **map, t_window *win)
|
2024-01-09 16:12:58 +01:00
|
|
|
{
|
2024-01-13 17:17:22 +01:00
|
|
|
int x;
|
|
|
|
int y;
|
2024-01-09 16:12:58 +01:00
|
|
|
|
|
|
|
y = 0;
|
2024-01-13 19:04:22 +01:00
|
|
|
// win->c_count = malloc(1 * sizeof(size_t));
|
2024-01-13 17:17:22 +01:00
|
|
|
win->c_count = 0;
|
2024-01-09 16:12:58 +01:00
|
|
|
while (map[y])
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
while (map[y][x])
|
|
|
|
{
|
|
|
|
if (map[y][x] == '1')
|
2024-01-13 17:17:22 +01:00
|
|
|
ft_putimg(x, y, win, W_PNG);
|
2024-01-09 16:12:58 +01:00
|
|
|
else if (map[y][x] == '0')
|
2024-01-13 17:17:22 +01:00
|
|
|
ft_putimg(x, y, win, G_PNG);
|
2024-01-09 16:12:58 +01:00
|
|
|
else if (map[y][x] == 'C')
|
2024-01-13 17:17:22 +01:00
|
|
|
{
|
|
|
|
ft_putimg(x, y, win, C_PNG);
|
|
|
|
win->c_count++;
|
|
|
|
}
|
2024-01-09 16:12:58 +01:00
|
|
|
else if (map[y][x] == 'E')
|
2024-01-13 19:04:22 +01:00
|
|
|
{
|
|
|
|
win->e_coords = malloc(sizeof(t_coords *));
|
|
|
|
win->e_coords->x = x;
|
|
|
|
win->e_coords->y = y;
|
2024-01-13 17:17:22 +01:00
|
|
|
ft_putimg(x, y, win, E_PNG);
|
2024-01-13 19:04:22 +01:00
|
|
|
}
|
2024-01-12 11:25:48 +01:00
|
|
|
else if (map[y][x] == 'P')
|
2024-01-13 17:17:22 +01:00
|
|
|
{
|
|
|
|
win->p_coords = malloc(sizeof(t_coords *));
|
|
|
|
win->p_coords->y = y;
|
|
|
|
win->p_coords->x = x;
|
|
|
|
ft_putimg(x, y, win, P_PNG);
|
|
|
|
}
|
2024-01-09 16:12:58 +01:00
|
|
|
x++;
|
|
|
|
}
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
}
|