-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zakaria Walad
committed
Mar 15, 2023
0 parents
commit e31a07b
Showing
27 changed files
with
2,624 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# Makefile :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: zwalad <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2022/12/26 19:54:07 by zwalad #+# #+# # | ||
# Updated: 2023/01/05 16:06:15 by zwalad ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
NAME := cub3D | ||
|
||
CC := @gcc | ||
|
||
FLAGS := -lmlx -framework OpenGL -framework AppKit | ||
|
||
CFLAGS = -Wall -Wextra -Werror | ||
|
||
HEADER = cub1d.h | ||
|
||
RM = @rm -rf | ||
|
||
SOURCE := main.c\ | ||
submain.c\ | ||
libft.c\ | ||
get/get_next_line.c\ | ||
get/get_next_line_utils.c\ | ||
minimap.c\ | ||
map_init.c\ | ||
map_init2.c\ | ||
map_init3.c\ | ||
moves.c\ | ||
src/get_dis.c \ | ||
src/get_3d_wall.c \ | ||
src/raycasting_help.c \ | ||
src/init_data.c \ | ||
src/init_data2.c \ | ||
player_init.c\ | ||
|
||
OBJCT = $(SOURCE:.c=.o) | ||
|
||
all: $(NAME) | ||
|
||
$(NAME) : $(OBJCT) $(HEADER) | ||
$(CC) $(SOURCE) $(FLAGS) -o $(NAME) | ||
|
||
clean: | ||
$(RM) $(OBJCT) | ||
|
||
fclean: clean | ||
$(RM) $(NAME) | ||
|
||
re: fclean all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* cub1d.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: zwalad <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/13 17:02:43 by zwalad #+# #+# */ | ||
/* Updated: 2023/01/05 18:52:28 by zwalad ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef CUB1D_H | ||
# define CUB1D_H | ||
|
||
# include "get/get_next_line.h" | ||
# include <mlx.h> | ||
# include <math.h> | ||
# include <limits.h> | ||
|
||
# define PI 3.14159 | ||
# define MIN 0.001 | ||
# define SIZE 32 | ||
# define STEPS 6 | ||
# define SIZEMINI 8 | ||
# define SIZE_IMG 64 | ||
# define WIDTH 1600 | ||
# define HEIGHT 800 | ||
# define NUMS_RAYS 1600 | ||
# define RED 0xFF0000 | ||
# define FOV 1.047197 | ||
|
||
typedef struct s_playerr | ||
{ | ||
double px; | ||
double py; | ||
double pdx; | ||
double pdy; | ||
double pa; | ||
}t_playerr; | ||
|
||
typedef enum s_side | ||
{ | ||
zero, | ||
north, | ||
south, | ||
east, | ||
west | ||
} t_player; | ||
|
||
typedef struct s_var | ||
{ | ||
double disttoplan; | ||
double projplan; | ||
double disttowall; | ||
int start; | ||
int end; | ||
}t_var; | ||
|
||
typedef struct s_line | ||
{ | ||
int dx; | ||
int dy; | ||
int yi; | ||
int xi; | ||
int y; | ||
int x; | ||
int diff; | ||
} t_line; | ||
|
||
typedef struct s_point | ||
{ | ||
int x; | ||
int y; | ||
} t_point; | ||
|
||
typedef struct s_image | ||
{ | ||
void *ptr; | ||
char *addr; | ||
int bts_pxt; | ||
int endn; | ||
int len; | ||
int width; | ||
int height; | ||
}t_image; | ||
|
||
typedef struct s_xtr | ||
{ | ||
t_image *n_orth; | ||
t_image *w_est; | ||
t_image *s_outh; | ||
t_image *e_ast; | ||
}t_xtr; | ||
|
||
typedef struct s_map | ||
{ | ||
int player; | ||
char **map; | ||
int ort; | ||
int i; | ||
double ip; | ||
int j; | ||
double jp; | ||
}t_map; | ||
|
||
typedef struct s_mlx | ||
{ | ||
void *mlx_ptr; | ||
void *win_ptr; | ||
void *player; | ||
}t_mlx; | ||
|
||
typedef struct s_content | ||
{ | ||
int no; | ||
int so; | ||
int we; | ||
int ea; | ||
int f; | ||
int c; | ||
int ff; | ||
int cc; | ||
char *north_p; | ||
char *south_p; | ||
char *west_p; | ||
char *east_p; | ||
int *fn; | ||
int *cn; | ||
} t_content; | ||
|
||
typedef struct s_rays | ||
{ | ||
double xsp; | ||
double ysp; | ||
double rayangle; | ||
double xi; | ||
double yi; | ||
double horzy; | ||
double horzx; | ||
double vrzay; | ||
double vrzax; | ||
double prop; | ||
int view_down; | ||
int view_up; | ||
int view_right; | ||
int view_left; | ||
double next_x; | ||
double next_y; | ||
int foundh; | ||
int foundv; | ||
double hdis; | ||
double vdis; | ||
double dis; | ||
int wall; | ||
int offx; | ||
int offy; | ||
}t_rays; | ||
|
||
typedef struct s_big | ||
{ | ||
int i; | ||
int j; | ||
int fd; | ||
char *line; | ||
char *file; | ||
t_map map; | ||
t_content content; | ||
t_xtr texture; | ||
t_image image; | ||
t_mlx mlx; | ||
t_playerr player; | ||
} t_big; | ||
|
||
int *ft_aatoi(char *str, int i, int j); | ||
void ft_error(char *str); | ||
int ft_isalnum(int c); | ||
void check_map_file(t_big *p); | ||
char **ft_split(char const *s, char c); | ||
void read_map(t_big *p, int i, int j); | ||
void ft_mooove2(int keycode, t_big *p, int s); | ||
int ft_mooove(int keycode, t_big *p); | ||
void check_mfile3(t_big *p, int i, char **side); | ||
void check_mfile4(t_big *p, int i, int **side); | ||
void check_mfile2(t_big *p); | ||
void get_map2(t_big *p); | ||
void get_map(t_big *p); | ||
void getl(t_big *p); | ||
void get_contents(t_big *p); | ||
void check_map(t_big *p); | ||
int check_zerov2(char c); | ||
void ckeck_zero(t_big *p); | ||
void check_texture(t_big *p); | ||
void get_player2(t_big *p, int ort); | ||
void get_player1(t_big *p); | ||
void get_player(t_big *p); | ||
int mouse(int keycode, t_big *p); | ||
void get_player2(t_big *p, int ort); | ||
void get_player1(t_big *p); | ||
void get_player(t_big *p); | ||
void get_dataa2(t_big *p); | ||
void get_dataa(t_big *p); | ||
void content_init(t_big *p); | ||
void check_path(char *str, const char *s); | ||
t_image *get_texture_image(t_big *p, char *str); | ||
int ft_instr(const char *s, int c); | ||
void mini_map(t_big *p); | ||
void get_xy(t_big *p); | ||
void image_init(t_big *p); | ||
void get_colors(t_big *p); | ||
int get_rgb(int red, int green, int blue); | ||
int mouse_turn(int keycode, int i, int j, t_big *p); | ||
void get_correct(t_big *p); | ||
void exito(t_big *p); | ||
/*********************raycasting*************************/ | ||
void draw_line(t_big *data, t_point a, t_point b); | ||
void cast_rays(t_big *p); | ||
double dis(double x1, double y1, double x2, double y2); | ||
void check_angle(t_rays *ray); | ||
void get_2d_view(t_rays *ray); | ||
void get_3d_map(t_big *data, t_rays *ray); | ||
int hit_wall(t_big *data, double x, double y); | ||
void init_3d_variable(t_var *var, t_rays *ray, t_big *data); | ||
void init_horizontal(t_big *data, t_rays *ray); | ||
void init_vertical(t_big *data, t_rays *ray); | ||
void my_mlx_pixel_put(t_big *data, int x, int y, int color); | ||
void get_dis_rays(t_big *data, t_rays *ray); | ||
void get_deriction(t_big *data, t_rays *ray, int i, int j); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* get_next_line.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: zwalad <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2021/11/30 20:37:33 by zwalad #+# #+# */ | ||
/* Updated: 2022/12/13 19:27:29 by zwalad ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "get_next_line.h" | ||
|
||
char *get_line(char *str) | ||
{ | ||
int i; | ||
char *l; | ||
|
||
i = 0; | ||
while (str[i] && str[i] != '\n') | ||
i++; | ||
if (str[i] == '\n') | ||
{ | ||
l = ft_substr(str, 0, i + 1); | ||
return (l); | ||
} | ||
l = ft_strdup(str); | ||
return (l); | ||
} | ||
|
||
char *get_next(char *str) | ||
{ | ||
int i; | ||
char *sstr; | ||
|
||
i = 0; | ||
sstr = NULL; | ||
while (str[i] && str[i] != '\n') | ||
i++; | ||
if (str[i] == '\n') | ||
{ | ||
i++; | ||
sstr = ft_substr(str, i, ft_strlen(str) - i); | ||
} | ||
free(str); | ||
return (sstr); | ||
} | ||
|
||
char *norm_kekw(char *str, int fd) | ||
{ | ||
int len; | ||
char *buf; | ||
|
||
len = 1; | ||
buf = malloc(1 + 1); | ||
if (!buf) | ||
return (NULL); | ||
while (len > 0 && !ft_strchr(str)) | ||
{ | ||
len = read(fd, buf, 1); | ||
if (len <= 0) | ||
break ; | ||
buf[len] = '\0'; | ||
str = ft_strjoin(str, buf); | ||
} | ||
free(buf); | ||
buf = NULL; | ||
return (str); | ||
} | ||
|
||
char *get_next_line(int fd) | ||
{ | ||
static char *str; | ||
char *line; | ||
|
||
if (fd < 0) | ||
return (NULL); | ||
if (!str) | ||
str = ft_strdup(""); | ||
str = norm_kekw(str, fd); | ||
if (!str[0]) | ||
{ | ||
free(str); | ||
str = NULL; | ||
return (NULL); | ||
} | ||
line = get_line(str); | ||
str = get_next(str); | ||
return (line); | ||
} |
Oops, something went wrong.