aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-03-07 20:30:07 +0100
committerRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-03-07 20:30:07 +0100
commitced2be0469537a5d21043325c9bc54762197ec30 (patch)
tree0147b95e157bec2b301e82badc1532d40335201b
parentThe sky is nice (diff)
download42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.gz
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.bz2
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.xz
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.tar.zst
42-cub3d-ced2be0469537a5d21043325c9bc54762197ec30.zip
qwe
Diffstat (limited to '')
-rw-r--r--inc/cub3d.h3
-rw-r--r--inc/cub3d_structs.h1
-rw-r--r--map/lvl_four.cub24
-rw-r--r--map/lvl_one.cub6
-rw-r--r--src/ft_darken_rgb.c33
-rw-r--r--src/ft_draw_scene.c19
-rw-r--r--src/ft_draw_verline.c6
-rw-r--r--src/ft_rgb_to_hex.c6
8 files changed, 61 insertions, 37 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 692822a..5c37433 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -130,7 +130,8 @@ uint8_t ft_free_words(char **words);
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);
-uint32_t ft_darken_rgb(t_rgb rgb, t_cub *cl);
+uint32_t ft_darken_ceil(t_rgb rgb, t_cub *cl);
+uint32_t ft_darken_floor(t_rgb rgb, t_cub *cl);
t_bmp_rgb ft_hex_to_rgb(uint32_t color);
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index d392f0c..4638030 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -192,6 +192,7 @@ typedef struct s_cub
struct s_rgb c_rgb;
struct s_img tlist[6];
struct s_sprite sp_list;
+ int32_t y;
} t_cub;
# endif
diff --git a/map/lvl_four.cub b/map/lvl_four.cub
index 4b34b69..58e99a6 100644
--- a/map/lvl_four.cub
+++ b/map/lvl_four.cub
@@ -1,4 +1,4 @@
-R 1000 1000
+R 1500 1000
NO ./media/img/arrow1.xpm
SO ./media/img/arrow2.xpm
@@ -13,12 +13,16 @@ MU ./media/sound/DEVANT-LES-KAISSONS.wav
LT ./media/img/plate.xpm
L ./map/lvl_five.cub
-111111111111111111111111111111111111111111111111111111111111 111
-1E0000000000000000000000000000000000000011000000000000000001 101
-1111111111111111111111111111111111111110110111111111111111011111111101
- 10000000000000000000000000000000000001101 1L1 1000000000001
- 10111111111111111111111111111111111111101 101 1011111111101
- 1000000011111110000000000001 101 1011111111101 101
- 11111110000000001111111111011111111111101 1000000000001 101
- 11111111111 1000000000000001 1111111111111 101
- 1111111111111111 111
+ 1
+ 1L1
+ 11011
+ 1110111
+ 110000011
+ 11101111111
+ 1000000000001
+ 111110111111011
+ 11111111111010111
+ 1100000000000000001
+ 111011111000111111011
+ 1E000000000000000000001
+1111111111111111111111111
diff --git a/map/lvl_one.cub b/map/lvl_one.cub
index c6c7cc0..e772d30 100644
--- a/map/lvl_one.cub
+++ b/map/lvl_one.cub
@@ -1,4 +1,4 @@
-R 1500 900
+R 1600 1000
NO ./media/img/BRIQUASSE_3.xpm
SO ./media/img/BRIQUASSE_3.xpm
@@ -15,8 +15,8 @@ LT ./media/img/crapaud.xpm
MU ./media/sound/DEVANT-LES-KAISSONS.wav
1111111
-111111111111L000W1
+111111111111L00001
110101010101111101
-100000000000000001
+1E0000000000000001
110101010101010111
111111111111111111
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c
index 3587d72..fe69fa2 100644
--- a/src/ft_darken_rgb.c
+++ b/src/ft_darken_rgb.c
@@ -15,20 +15,33 @@
#include <stdio.h>
uint32_t
- ft_darken_rgb(t_rgb rgb, t_cub *cl)
+ ft_darken_ceil(t_rgb rgb, t_cub *cl)
{
t_rgb darker;
- float dist;
float calc;
- if ((dist = cl->rlist.wall_dist) <= 0)
- dist = 0.0001;
- calc = (dist * 0.2);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
darker = rgb;
- darker.r /= calc;
- darker.g /= calc;
- darker.b /= calc;
+ calc = ((float)(cl->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;
+ return (ft_rgb_to_hex(darker));
+}
+
+uint32_t
+ ft_darken_floor(t_rgb rgb, t_cub *cl)
+{
+ t_rgb darker;
+ float calc;
+
+ calc = ((float)(cl->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_scene.c b/src/ft_draw_scene.c
index f96eae6..e7895f5 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -21,20 +21,18 @@ static int8_t
const uint32_t x = 15;
const uint32_t y = clist->wlist.y_size
- (clist->mlist.map_h * clist->mlist.scale) - 20;
- const uint8_t len = 6 + ft_uintlen(clist->currlvl);
+ uint8_t len;
char *str;
+ len = 6 + ft_uintlen(clist->currlvl);
if (!(str = (char*)malloc((len + 1) * sizeof(char))))
return (-1);
ft_sprintf(str, "Stage %hd", clist->currlvl);
- if (clist->mlist.isnlvl)
- {
- mlx_string_put(clist->wlist.wlx,
- clist->wlist.winptr,
- x, y,
- 0x00ff0000,
- str);
- }
+ mlx_string_put(clist->wlist.wlx,
+ clist->wlist.winptr,
+ x, y,
+ 0x00ff0000,
+ str);
ft_memdel((void**)&str);
return (0);
}
@@ -50,11 +48,10 @@ void
if (clist->ishud)
{
ft_draw_hud(clist);
- ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist);
}
mlx_put_image_to_window(clist->wlist.wlx,
clist->wlist.winptr, clist->img.img, 0, 0);
- if (clist->ishud)
+ if (clist->ishud && clist->mlist.isnlvl)
{
if (ft_put_stage(clist) < 0)
{
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index 3198357..8621668 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -18,9 +18,10 @@ static void
{
while ((uint32_t)y < cl->wlist.y_size)
{
+ cl->y = y;
*(int*)(cl->img.ptr +
(x * 4 + (y * cl->img.sizeline)))
- = ft_rgb_to_hex(cl->f_rgb);
+ = ft_darken_floor(cl->f_rgb, cl);
y++;
}
}
@@ -33,9 +34,10 @@ static void
i = 0;
while (i <= y)
{
+ cl->y = i;
*(int*)(cl->img.ptr +
(x * 4 + (i * cl->img.sizeline)))
- = ft_darken_rgb(cl->c_rgb, cl);
+ = ft_darken_ceil(cl->c_rgb, cl);
i++;
}
}
diff --git a/src/ft_rgb_to_hex.c b/src/ft_rgb_to_hex.c
index a25d3e0..e101dcf 100644
--- a/src/ft_rgb_to_hex.c
+++ b/src/ft_rgb_to_hex.c
@@ -18,6 +18,12 @@ uint32_t
{
uint32_t res;
+ rgb.r = (rgb.r > 255) ? (255) : (rgb.r);
+ rgb.g = (rgb.g > 255) ? (255) : (rgb.g);
+ rgb.b = (rgb.b > 255) ? (255) : (rgb.b);
+ rgb.r = (rgb.r < 0) ? (0) : (rgb.r);
+ rgb.g = (rgb.g < 0) ? (0) : (rgb.g);
+ rgb.b = (rgb.b < 0) ? (0) : (rgb.b);
res = 0;
res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b);
return (res);