diff --git a/Makefile b/Makefile index 669aa2e..0678d5e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ CC=cc -SANITIZERS= -#-fsanitize-address -fno-omit-frame-pointer -CFLAGS=-Wall -Wextra -Werror -g $(SANITIZERS) -I mlx +SANITIZERS=-fsanitize=address -fno-omit-frame-pointer +CFLAGS=-Wall -Wextra -Werror -ggdb $(SANITIZERS) -I mlx SOURCEFILES=src/main.c \ src/map/map_checker.c \ src/map/checkers.c \ diff --git a/README.md b/README.md index aaef04f..163d008 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,18 @@ ## Probleme possible avec la MLX sur un pc perso attention /usr/bin/cc doit rediriger vers /usr/bin/clang + +## liste des symboles +1 - mur +0 - espace vide +D - porte tel que defini dans le sujet +d - porte a points (cod) +Z - zombie +z - spawner zombie (porte a six coups pour les zombies) +S - source de son +M - boite magique + +## idées (avec symboles si possible) +C - arme dessinée sur le mur + +faire un systeme de "cheats" soit par un menu de debug soit par une ligne de commande intégrée dans le jeu diff --git a/includes/structs.h b/includes/structs.h index 1b29521..e933ffd 100644 --- a/includes/structs.h +++ b/includes/structs.h @@ -6,7 +6,7 @@ /* By: tchampio +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:46:20 by tchampio #+# #+# */ -/* Updated: 2025/06/21 19:48:20 by tchampio ### ########.fr */ +/* Updated: 2025/06/24 11:47:02 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,4 +50,12 @@ typedef struct s_mapdata char error[1024]; } t_mapdata; +typedef struct s_cub3d_data +{ + void *mlx; + void *mlx_win; + t_mlx_data *mlx_data; + t_mapdata *map; +} t_cub3d_data; + #endif diff --git a/ressources/bad_maps/wrongmap_end_letter.cub b/ressources/bad_maps/wrongmap_end_letter.cub new file mode 100644 index 0000000..f40518b --- /dev/null +++ b/ressources/bad_maps/wrongmap_end_letter.cub @@ -0,0 +1,25 @@ +NO ./path_to_the_north_texture +SO ./path_to_the_south_texture +WE ./path_to_the_west_texture +EA ./path_to_the_east_texture + +F 220,100,0 +C 225,30,0 + + 1111111111111111111111111 + 1000000000110000000000001 + 1011000001110000000000001 + 1001000000000000000000001 +111111111011000001110000000000001 +100000000011000001110111110111111 +11110111111111011100000010001 +11110111111111011101010010001 +11000000110101011100000010001 +10000000000000001100000010001 +10000000000000001101010010001 +11000001110101011111011110N0111 +11110111 1110101 101111010001 +11111111 1111111 111111111111 + + +1 diff --git a/src/main.c b/src/main.c index 1bcd785..4348fe0 100644 --- a/src/main.c +++ b/src/main.c @@ -6,12 +6,11 @@ /* By: tchampio addr + (y * data->line_length + x * (data->bits_per_pixel / 8)); - *(unsigned int*)dst = color; + *(unsigned int *)dst = color; } -void draw_2d_wall(unsigned int color, t_mlx_data *data, int size, int x, int y) +void draw_2d_wall(unsigned int color, t_mlx_data *data, + int size, int x, int y) { int i; int j; @@ -85,15 +85,15 @@ void draw_map(t_mapdata *map, t_mlx_data *data) int j; i = 0; - while (map->mapflood[i]) + while (map->map[i]) { j = 0; - while (map->mapflood[i][j]) + while (map->map[i][j]) { - if (map->mapflood[i][j] == '1') - draw_2d_wall(map->f_color, data, 10, 10 * j, 10 * i); + if (map->map[i][j] == '1') + draw_2d_wall(map->f_color, data, 20, 20 * j, 20 * i); else if (ft_strchr("NSEW", map->map[i][j])) - draw_2d_wall(0x00FF0000, data, 10, 10 * j, 10 * i); + draw_2d_wall(0x00FF0000, data, 20, 20 * j, 20 * i); j++; } i++; @@ -102,23 +102,20 @@ void draw_map(t_mapdata *map, t_mlx_data *data) int main(int argc, char **argv) { - void *mlx; - void *mlx_win; - t_mlx_data data; - t_mapdata map; + t_cub3d_data data; - ft_bzero(&map, sizeof(map)); + data.map = ft_calloc(sizeof(t_mapdata), 1); if (argc < 2) return (ft_printf("Error: Missing cub3d file\n"), 1); - if (!check_cubfile(argv[1], &map)) - return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1); - mlx = mlx_init(); - 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); - 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_loop(mlx); + if (!check_cubfile(argv[1], data.map)) + return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1); + data.mlx = mlx_init(); + data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d"); + data.mlx_data->img = mlx_new_image(data.mlx, 800, 600); + data.mlx_data->addr = mlx_get_data_addr(data.mlx_data->img, &data.mlx_data->bits_per_pixel, &data.mlx_data->line_length, &data.mlx_data->endian); + mlx_hook(data.mlx_win, 17, 0L, destroy, data.map); + draw_map(data.map, data.mlx_data); + mlx_key_hook(data.mlx_win, key_destroy, data.map); + mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0); + mlx_loop(data.mlx); } diff --git a/src/map/map_checker.c b/src/map/map_checker.c index adb2560..d556197 100644 --- a/src/map/map_checker.c +++ b/src/map/map_checker.c @@ -6,7 +6,7 @@ /* By: tchampio mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n') map->isvalid = false; - map->mapflood[y][x] = '1'; flood_fill(map, x + 1, y); flood_fill(map, x, y + 1);