aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--inc/cub3d.h5
-rw-r--r--inc/cub3d_defines.h9
-rw-r--r--inc/cub3d_structs.h9
-rw-r--r--map/map_one.cub2
-rw-r--r--src/ft_check_not_found.c27
-rw-r--r--src/ft_draw_circle.c26
-rw-r--r--src/ft_draw_map.c2
-rw-r--r--src/ft_draw_textures.c8
-rw-r--r--src/ft_get_sprite.c5
-rw-r--r--src/ft_get_tex.c20
-rw-r--r--src/ft_parse_map.c1
-rw-r--r--src/ft_print_list.c40
-rw-r--r--src/ft_tex_init.c12
14 files changed, 92 insertions, 76 deletions
diff --git a/Makefile b/Makefile
index a120b23..d7bcdea 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,7 @@ SRCS_NAME += ft_get_map.c
SRCS_NAME += ft_get_player_spawn.c
SRCS_NAME += ft_set_minimap_scale.c
SRCS_NAME += ft_check_missing.c
+SRCS_NAME += ft_check_not_found.c
SRCS_NAME += ft_check_map_line.c
SRCS_NAME += ft_free_words.c
SRCS_NAME += ft_map_error.c
@@ -46,7 +47,6 @@ SRCS_NAME += ft_draw_scene.c
SRCS_NAME += ft_basic_keys.c
SRCS_NAME += ft_extra_keys.c
SRCS_NAME += ft_draw_verline.c
-SRCS_NAME += ft_print_list.c
SRCS_NAME += ft_rgb_to_hex.c
SRCS_NAME += ft_raycasting.c
SRCS_NAME += ft_init_s_ray.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 8625705..a6131b7 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -25,6 +25,7 @@
** 3: failed mlx init
** 4: map error
** 5: no map
+** 6: read error
*/
int8_t ft_init_cub3d(t_cub **clist);
@@ -81,6 +82,10 @@ int ft_key_loop(t_cub *cl);
void ft_draw_circle(int32_t a, int32_t b,
int32_t color, t_cub *cl);
void ft_draw_texture(t_cub *cl, int x, int y, int tex_y);
+<<<<<<< HEAD
+int8_t ft_check_not_found(const char *path);
+=======
void ft_calc_tex(t_cub *clist);
+>>>>>>> textures_fix
# endif
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 209d0bc..9f54dda 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -50,8 +50,8 @@
*/
# define FT_MOVE_SPEED 0.1
-# define FT_STRAFE_SPEED 0.05
-# define FT_ROT_SPEED 0.07
+# define FT_STRAFE_SPEED 0.1
+# define FT_ROT_SPEED 0.09
/*
** ====== SCREEN ======
@@ -82,6 +82,11 @@
# define FT_ERR_ILL_MAP "map contains illegal char"
# define FT_ERR_MULT_SPAWN "multiple spawn points"
# define FT_ERR_MAP_L_L "last line is invalid"
+# define FT_ERR_RD_NO "could not find north side texture file"
+# define FT_ERR_RD_SO "could not find south side texture file"
+# define FT_ERR_RD_EA "could not find east side texture file"
+# define FT_ERR_RD_WE "could not find west side texture file"
+# define FT_ERR_RD_SP "could not find sprite texture file"
/*
** ====== MISSING ERROR MSG ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 9e19e2b..66686eb 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -47,14 +47,6 @@ typedef struct s_rgb
int16_t b;
} t_rgb;
-/*
-** player view_side:
-** 1: North
-** 2: East
-** 3: South
-** 4: West
-*/
-
typedef struct s_player
{
float pos_x;
@@ -72,6 +64,7 @@ typedef struct s_ray
{
uint16_t line_h;
float wall_dist;
+ float mid_dist;
float x_ray_pos;
float y_ray_pos;
float x_ray_dir;
diff --git a/map/map_one.cub b/map/map_one.cub
index aba8f38..14f98f5 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,4 +1,4 @@
-R 1080 720
+R 1600 900
NO ./map/img/linuz.xpm
SO ./map/img/linuz.xpm
diff --git a/src/ft_check_not_found.c b/src/ft_check_not_found.c
new file mode 100644
index 0000000..25afe1a
--- /dev/null
+++ b/src/ft_check_not_found.c
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_check_not_found.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/19 19:26:27 by rbousset #+# #+# */
+/* Updated: 2020/02/19 19:26:28 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int8_t
+ ft_check_not_found(const char *path)
+{
+ int fd;
+
+ if ((fd = open(path, O_RDONLY)) < 0)
+ return (-1);
+ close(fd);
+ return (0);
+}
diff --git a/src/ft_draw_circle.c b/src/ft_draw_circle.c
index 32a1612..3e17dfa 100644
--- a/src/ft_draw_circle.c
+++ b/src/ft_draw_circle.c
@@ -18,24 +18,26 @@
void
ft_draw_circle(int32_t a, int32_t b, int32_t color, t_cub *cl)
{
- const uint16_t scale = cl->mlist->scale / 2.5;
- int x;
- int y;
+ float scale;
float i;
float angle;
float x1;
float y1;
- x = a;
- y = b;
-
i = 0;
- while (i < 360)
+ scale = cl->mlist->scale / 2.5;
+ while (scale > 0)
{
- angle = i;
- x1 = scale * cos(angle * M_PI / 180);
- y1 = scale * sin(angle * M_PI / 180);
- *(int*)(cl->img.ptr + (x + (int)x1) * 4 + ((y + (int)y1) * cl->img.sizeline)) = color;
- i += 0.1;
+ while (i < 360)
+ {
+ angle = i;
+ x1 = scale * cos(angle * M_PI / 180);
+ y1 = scale * sin(angle * M_PI / 180);
+ *(int*)(cl->img.ptr + (a + (int)x1) * 4 +
+ ((b + (int)y1) * cl->img.sizeline)) = color;
+ i += 0.1;
+ }
+ i = 0;
+ scale--;
}
}
diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c
index 7da2e58..39299c1 100644
--- a/src/ft_draw_map.c
+++ b/src/ft_draw_map.c
@@ -29,7 +29,7 @@ static void
const uint16_t scale = clist->mlist->scale;
ft_draw_circle(
- (scale / 2 ) + (x * (scale)),
+ (scale / 2) + (x * (scale)),
ft_y_offset(clist) - (scale) + (y * (scale)),
0x009843fa,
clist);
diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c
index 0c86043..598fd91 100644
--- a/src/ft_draw_textures.c
+++ b/src/ft_draw_textures.c
@@ -15,10 +15,10 @@
#include <stdint.h>
/*
-** 0 : no
-** 1 : so
-** 2 : ea
-** 3 : we
+** 1 : no
+** 0 : so
+** 3 : ea
+** 4 : we
** 4 : sprite
*/
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c
index 791f51f..ebf0566 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -35,5 +35,10 @@ int8_t
ft_strlen(FT_ERR_ALLOCATE) + 1);
return (-1);
}
+ if (ft_check_not_found(clist->mlist->sprite_path) < 0)
+ {
+ ft_strlcpy(clist->errmsg, FT_ERR_RD_SP, ft_strlen(FT_ERR_RD_SP) + 1);
+ return (-1);
+ }
return (0);
}
diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c
index ad093ed..58a0358 100644
--- a/src/ft_get_tex.c
+++ b/src/ft_get_tex.c
@@ -35,6 +35,11 @@ int8_t
ft_strlen(FT_ERR_ALLOCATE) + 1);
return (-1);
}
+ if (ft_check_not_found(clist->mlist->no_tex_path) < 0)
+ {
+ ft_strlcpy(clist->errmsg, FT_ERR_RD_NO, ft_strlen(FT_ERR_RD_NO) + 1);
+ return (-1);
+ }
return (0);
}
@@ -59,6 +64,11 @@ int8_t
ft_strlen(FT_ERR_ALLOCATE) + 1);
return (-1);
}
+ if (ft_check_not_found(clist->mlist->so_tex_path) < 0)
+ {
+ ft_strlcpy(clist->errmsg, FT_ERR_RD_SO, ft_strlen(FT_ERR_RD_SO) + 1);
+ return (-1);
+ }
return (0);
}
@@ -83,6 +93,11 @@ int8_t
ft_strlen(FT_ERR_ALLOCATE) + 1);
return (-1);
}
+ if (ft_check_not_found(clist->mlist->ea_tex_path) < 0)
+ {
+ ft_strlcpy(clist->errmsg, FT_ERR_RD_EA, ft_strlen(FT_ERR_RD_EA) + 1);
+ return (-1);
+ }
return (0);
}
@@ -107,5 +122,10 @@ int8_t
ft_strlen(FT_ERR_ALLOCATE) + 1);
return (-1);
}
+ if (ft_check_not_found(clist->mlist->we_tex_path) < 0)
+ {
+ ft_strlcpy(clist->errmsg, FT_ERR_RD_WE, ft_strlen(FT_ERR_RD_WE) + 1);
+ return (-1);
+ }
return (0);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 4fd870b..0dfb779 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -100,6 +100,5 @@ void
ft_get_player_spawn(clist->plist, clist);
ft_check_missing(clist);
ft_set_minimap_scale(clist);
- ft_print_list(clist);
close(fd);
}
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
deleted file mode 100644
index 3b44115..0000000
--- a/src/ft_print_list.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_print_list.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/14 17:28:57 by rbousset #+# #+# */
-/* Updated: 2020/02/14 17:28:57 by rbousset ### ########lyon.fr */
-/* */
-/* ************************************************************************** */
-
-#include <libft.h>
-#include <cub3d.h>
-
-void
- ft_print_list(t_cub *clist)
-{
- size_t i;
-
- ft_printf("x size ----- [%d]\n", clist->wlist->x_size);
- ft_printf("y size ----- [%d]\n", clist->wlist->y_size);
- ft_printf("North ------ [%s]\n", clist->mlist->no_tex_path);
- ft_printf("South ------ [%s]\n", clist->mlist->so_tex_path);
- ft_printf("West ------- [%s]\n", clist->mlist->we_tex_path);
- ft_printf("East ------- [%s]\n", clist->mlist->ea_tex_path);
- ft_printf("Sprite ----- [%s]\n", clist->mlist->sprite_path);
- ft_printf("F color ---- [%d]\n", ft_rgb_to_hex(clist->f_rgb));
- ft_printf("C color ---- [%d]\n", ft_rgb_to_hex(clist->c_rgb));
- i = 0;
- ft_printf("Map\n----\n");
- while (clist->mlist->map[i])
- {
- ft_printf("%2zu -- [%s]\n", i + 1, clist->mlist->map[i]);
- i++;
- }
- ft_printf("Map width -- [%zu]\n", clist->mlist->map_w);
- ft_printf("2D scale --- [%hhu]\n", clist->mlist->scale);
- ft_printf("----------------------\n");
-}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 724877f..40e39e5 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -10,10 +10,10 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
#include <mlx.h>
-#include <libft.h>
/*
** 0 : no
@@ -26,23 +26,23 @@
void ft_wall_tex_init(t_cub *cl)
{
cl->tlist[0].img = mlx_xpm_file_to_image(cl->wlist->wlx,
- cl->mlist->no_tex_path, &cl->tlist[0].img_w, &cl->tlist[0].img_h);
+ cl->mlist->no_tex_path, &cl->tlist[0].img_w, &cl->tlist[0].img_h);
cl->tlist[0].ptr = mlx_get_data_addr(cl->tlist[0].img,
&cl->tlist[0].bpp, &cl->tlist[0].sizeline, &cl->tlist[0].endian);
cl->tlist[1].img = mlx_xpm_file_to_image(cl->wlist->wlx,
- cl->mlist->so_tex_path, &cl->tlist[1].img_w, &cl->tlist[1].img_h);
+ cl->mlist->so_tex_path, &cl->tlist[1].img_w, &cl->tlist[1].img_h);
cl->tlist[1].ptr = mlx_get_data_addr(cl->tlist[1].img,
&cl->tlist[1].bpp, &cl->tlist[1].sizeline, &cl->tlist[1].endian);
cl->tlist[2].img = mlx_xpm_file_to_image(cl->wlist->wlx,
- cl->mlist->ea_tex_path, &cl->tlist[2].img_w, &cl->tlist[2].img_h);
+ cl->mlist->ea_tex_path, &cl->tlist[2].img_w, &cl->tlist[2].img_h);
cl->tlist[2].ptr = mlx_get_data_addr(cl->tlist[2].img,
&cl->tlist[2].bpp, &cl->tlist[2].sizeline, &cl->tlist[2].endian);
cl->tlist[3].img = mlx_xpm_file_to_image(cl->wlist->wlx,
- cl->mlist->we_tex_path, &cl->tlist[3].img_w, &cl->tlist[3].img_h);
+ cl->mlist->we_tex_path, &cl->tlist[3].img_w, &cl->tlist[3].img_h);
cl->tlist[3].ptr = mlx_get_data_addr(cl->tlist[3].img,
&cl->tlist[3].bpp, &cl->tlist[3].sizeline, &cl->tlist[3].endian);
cl->tlist[4].img = mlx_xpm_file_to_image(cl->wlist->wlx,
- cl->mlist->sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h);
+ cl->mlist->sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h);
cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img,
&cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian);
}