mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2025-12-13 04:36:59 +01:00
onapprochefin
This commit is contained in:
parent
0a69fd5b32
commit
c8dcaba517
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# #
|
||||
# Updated: 2024/01/30 12:40:15 by fgras-ca ### ########.fr #
|
||||
# Updated: 2024/01/30 16:18:26 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -59,6 +59,8 @@ SRC = main.c \
|
||||
./parsing/ft_map_check_utils.c \
|
||||
./parsing/ft_text_and_col_utils.c \
|
||||
./utils/ft_utils_mem.c \
|
||||
./exit/ft_exit.c \
|
||||
./exit/ft_kill_prog.c \
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
|
||||
3
cub3d.h
3
cub3d.h
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 15:14:01 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/30 15:47:04 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -156,6 +156,7 @@ typedef struct s_structure_main
|
||||
t_texture *t;
|
||||
char current_wall_type;
|
||||
t_sprite sprite;
|
||||
int error;
|
||||
} t_structure_main;
|
||||
|
||||
typedef struct s_res_params {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 15:05:11 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/30 16:07:36 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -38,8 +38,3 @@ void load_wall_textures(t_structure_main *w)
|
||||
load_texture(w, w->t->east, (void **)&w->s_img.east_texture);
|
||||
load_texture(w, "textures/door_close.xpm", (void **)&w->s_img.door_texture);
|
||||
}
|
||||
|
||||
void exit_error(t_structure_main *w)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
73
exit/ft_exit.c
Normal file
73
exit/ft_exit.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/30 16:06:24 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 16:07:27 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
static void free_texture_images(t_structure_main *w)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (++i <= 10)
|
||||
{
|
||||
if (w->s_img.roomadslam[i])
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.roomadslam[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void free_textures(t_texture *t)
|
||||
{
|
||||
if (t->north)
|
||||
free(t->north);
|
||||
if (t->south)
|
||||
free(t->south);
|
||||
if (t->west)
|
||||
free(t->west);
|
||||
if (t->east)
|
||||
free(t->east);
|
||||
}
|
||||
|
||||
static void destroy_images(t_structure_main *w)
|
||||
{
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_player);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.pedro_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.north_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.south_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.west_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.east_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.door_texture);
|
||||
free_texture_images(w);
|
||||
}
|
||||
}
|
||||
|
||||
void exit_error(t_structure_main *w)
|
||||
{
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_window(w->s_win.mlx, w->s_win.win);
|
||||
destroy_images(w);
|
||||
mlx_destroy_display(w->s_win.mlx);
|
||||
free(w->s_win.mlx);
|
||||
}
|
||||
if (w->s_map.map && (w->error != 1))
|
||||
free(w->s_map.map);
|
||||
if (w->t)
|
||||
{
|
||||
free_textures(w->t);
|
||||
free(w->t);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
65
exit/ft_kill_prog.c
Normal file
65
exit/ft_kill_prog.c
Normal file
@ -0,0 +1,65 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_kill_prog.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/30 16:12:26 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 16:17:45 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
static void destroy_images_and_window(t_structure_main *w)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_window(w->s_win.mlx, w->s_win.win);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_player);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.pedro_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.north_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.south_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.west_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.east_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.door_texture);
|
||||
while (++i <= 10)
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.roomadslam[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_and_exit(t_structure_main *w)
|
||||
{
|
||||
if (w->s_map.map)
|
||||
{
|
||||
free(w->s_map.map);
|
||||
w->s_map.map = NULL;
|
||||
}
|
||||
if (w->t)
|
||||
{
|
||||
free(w->t->north);
|
||||
free(w->t->south);
|
||||
free(w->t->west);
|
||||
free(w->t->east);
|
||||
free(w->t);
|
||||
}
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_display(w->s_win.mlx);
|
||||
free(w->s_win.mlx);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int *kill_prog(t_structure_main *w)
|
||||
{
|
||||
destroy_images_and_window(w);
|
||||
cleanup_and_exit(w);
|
||||
return (0);
|
||||
}
|
||||
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/15 18:45:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 14:59:40 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/30 15:47:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -23,6 +23,8 @@ int setup_and_load_map(int argc, char **argv,
|
||||
if (!load_cub_file(argv[1], textures, &w->s_map))
|
||||
{
|
||||
printf("Failed to load the map or map is not closed. Exiting...\n");
|
||||
w->error = 1;
|
||||
exit_error(w);
|
||||
return (0);
|
||||
}
|
||||
if (w->s_map.map == NULL)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:09:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/29 17:43:10 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/30 16:21:09 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,7 +26,7 @@ static int check_collision(t_structure_main *w, double future_x,
|
||||
map_x = (int)((future_x + coll_params->dx[i]) / w->s_map.map_s);
|
||||
map_y = (int)((future_y + coll_params->dy[i]) / w->s_map.map_s);
|
||||
map_position = w->s_map.map[map_y * w->s_map.map_x + map_x];
|
||||
if (map_position != '0' && map_position != '3')
|
||||
if (map_position == '1' || map_position == '2')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -6,35 +6,12 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:17:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/29 17:53:45 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/30 16:15:56 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
int *kill_prog(t_structure_main *w)
|
||||
{
|
||||
int i;
|
||||
|
||||
mlx_destroy_window(w->s_win.mlx, w->s_win.win);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_player);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.pedro_wall);
|
||||
i = -1;
|
||||
while (++i <= 10)
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.roomadslam[i]);
|
||||
if (w->s_map.map)
|
||||
{
|
||||
free(w->s_map.map);
|
||||
w->s_map.map = NULL;
|
||||
}
|
||||
mlx_destroy_display(w->s_win.mlx);
|
||||
free(w->s_win.mlx);
|
||||
exit(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void adjust_player_angle(t_structure_main *w, int key)
|
||||
{
|
||||
double angle_adjustment;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user