Skip to content

Commit 8c58413

Browse files
committed
add bonus and mandatory rules
1 parent 122ea13 commit 8c58413

File tree

130 files changed

+1255
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1255
-23
lines changed

Makefile

+41-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
NAME = cub3D
22

3-
LIBFT = srcs/libft
3+
LIBFT = libft
44
LIBMLX = ./MLX42/build/libmlx42.a
55

66
OBJS_DIR = .objs
7-
SRCS = main.c \
8-
srcs/cub3d/init_and_unit/init_and_unit.c \
9-
srcs/cub3d/parsing/check_file.c \
10-
srcs/cub3d/parsing/check_map.c \
11-
srcs/cub3d/window_and_event/window.c \
12-
srcs/cub3d/window_and_event/event_hooks.c \
13-
srcs/cub3d/utils/utils.c \
14-
srcs/cub3d/rendering/raycasting/raycasting.c \
15-
srcs/cub3d/rendering/raycasting/raycasting_utils.c \
16-
srcs/cub3d/rendering/minimap/minimap.c \
17-
srcs/cub3d/rendering/minimap/minimap_utils.c
7+
SRCS = mandatory/main.c \
8+
mandatory/srcs/cub3d/init_and_unit/init_and_unit.c \
9+
mandatory/srcs/cub3d/parsing/check_file.c \
10+
mandatory/srcs/cub3d/parsing/check_map.c \
11+
mandatory/srcs/cub3d/window_and_event/window.c \
12+
mandatory/srcs/cub3d/window_and_event/event_hooks.c \
13+
mandatory/srcs/cub3d/utils/utils.c \
14+
mandatory/srcs/cub3d/rendering/raycasting/raycasting.c \
15+
mandatory/srcs/cub3d/rendering/raycasting/raycasting_utils.c \
16+
mandatory/srcs/cub3d/rendering/minimap/minimap.c \
17+
mandatory/srcs/cub3d/rendering/minimap/minimap_utils.c
18+
19+
# SRCS_BONUS = bonus/main.c \
20+
# bonus/srcs/cub3d/init_and_unit/init_and_unit.c \
21+
# bonus/srcs/cub3d/parsing/check_file.c \
22+
# bonus/srcs/cub3d/parsing/check_map.c \
23+
# bonus/srcs/cub3d/window_and_event/window.c \
24+
# bonus/srcs/cub3d/window_and_event/event_hooks.c \
25+
# bonus/srcs/cub3d/utils/utils.c \
26+
# bonus/srcs/cub3d/rendering/raycasting/raycasting.c \
27+
# bonus/srcs/cub3d/rendering/raycasting/raycasting_utils.c \
28+
# bonus/srcs/cub3d/rendering/minimap/minimap.c \
29+
# bonus/srcs/cub3d/rendering/minimap/minimap_utils.c
1830

1931
OBJS = $(addprefix $(OBJS_DIR)/, $(SRCS:%.c=%.o))
20-
32+
OBJS_BONUS = $(addprefix $(OBJS_DIR)/, $(SRCS_BONUS:%.c=%.o))
2133

2234
OS = $(shell uname)
2335
FLAG_OPTI = -Ofast -ffast-math -O3
@@ -32,10 +44,6 @@ endif
3244

3345
CFLAGS = -I $(LIBFT) -Wall -Werror -Wextra -g -ggdb3 -fsanitize=address
3446
LDFLAGS = -lft -L $(LIBFT) -Wall -Werror -Wextra -g -ggdb3 -fsanitize=address
35-
FLAG = $(LIBMLX) -Iinclude
36-
LINUXFLAG2 = -lglfw -lm -lGL $(FLAG_OPTI)
37-
MACOSFLAG = -L "/Users/$(USER)/.brew/opt/glfw/lib/" -lglfw -lm -O3 -Ofast -ffast-math -framework Cocoa -framework OpenGL -framework IOKit $(FLAG_OPTI)
38-
FLAG_OPTI = -Ofast -ffast-math -O3
3947

4048
RED=\033[0;31m
4149
GREEN=\033[0;32m
@@ -56,6 +64,21 @@ $(OBJS_DIR)/%.o: %.c | $(OBJS_DIR)
5664
$(OBJS_DIR):
5765
mkdir -p $(dir $(OBJS))
5866

67+
# bonus: $(NAME)
68+
69+
# $(LIBFT)/libft.a:
70+
# $(MAKE) -C $(LIBFT)
71+
72+
# $(NAME): $(OBJS_BONUS) $(LIBFT)/libft.a
73+
# @gcc $(OBJS_BONUS) $(LDFLAGS) $(FLAG) $(PROJECT_FLAGS) -o $(NAME)
74+
# @echo "${GREEN}./${NAME} ${RED}map${NC}"
75+
76+
# $(OBJS_DIR)/%.o: %.c | $(OBJS_DIR)
77+
# @gcc $(CFLAGS) $(FLAG_OPTI) $ -c $< -o $@
78+
79+
# $(OBJS_DIR):
80+
# mkdir -p $(dir $(OBJS_BONUS))
81+
5982
clean:
6083
$(MAKE) -C $(LIBFT) clean
6184
@rm -rf $(OBJS_DIR)
@@ -67,6 +90,6 @@ fclean: clean
6790
re: fclean all
6891

6992
run: all
70-
./$(NAME) maps/cub.cub
93+
./$(NAME) rsrcs/maps/cub.cub
7194

7295
.PHONY: all clean fclean re run

includes/cub3d.h bonus/includes/cub3d.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# define CUB3D_H
1515

1616
# include "../MLX42/include/MLX42/MLX42.h"
17-
# include "../srcs/libft/includes/libft.h"
17+
# include "../libft/includes/libft.h"
1818
# include "macros.h"
1919
# include <errno.h>
2020
# include <limits.h>
File renamed without changes.

main.c bonus/main.c

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

srcs/libft/Makefile libft/Makefile

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

mandatory/includes/cub3d.h

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* cub3d.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/06/24 10:38:12 by mvpee #+# #+# */
9+
/* Updated: 2024/06/24 10:38:12 by mvpee ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef CUB3D_H
14+
# define CUB3D_H
15+
16+
# include "../MLX42/include/MLX42/MLX42.h"
17+
# include "../libft/includes/libft.h"
18+
# include "macros.h"
19+
# include <errno.h>
20+
# include <limits.h>
21+
# include <math.h>
22+
# include <stdbool.h>
23+
# include <stdio.h>
24+
25+
typedef mlx_image_t t_img;
26+
typedef mlx_key_data_t t_mlx_key;
27+
28+
typedef enum e_move
29+
{
30+
GO_RIGHT,
31+
GO_LEFT,
32+
GO_UP,
33+
GO_DOWN,
34+
ROTATE_LEFT,
35+
ROTATE_RIGHT
36+
} t_move;
37+
38+
typedef struct s_player_pos
39+
{
40+
double x;
41+
double y;
42+
int angle;
43+
} t_player_pos;
44+
45+
// RAYCAST STRUCTURES
46+
typedef struct s_distance
47+
{
48+
float x;
49+
float y;
50+
float angle_rad;
51+
float step_x;
52+
float step_y;
53+
int prev_x;
54+
int prev_y;
55+
float distance;
56+
} t_distance;
57+
58+
typedef struct s_raycast
59+
{
60+
float distance;
61+
float rotation;
62+
float wall_height;
63+
int texture_x;
64+
int texture_y;
65+
float hit_x;
66+
float hit_y;
67+
float hit_pos;
68+
int color;
69+
int x;
70+
int y;
71+
mlx_image_t *wall_img;
72+
} t_raycast;
73+
74+
typedef struct s_minimap
75+
{
76+
t_img *image;
77+
int **map_input;
78+
int **map_output;
79+
int black;
80+
int white;
81+
int transparent;
82+
int transparent_black;
83+
int transparent_white;
84+
int x_adjust;
85+
int y_adjust;
86+
int map_x;
87+
int map_y;
88+
} t_minimap;
89+
90+
typedef struct s_data
91+
{
92+
t_img *north_image;
93+
t_img *south_image;
94+
t_img *west_image;
95+
t_img *east_image;
96+
int floor_color;
97+
int ceiling_color;
98+
char **file;
99+
char **map;
100+
size_t map_width;
101+
size_t map_height;
102+
char wall_dir;
103+
mlx_t *mlx;
104+
t_img *floor_image;
105+
t_img *ceiling_image;
106+
t_img *image;
107+
t_player_pos *player;
108+
t_minimap *minimap;
109+
bool *keys;
110+
} t_data;
111+
112+
// PARSING
113+
bool check_extension(char *str);
114+
bool check_file(t_data *data);
115+
bool check_map(char ***map);
116+
117+
// GRAPHICS
118+
int game_loop(t_data *data);
119+
120+
// KEY_HOOKS
121+
void move_keyhook(void *param);
122+
123+
// UTILS
124+
int get_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
125+
void get_player_pos(t_data *data);
126+
void get_map_size(t_data *data);
127+
int get_correct_color(u_int8_t *pixel);
128+
129+
// RAYCASTING
130+
void raycasting(t_data *data);
131+
132+
// MINIMAP
133+
void minimap(t_data *data);
134+
bool is_in_circle(int x, int y);
135+
void draw_square(t_minimap *minimap, int x, int y, char c);
136+
void get_adjust_coord(t_data *data);
137+
void map_init(t_data *data);
138+
139+
// RAYCASTING UTILS
140+
float get_distance(t_data *data, float rotation, float *hit_x, float *hit_y);
141+
142+
// INIT AND UNIT
143+
bool init_data(t_data *data);
144+
void free_data(t_data *data);
145+
#endif

mandatory/includes/macros.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* macros.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/06/06 13:08:32 by nechaara #+# #+# */
9+
/* Updated: 2024/06/26 15:59:30 by mvpee ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef MACROS_H
14+
# define MACROS_H
15+
16+
// MACROS
17+
# define PROGRAM_NAME "CUB3D"
18+
19+
// ERROR
20+
# define WIN_INIT_FAILED "Windows initialization failed, check MLX\n"
21+
# define INVALID_MAP "Error\nInvalid map in y: %d x:%d c:'%c'\n"
22+
# define INVALID_BORDER "Error\nBad Border\n"
23+
# define WRONG_PLAYER_COUNT "Error\nWrong player count\n"
24+
# define NUMBERS_OF_ARGUMENTS "Error\nNumber of argument(s)\n"
25+
// COLOR
26+
# define RED "\x1b[31m"
27+
# define GREEN "\x1b[32m"
28+
# define BLUE "\x1b[34m"
29+
# define BLACK "\x1b[30m"
30+
# define WHITE "\x1b[37m"
31+
# define PINK "\x1b[35m"
32+
# define YELLOW "\x1b[33m"
33+
# define BROWN "\x1b[33m"
34+
# define ORANGE "\x1b[33m"
35+
# define PURPLE "\x1b[35m"
36+
# define GRAY "\x1b[90m"
37+
# define LIGHTGRAY "\x1b[37m"
38+
# define DARKGRAY "\x1b[90m"
39+
# define RESET "\x1b[0m"
40+
41+
// MOVEMENT MACROS
42+
# define RADIANT 0.0174533
43+
# define PIXEL 128
44+
# define SPEED 8
45+
# define SPEED_ROTATION 5
46+
# define DEGREE 0.0833333333333333
47+
# define FOV 60
48+
# define F_PI 57.2957795131
49+
50+
// RESOLUTION
51+
# define WIDTH 1080
52+
# define HEIGHT 720
53+
54+
// MINIMAP
55+
# define MINIMAP_SIZE 200
56+
# define WALL_SIZE 20
57+
# define PLAYER_SIZE 10
58+
59+
// KEY
60+
# define MLX_KEY_Z 87
61+
# define MLX_KEY_S 83
62+
# define MLX_KEY_Q 65
63+
# define MLX_KEY_D 68
64+
# define MLX_KEY_RIGHT 262
65+
# define MLX_KEY_LEFT 263
66+
# define MLX_KEY_ESCAPE 256
67+
# define MLX_KEY_SHIFT 340
68+
69+
#endif

mandatory/main.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* main.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mvpee <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024/06/11 09:16:29 by mvpee #+# #+# */
9+
/* Updated: 2024/06/11 09:16:29 by mvpee ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "includes/cub3d.h"
14+
15+
int main(int ac, char **av)
16+
{
17+
t_data data;
18+
char *temp;
19+
20+
temp = NULL;
21+
if (ac != 2)
22+
return (ft_printf_fd(2, RED NUMBERS_OF_ARGUMENTS RESET), 1);
23+
if (init_data(&data))
24+
return (ft_printf_fd(2, RED WIN_INIT_FAILED RESET), 1);
25+
if (check_extension(av[1]))
26+
return (free_data(&data), 1);
27+
temp = ft_read(open(av[1], O_RDONLY));
28+
data.file = ft_split(temp, "\n");
29+
if (!data.file)
30+
return (ft_free(1, &temp), free_data(&data), 1);
31+
ft_free(1, &temp);
32+
if (check_file(&data))
33+
return (free_data(&data), 1);
34+
if (check_map(&data.map))
35+
return (free_data(&data), 1);
36+
get_map_size(&data);
37+
get_player_pos(&data);
38+
if (game_loop(&data))
39+
return (free_data(&data), 1);
40+
return (free_data(&data), 0);
41+
}

0 commit comments

Comments
 (0)