mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
started to move all variables to a struct
This commit is contained in:
parent
f9825feeea
commit
c1484d2d3c
6 changed files with 74 additions and 31 deletions
5
Makefile
5
Makefile
|
|
@ -1,7 +1,6 @@
|
||||||
CC=cc
|
CC=cc
|
||||||
SANITIZERS=
|
SANITIZERS=-fsanitize=address -fno-omit-frame-pointer
|
||||||
#-fsanitize-address -fno-omit-frame-pointer
|
CFLAGS=-Wall -Wextra -Werror -ggdb $(SANITIZERS) -I mlx
|
||||||
CFLAGS=-Wall -Wextra -Werror -g $(SANITIZERS) -I mlx
|
|
||||||
SOURCEFILES=src/main.c \
|
SOURCEFILES=src/main.c \
|
||||||
src/map/map_checker.c \
|
src/map/map_checker.c \
|
||||||
src/map/checkers.c \
|
src/map/checkers.c \
|
||||||
|
|
|
||||||
15
README.md
15
README.md
|
|
@ -2,3 +2,18 @@
|
||||||
|
|
||||||
## Probleme possible avec la MLX sur un pc perso
|
## Probleme possible avec la MLX sur un pc perso
|
||||||
attention /usr/bin/cc doit rediriger vers /usr/bin/clang
|
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
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/21 19:46:20 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];
|
char error[1024];
|
||||||
} t_mapdata;
|
} t_mapdata;
|
||||||
|
|
||||||
|
typedef struct s_cub3d_data
|
||||||
|
{
|
||||||
|
void *mlx;
|
||||||
|
void *mlx_win;
|
||||||
|
t_mlx_data *mlx_data;
|
||||||
|
t_mapdata *map;
|
||||||
|
} t_cub3d_data;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
25
ressources/bad_maps/wrongmap_end_letter.cub
Normal file
25
ressources/bad_maps/wrongmap_end_letter.cub
Normal 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
|
||||||
47
src/main.c
47
src/main.c
|
|
@ -6,12 +6,11 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
/* 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/libft.h"
|
||||||
#include "../includes/cub3d_consts.h"
|
|
||||||
#include "../includes/structs.h"
|
#include "../includes/structs.h"
|
||||||
#include "../mlx/mlx.h"
|
#include "../mlx/mlx.h"
|
||||||
#include "../includes/maputils.h"
|
#include "../includes/maputils.h"
|
||||||
|
|
@ -24,10 +23,11 @@ void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color)
|
||||||
char *dst;
|
char *dst;
|
||||||
|
|
||||||
dst = data->addr + (y * data->line_length + x * (data->bits_per_pixel / 8));
|
dst = data->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 i;
|
||||||
int j;
|
int j;
|
||||||
|
|
@ -85,15 +85,15 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (map->mapflood[i])
|
while (map->map[i])
|
||||||
{
|
{
|
||||||
j = 0;
|
j = 0;
|
||||||
while (map->mapflood[i][j])
|
while (map->map[i][j])
|
||||||
{
|
{
|
||||||
if (map->mapflood[i][j] == '1')
|
if (map->map[i][j] == '1')
|
||||||
draw_2d_wall(map->f_color, data, 10, 10 * j, 10 * i);
|
draw_2d_wall(map->f_color, data, 20, 20 * j, 20 * i);
|
||||||
else if (ft_strchr("NSEW", map->map[i][j]))
|
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++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -102,23 +102,20 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
void *mlx;
|
t_cub3d_data data;
|
||||||
void *mlx_win;
|
|
||||||
t_mlx_data data;
|
|
||||||
t_mapdata map;
|
|
||||||
|
|
||||||
ft_bzero(&map, sizeof(map));
|
data.map = ft_calloc(sizeof(t_mapdata), 1);
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
||||||
if (!check_cubfile(argv[1], &map))
|
if (!check_cubfile(argv[1], data.map))
|
||||||
return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1);
|
return (ft_printf("Error: Wrong map file. Reason: %s\n", data.map->error), 1);
|
||||||
mlx = mlx_init();
|
data.mlx = mlx_init();
|
||||||
mlx_win = mlx_new_window(mlx, 800, 600, "Cub3d");
|
data.mlx_win = mlx_new_window(data.mlx, 800, 600, "Cub3d");
|
||||||
data.img = mlx_new_image(mlx, 800, 600);
|
data.mlx_data->img = mlx_new_image(data.mlx, 800, 600);
|
||||||
data.addr = mlx_get_data_addr(data.img, &data.bits_per_pixel, &data.line_length, &data.endian);
|
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(mlx_win, 17, 0L, destroy, &map);
|
mlx_hook(data.mlx_win, 17, 0L, destroy, data.map);
|
||||||
draw_map(&map, &data);
|
draw_map(data.map, data.mlx_data);
|
||||||
mlx_key_hook(mlx_win, key_destroy, &map);
|
mlx_key_hook(data.mlx_win, key_destroy, data.map);
|
||||||
mlx_put_image_to_window(mlx, mlx_win, data.img, 0, 0);
|
mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0);
|
||||||
mlx_loop(mlx);
|
mlx_loop(data.mlx);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
/* 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 ;
|
return ;
|
||||||
if (map->mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n')
|
if (map->mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n')
|
||||||
map->isvalid = false;
|
map->isvalid = false;
|
||||||
|
|
||||||
map->mapflood[y][x] = '1';
|
map->mapflood[y][x] = '1';
|
||||||
flood_fill(map, x + 1, y);
|
flood_fill(map, x + 1, y);
|
||||||
flood_fill(map, x, y + 1);
|
flood_fill(map, x, y + 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue