avant d'aller bosser a carreouf

This commit is contained in:
Theo Champion 2025-06-24 00:17:33 +02:00
parent b185cddbf0
commit 321ef3db7c
7 changed files with 393 additions and 288 deletions

View file

@ -6,28 +6,19 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
/* Updated: 2025/06/20 23:58:56 by tchampio ### ########.fr */
/* Updated: 2025/06/22 00:17:39 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/libft.h"
#include "../includes/cub3d_consts.h"
#include "../includes/structs.h"
#include "../mlx/mlx.h"
#include "../includes/maputils.h"
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
typedef struct s_mlx_data
{
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
} t_mlx_data;
void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color)
{
char *dst;
@ -36,6 +27,24 @@ void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color)
*(unsigned int*)dst = color;
}
void draw_2d_wall(unsigned int color, t_mlx_data *data, int size, int x, int y)
{
int i;
int j;
i = 0;
while (i < size)
{
j = 0;
while (j < size)
{
my_mlx_pixel_put(data, x + i, y + j, color);
j++;
}
i++;
}
}
void free_tab(char **tab)
{
int i;
@ -54,10 +63,10 @@ int destroy(t_mapdata *map)
{
free_tab(map->map);
free_tab(map->mapflood);
free(map->EA_texture);
free(map->NO_texture);
free(map->SO_texture);
free(map->WE_texture);
free(map->ea_texture);
free(map->no_texture);
free(map->so_texture);
free(map->we_texture);
free(map->filename);
exit(0);
return 0;
@ -70,14 +79,31 @@ int key_destroy(int keycode, t_mapdata *map)
return (0);
}
void draw_map(t_mapdata *map, t_mlx_data *data)
{
int i;
int j;
i = 0;
while (map->map[i])
{
j = 0;
while (map->map[i][j])
{
if (map->map[i][j] == '1')
draw_2d_wall(map->f_color, data, 10, 10 * j, 10 * i);
else if (ft_strchr("NSEW", map->map[i][j]))
draw_2d_wall(0x00FF0000, data, 10, 10 * j, 10 * i);
j++;
}
i++;
}
}
int main(int argc, char **argv)
{
void *mlx;
void *mlx_win;
char *xpm = "./ressources/test.xpm";
void *xpm_image;
int xpm_height;
int xpm_width;
t_mlx_data data;
t_mapdata map;
@ -90,11 +116,9 @@ int main(int argc, char **argv)
mlx_win = mlx_new_window(mlx, 800, 600, "Cub3d");
data.img = mlx_new_image(mlx, 800, 600);
data.addr = mlx_get_data_addr(data.img, &data.bits_per_pixel, &data.line_length, &data.endian);
xpm_image = mlx_xpm_file_to_image(mlx, xpm, &xpm_width, &xpm_height);
//my_mlx_pixel_put(&data, 5, 5, 0x00FF0000);
mlx_hook(mlx_win, 17, 0L, destroy, &map);
draw_map(&map, &data);
mlx_key_hook(mlx_win, key_destroy, &map);
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
mlx_put_image_to_window(mlx, mlx_win, xpm_image, 0, 0);
mlx_loop(mlx);
}