aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
9 files changed, 77 insertions, 64 deletions
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);
}