started to move all variables to a struct

This commit is contained in:
Theo Champion 2025-06-24 11:51:49 +02:00
parent f9825feeea
commit c1484d2d3c
6 changed files with 74 additions and 31 deletions

View file

@ -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 \

View file

@ -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

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -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

View file

@ -6,12 +6,11 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
/* Updated: 2025/06/24 10:40:02 by tchampio ### ########.fr */
/* Updated: 2025/06/24 11:50:17 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/libft.h"
#include "../includes/cub3d_consts.h"
#include "../includes/structs.h"
#include "../mlx/mlx.h"
#include "../includes/maputils.h"
@ -27,7 +26,8 @@ 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)
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);
}

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
/* Updated: 2025/06/24 10:40:30 by tchampio ### ########.fr */
/* Updated: 2025/06/24 11:31:48 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -59,7 +59,6 @@ void flood_fill(t_mapdata *map, int x, int y)
return ;
if (map->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);