From c51419a68e38ed3a2eb28e740f72eaa436fbd106 Mon Sep 17 00:00:00 2001
From: JozanLeClerc <bousset.rudy@gmail.com>
Date: Mon, 9 Mar 2020 01:52:21 +0100
Subject: Boy

---
 inc/cub3d.h           |  3 +--
 inc/cub3d_structs.h   |  2 +-
 map/map_six.cub       | 21 +++++++++++++++++++++
 src/ft_darken_rgb.c   | 33 ++++++++++-----------------------
 src/ft_draw_verline.c | 29 -----------------------------
 src/ft_floor_cast.c   | 39 +++++++++++++++++++++++++++++++--------
 src/ft_tex_init.c     | 10 ++++++++++
 7 files changed, 74 insertions(+), 63 deletions(-)
 create mode 100644 map/map_six.cub

diff --git a/inc/cub3d.h b/inc/cub3d.h
index 77ade74..ba8ee89 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -137,7 +137,6 @@ int8_t			ft_warp_level(t_cub *cl);
 int				ft_exit(uint8_t exit_code, t_cub *clist);
 uint32_t		ft_rgb_to_hex(t_rgb rgb);
 t_bmp_rgb		ft_hex_to_rgb(uint32_t color);
-uint32_t		ft_darken_ceil(t_rgb rgb, int32_t y, t_cub *cl);
-uint32_t		ft_darken_floor(t_rgb rgb, int32_t y, t_cub *cl);
+uint32_t		ft_darken(t_rgb rgb, t_cub *cl);
 
 #	endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index a516036..64db18c 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -203,7 +203,7 @@ typedef struct			s_cub
 	struct s_img		img;
 	struct s_rgb		f_rgb;
 	struct s_rgb		c_rgb;
-	struct s_img		tlist[7];
+	struct s_img		tlist[8];
 	struct s_sprite		sp_list;
 }						t_cub;
 
diff --git a/map/map_six.cub b/map/map_six.cub
new file mode 100644
index 0000000..5678d4e
--- /dev/null
+++ b/map/map_six.cub
@@ -0,0 +1,21 @@
+R 1600 1100
+
+NO ./media/img/larry.xpm
+SO ./media/img/larry.xpm
+EA ./media/img/larry.xpm
+WE ./media/img/larry.xpm
+S ./media/img/larry.xpm
+
+C 26,165,204
+F 24,170,25
+
+11111111111111111
+100000000000000W1
+10111111111111101
+10100000000000111
+10111111111100001
+10000000000100001
+10111111111100001
+10100000000000001
+10000000000000001
+11111111111111111
\ No newline at end of file
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c
index 656aac7..4c571cf 100644
--- a/src/ft_darken_rgb.c
+++ b/src/ft_darken_rgb.c
@@ -14,33 +14,20 @@
 #include <stdint.h>
 
 uint32_t
-	ft_darken_ceil(t_rgb rgb, int32_t y, t_cub *cl)
+	ft_darken(t_rgb rgb, t_cub *cl)
 {
 	t_rgb		darker;
 	float		calc;
+	float		dist;
 
+	if ((dist = cl->rlist.row_dist) <= 0)
+		dist = 0.0001;
+	calc = (dist * 0.4);
+	calc = (calc >= 255) ? (255) : (calc);
+	calc = (calc < 1) ? (1) : (calc);
 	darker = rgb;
-	calc = ((float)(y - (75000.0 / cl->wlist.y_size))
-			/ (cl->wlist.y_size / 2));
-	calc = (calc < 0) ? (0) : (calc);
-	darker.r *= 1 - calc;
-	darker.g *= 1 - calc;
-	darker.b *= 1 - calc;
+	darker.r /= calc;
+	darker.g /= calc;
+	darker.b /= calc;
 	return (ft_rgb_to_hex(darker));
 }
-
-/* uint32_t */
-/* 	ft_darken_floor(t_rgb rgb, int32_t y, t_cub *cl) */
-/* { */
-/* 	t_rgb		darker; */
-/* 	float		calc; */
-
-/* 	calc = ((float)(y + (75000.0 / cl->wlist.y_size)) */
-/* 			/ (cl->wlist.y_size / 2)) - 1.0; */
-/* 	calc = (calc < 0) ? (0) : (calc); */
-/* 	darker = rgb; */
-/* 	darker.r *= calc; */
-/* 	darker.g *= calc; */
-/* 	darker.b *= calc; */
-/* 	return (ft_rgb_to_hex(darker)); */
-/* } */
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index b6729de..7bfba8d 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -13,33 +13,6 @@
 #include <cub3d.h>
 #include <stdint.h>
 
-/* static void */
-/* 	ft_draw_floor(t_cub *cl, int32_t y, int32_t x) */
-/* { */
-/* 	while ((uint32_t)y < cl->wlist.y_size) */
-/* 	{ */
-/* 		*(int*)(cl->img.ptr + */
-/* 				(x * 4 + (y * cl->img.sizeline))) */
-/* 				= ft_darken_floor(cl->f_rgb, y, cl); */
-/* 		y++; */
-/* 	} */
-/* } */
-
-static void
-	ft_draw_ceil(t_cub *cl, int32_t y, int32_t x)
-{
-	int16_t	i;
-
-	i = 0;
-	while (i <= y)
-	{
-		*(int*)(cl->img.ptr +
-			(x * 4 + (i * cl->img.sizeline)))
-			= ft_darken_ceil(cl->c_rgb, i, cl);
-		i++;
-	}
-}
-
 int8_t
 	ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
 {
@@ -48,7 +21,6 @@ int8_t
 
 	(y < 0) ? (y = 0) : 0;
 	(y2 < 0) ? (y2 = 0) : 0;
-	ft_draw_ceil(cl, y, x);
 	(cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0;
 	while (y < y2)
 	{
@@ -59,6 +31,5 @@ int8_t
 		ft_draw_texture(cl, x, y, tex_y);
 		y++;
 	}
-	/* ft_draw_floor(cl, y, x); */
 	return (0);
 }
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index 6947403..1b22a71 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -13,18 +13,34 @@
 #include <cub3d.h>
 #include <stdint.h>
 
+/* static void */
+/* 	ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) */
+/* { */
+/* 	*(int*)(cl->img.ptr + */
+/* 			(x * 4 + (y * cl->img.sizeline))) */
+/* 		= ft_darken(rgb, cl); */
+/* } */
+
 static void
-	ft_put_floor_tex(uint16_t y, uint16_t x, t_cub *cl)
+	ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl)
 {
+	float		dist;
+	float		calc;
+
+	if ((dist = cl->rlist.row_dist) <= 0)
+		dist = 0.0001;
+	calc = (dist * 0.4);
+	calc = (calc >= 255) ? (255) : (calc);
+	calc = (calc < 1) ? (1) : (calc);
 	cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
-		(uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 *
-		cl->tlist[6].img_h * cl->tlist[6].tex_y];
+		(uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+		cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc;
 	cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
-		(uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 *
-		cl->tlist[6].img_h * cl->tlist[6].tex_y + 1];
+		(uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+		cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc;
 	cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
-		(uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 *
-		cl->tlist[6].img_h * cl->tlist[6].tex_y + 2];
+		(uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 *
+		cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2] / calc;
 	cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;
 }
 
@@ -37,9 +53,16 @@ static void
 			* (rl->x_floor - rl->x_cell)) % (cl->tlist[6].img_w);
 	cl->tlist[6].tex_x = (int32_t)(cl->tlist[6].img_h
 			* (rl->y_floor - rl->y_cell)) % (cl->tlist[6].img_h);
+	cl->tlist[7].tex_y = (int32_t)(cl->tlist[7].img_w
+			* (rl->x_floor - rl->x_cell)) % (cl->tlist[7].img_w);
+	cl->tlist[7].tex_x = (int32_t)(cl->tlist[7].img_h
+			* (rl->y_floor - rl->y_cell)) % (cl->tlist[7].img_h);
 	rl->x_floor += cl->mlist.x_floor_step;
 	rl->y_floor += cl->mlist.y_floor_step;
-	ft_put_floor_tex(y, x, cl);
+	ft_draw_extra_tex(6, y, x, cl);
+	ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl);
+	/* ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); */
+	/* ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); */
 }
 
 void
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 116f537..599e902 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -42,6 +42,15 @@ static void
 		&cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian);
 }
 
+static void
+	ft_get_ceil_tex(t_cub *cl)
+{
+	cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+			cl->mlist.no_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h);
+	cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img,
+		&cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian);
+}
+
 void
 	ft_wall_tex_init(t_cub *cl)
 {
@@ -68,5 +77,6 @@ void
 	if (cl->mlist.isnlvl)
 		ft_get_nlvl_img(cl);
 	ft_get_floor_tex(cl);
+	ft_get_ceil_tex(cl);
 	cl->walltexgood = 1;
 }
-- 
cgit v1.2.3