diff --git a/README.md b/README.md index 47aae9a..d003282 100644 --- a/README.md +++ b/README.md @@ -1,104 +1,5 @@ -# run +# cube3D -**add minilibx and libft submodules :** -- git submodule init -- git submodule update - -# todo - -- resolve view buble -- add textures - -# ressources - -- [tuto mlx](https://harm-smits.github.io/42docs/libs/minilibx/getting_started.html) -- [tuto raycasting](https://lodev.org/cgtutor/raycasting.html) -- [tuto raycasting js](http://www.playfuljs.com/a-first-person-engine-in-265-lines) -- [tuto mlx and wolf3d](https://github.com/qst0/ft_libgfx) -- [tuto mlx images](https://github.com/keuhdall/images_example) -- [bmp images](https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html) -- [bmp images in c](https://stackoverflow.com/questions/2654480/writing-bmp-image-in-pure-c-c-without-other-libraries) - - ---- -# keys numbers - -``` -+-------------.-------.-------+------.-------.-------+------.-------.-------+ -| keys linux mac | keys linux mac | keys linux mac | -|-------------.-------.-------|------.-------.-------|------.-------.-------+ -| direction keys | alpha keys | num keys | -|-------------.-------.-------|------.-------.-------|------.-------.-------+ -| w forward . 119 . _____ | a . 97 . _____ | & (0). (38) . _____ | -| a left . 97 . _____ | b . 98 . _____ | é (1). (233) . _____ | -| s backward . 115 . _____ | c . 99 . _____ | " (2). (34) . _____ | -| d right . 100 . _____ | d . 100 . _____ | ' (3). (39) . _____ | -|-------------.-------.-------| e . 101 . _____ | ( (4). (40) . _____ | -| arrows keys | f . 102 . _____ | - (5). (45) . _____ | -|-------------.-------.-------| g . 103 . _____ | è (6). (232) . _____ | -| ← . 65361 . _____ | h . 104 . _____ | _ (7). (95) . _____ | -| → . 65363 . _____ | i . 105 . _____ | ç (8). (231) . _____ | -| ↓ . 65364 . _____ | j . 106 . _____ | à (9). (224) . _____ | -| ↑ . 65362 . _____ | k . 107 . _____ |------.-------.-------| -|-------------.-------.-------| l . 108 . _____ | other keys | -| special keys | m . 109 . _____ |------.-------.-------| -|-------------.-------.-------| n . 110 . _____ | < (>). 60 . _____ | -| esc . 65307 . _____ | o . 111 . _____ | > .(60) . _____ | -| suppr . 65535 . _____ | p . 112 . _____ | space. 32 . _____ | -| delete . 65288 . _____ | q . 113 . _____ | tab . 65289 . _____ | -| enter . 65293 . _____ | r . 114 . _____ | = (+). 61 . _____ | -|-------------.-------.-------| s . 115 . _____ | + .(61) . _____ | -| hot keys | t . 116 . _____ | - . 45 . _____ | -|-------------.-------.-------| u . 117 . _____ | . . | -| shift left . 65505 . _____ | v . 118 . _____ | . . | -| shift right . 65506 . _____ | w . 119 . _____ | . . | -| ctrl left . 65507 . _____ | x . 120 . _____ | . . | -| ctrl right . 65508 . _____ | y . 121 . _____ | . . | -| . . | z . 122 . _____ | . . | -+-------------.-------.-------+------.-------.-------+------.-------.-------+ -``` - ---- -# hook key masks - -- https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html - -``` -x_event | x_mask | action -------------------------------------------------- - 2 | 1L << 0 | key press - 3 | 1L << 1 | key release - 4 | | mouse press - 5 | | mouse release - 6 | | mouse move - 12 | | expose event - 17 | 1L << 17 | x button press (red button) -``` - ---- -# fonctions externes autorisees : - -- **open** -- **close** -- **read** -- **write** -- **malloc** -- **free** -- **perror** -- **strerror** -- **exit** -- **math lib** : - - **lm** -> needed at compilation to link the lib (eg: `gcc foo.c -o foo -lm`) - - **man** - - **man 3 math** -- **minilibx** : - - `minilibx_opengl.tgz` - - `minilibx_mms_20200219_beta.tgz` - - **to open an archive.tgz** : - - `gzip -d archive.tgz` -> turn it into archive.tar - - `tar -xf archive.tar` -> un-archive it - - how to add a man directory to the manual : - - cp man/man1 /usr/local/share/man/man1 (create man1 if necessary) - - mandb - - i didn't use any of both library above but the one for linux : https://github.com/42Paris/minilibx-linux (there are pbm with their man pages) +This is a 3D mini game, using raycasting, in imitation of Wolfenstein3D or Doom. +![]() diff --git a/assets/cube3d_image.gif b/assets/cube3d_image.gif new file mode 100644 index 0000000..6436500 Binary files /dev/null and b/assets/cube3d_image.gif differ diff --git a/assets/cube3d_map.gif b/assets/cube3d_map.gif new file mode 100644 index 0000000..f3ce241 Binary files /dev/null and b/assets/cube3d_map.gif differ diff --git a/assets/cube3d_tour.gif b/assets/cube3d_tour.gif new file mode 100644 index 0000000..882ad8c Binary files /dev/null and b/assets/cube3d_tour.gif differ diff --git a/headers/cube3d_macro.h b/headers/cube3d_macro.h index 3e6df47..b201c99 100644 --- a/headers/cube3d_macro.h +++ b/headers/cube3d_macro.h @@ -18,7 +18,7 @@ */ /* nbr pixel player move */ -# define PLR_MV 9 +# define PLR_MV 4 /* degree of rotation of the player per press */ # define PLR_ROT 1 /* nbr key you can press at the same time */ diff --git a/libs/libft b/libs/libft index f32d4bb..603303a 160000 --- a/libs/libft +++ b/libs/libft @@ -1 +1 @@ -Subproject commit f32d4bbc96af281afdb5c1443a54d185bd2f16e7 +Subproject commit 603303a21bd8485961a0159f0aeefa629604cb4c diff --git a/maps/map_valid_00_base.cub b/maps/map_valid_00_base.cub index 3509531..95ebb10 100644 --- a/maps/map_valid_00_base.cub +++ b/maps/map_valid_00_base.cub @@ -1,7 +1,7 @@ -NO textures/fish.xpm -SO textures/fish.xpm -EA textures/fish.xpm -WE textures/fish.xpm +NO textures/grey.xpm +SO textures/grey.xpm +EA textures/grey.xpm +WE textures/grey.xpm F 66,66,66 C 33,33,33 diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..47aae9a --- /dev/null +++ b/notes.md @@ -0,0 +1,104 @@ +# run + +**add minilibx and libft submodules :** +- git submodule init +- git submodule update + +# todo + +- resolve view buble +- add textures + +# ressources + +- [tuto mlx](https://harm-smits.github.io/42docs/libs/minilibx/getting_started.html) +- [tuto raycasting](https://lodev.org/cgtutor/raycasting.html) +- [tuto raycasting js](http://www.playfuljs.com/a-first-person-engine-in-265-lines) +- [tuto mlx and wolf3d](https://github.com/qst0/ft_libgfx) +- [tuto mlx images](https://github.com/keuhdall/images_example) +- [bmp images](https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html) +- [bmp images in c](https://stackoverflow.com/questions/2654480/writing-bmp-image-in-pure-c-c-without-other-libraries) + + +--- +# keys numbers + +``` ++-------------.-------.-------+------.-------.-------+------.-------.-------+ +| keys linux mac | keys linux mac | keys linux mac | +|-------------.-------.-------|------.-------.-------|------.-------.-------+ +| direction keys | alpha keys | num keys | +|-------------.-------.-------|------.-------.-------|------.-------.-------+ +| w forward . 119 . _____ | a . 97 . _____ | & (0). (38) . _____ | +| a left . 97 . _____ | b . 98 . _____ | é (1). (233) . _____ | +| s backward . 115 . _____ | c . 99 . _____ | " (2). (34) . _____ | +| d right . 100 . _____ | d . 100 . _____ | ' (3). (39) . _____ | +|-------------.-------.-------| e . 101 . _____ | ( (4). (40) . _____ | +| arrows keys | f . 102 . _____ | - (5). (45) . _____ | +|-------------.-------.-------| g . 103 . _____ | è (6). (232) . _____ | +| ← . 65361 . _____ | h . 104 . _____ | _ (7). (95) . _____ | +| → . 65363 . _____ | i . 105 . _____ | ç (8). (231) . _____ | +| ↓ . 65364 . _____ | j . 106 . _____ | à (9). (224) . _____ | +| ↑ . 65362 . _____ | k . 107 . _____ |------.-------.-------| +|-------------.-------.-------| l . 108 . _____ | other keys | +| special keys | m . 109 . _____ |------.-------.-------| +|-------------.-------.-------| n . 110 . _____ | < (>). 60 . _____ | +| esc . 65307 . _____ | o . 111 . _____ | > .(60) . _____ | +| suppr . 65535 . _____ | p . 112 . _____ | space. 32 . _____ | +| delete . 65288 . _____ | q . 113 . _____ | tab . 65289 . _____ | +| enter . 65293 . _____ | r . 114 . _____ | = (+). 61 . _____ | +|-------------.-------.-------| s . 115 . _____ | + .(61) . _____ | +| hot keys | t . 116 . _____ | - . 45 . _____ | +|-------------.-------.-------| u . 117 . _____ | . . | +| shift left . 65505 . _____ | v . 118 . _____ | . . | +| shift right . 65506 . _____ | w . 119 . _____ | . . | +| ctrl left . 65507 . _____ | x . 120 . _____ | . . | +| ctrl right . 65508 . _____ | y . 121 . _____ | . . | +| . . | z . 122 . _____ | . . | ++-------------.-------.-------+------.-------.-------+------.-------.-------+ +``` + +--- +# hook key masks + +- https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html + +``` +x_event | x_mask | action +------------------------------------------------- + 2 | 1L << 0 | key press + 3 | 1L << 1 | key release + 4 | | mouse press + 5 | | mouse release + 6 | | mouse move + 12 | | expose event + 17 | 1L << 17 | x button press (red button) +``` + +--- +# fonctions externes autorisees : + +- **open** +- **close** +- **read** +- **write** +- **malloc** +- **free** +- **perror** +- **strerror** +- **exit** +- **math lib** : + - **lm** -> needed at compilation to link the lib (eg: `gcc foo.c -o foo -lm`) + - **man** + - **man 3 math** +- **minilibx** : + - `minilibx_opengl.tgz` + - `minilibx_mms_20200219_beta.tgz` + - **to open an archive.tgz** : + - `gzip -d archive.tgz` -> turn it into archive.tar + - `tar -xf archive.tar` -> un-archive it + - how to add a man directory to the manual : + - cp man/man1 /usr/local/share/man/man1 (create man1 if necessary) + - mandb + - i didn't use any of both library above but the one for linux : https://github.com/42Paris/minilibx-linux (there are pbm with their man pages) + diff --git a/srcs/parsing/check_path.c b/srcs/parsing/check_path.c index 4b6ff62..b0ebb8d 100644 --- a/srcs/parsing/check_path.c +++ b/srcs/parsing/check_path.c @@ -102,7 +102,7 @@ int check_elements(t_game *game, char *file) return (-1); while (count < TOTAL_ELEMENTS) { - get_next_line(fd, &line); + ft_gnl(fd, &line); mb_add(line); if (line && *line != '\n' && !check_element(game, line)) count++; diff --git a/srcs/parsing/init_parsing.c b/srcs/parsing/init_parsing.c index b95c33e..b66f604 100644 --- a/srcs/parsing/init_parsing.c +++ b/srcs/parsing/init_parsing.c @@ -15,15 +15,19 @@ static int size_map(t_map *map, int fd) { char *line; + int ret; - get_next_line(fd, &line); + ret = ft_gnl(fd, &line); mb_add(line); - while (line) + while (ret > 0) { - if ((*line == '\n' || *line == '\0') && map->size_x) + if (ret != 0 && map->size_x) { - mb_free(line); - return (EXIT_FAILURE); + if (*line == '\n' || *line == '\0') + { + mb_free(line); + return (EXIT_FAILURE); + } } else if (*line != '\n' && (int)ft_strlen(line) > map->size_x) { @@ -35,7 +39,7 @@ static int size_map(t_map *map, int fd) map->size_y++; mb_free(line); line = NULL; - get_next_line(fd, &line); + ret = ft_gnl(fd, &line); mb_add(line); } return (EXIT_SUCCESS); @@ -52,7 +56,7 @@ static int find_map(t_map *map, char *file) return (-1); while (count < TOTAL_ELEMENTS + 1) { - get_next_line(fd, &map->tmp_str); + ft_gnl(fd, &map->tmp_str); mb_add(map->tmp_str); if (!map->tmp_str) { @@ -100,7 +104,7 @@ static void fill_map(t_map *map, int fd) { if (i > 0) { - ret = get_next_line(fd, &map->tmp_str); + ret = ft_gnl(fd, &map->tmp_str); mb_add(map->tmp_str); } map->content[i] = (char *)mb_alloc((map->size_x + 1) * sizeof(char)); @@ -110,7 +114,7 @@ static void fill_map(t_map *map, int fd) map->content[i] = NULL; while (ret) { - ret = get_next_line(fd, &map->tmp_str); + ret = ft_gnl(fd, &map->tmp_str); if (ret) mb_add(map->tmp_str); }