fix botoom line add floor and sky

This commit is contained in:
kinou-p 2022-06-01 19:23:23 +02:00
parent d895b3f4cc
commit 537c73b02c
4 changed files with 50 additions and 11 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */ /* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
/* Updated: 2022/05/20 14:04:12 by apommier ### ########.fr */ /* Updated: 2022/06/01 19:21:40 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -44,11 +44,18 @@ typedef struct all_wall_texture{
unsigned char *south; unsigned char *south;
} sprite; } sprite;
typedef struct s_color{
//unsigned char t;
unsigned char r;
unsigned char g;
unsigned char b;
} color;
typedef struct map_information{ typedef struct map_information{
char **map; char **map;
sprite texture; sprite texture;
int floor; color floor;
int sky; color sky;
char *simple_map; char *simple_map;
int size; int size;
int x; int x;

View File

@ -122,6 +122,8 @@ void draw_ray3d(t_data *img, ray ray)
int texture_size = 64; int texture_size = 64;
line_height = img->map.size * 960 / ray.dist; line_height = img->map.size * 960 / ray.dist;
if (line_height > 5000)
line_height = 5000;
line_offset = 256 - line_height / 2; line_offset = 256 - line_height / 2;
double gap = 1; double gap = 1;
double myy = 0; double myy = 0;
@ -130,7 +132,7 @@ void draw_ray3d(t_data *img, ray ray)
myy = 0; myy = 0;
gap = (texture_size / line_height); gap = (texture_size / line_height);
mx = ((int)ray.mp) % texture_size; mx = ((int)ray.mp) % texture_size;
while (y < line_height) while (y < line_height - 8)
{ {
myy += gap; myy += gap;
my = (int)myy;//gap; my = (int)myy;//gap;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */ /* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
/* Updated: 2022/05/20 15:57:10 by apommier ### ########.fr */ /* Updated: 2022/06/01 18:04:29 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,6 +49,8 @@ map_info set_map(char **argv)
} }
close(fd); close(fd);
ret_map.simple_map = map; ret_map.simple_map = map;
//ret_map.floor = ;
//ret_map.sky = ;
ret_map.x = 8; ret_map.x = 8;
ret_map.y = 8; ret_map.y = 8;
ret_map.size = ret_map.x * ret_map.y; ret_map.size = ret_map.x * ret_map.y;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */ /* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
/* Updated: 2022/05/20 16:00:24 by apommier ### ########.fr */ /* Updated: 2022/06/01 19:21:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -88,6 +88,15 @@ int is_good(t_data *img, int type)
return (1); return (1);
} }
/*int create_trgb(int t, int r, int g, int b)
{
return (t << 24 | r << 16 | g << 8 | b);
}*/
int create_trgb(unsigned char t, unsigned char r, unsigned char g, unsigned char b)
{
return (*(int *)(unsigned char [4]){b, g, r, t});
}
void set_back(t_data *img) void set_back(t_data *img)
{ {
//int x = 0; //int x = 0;
@ -121,25 +130,44 @@ void set_back(t_data *img)
//} //}
}*/ }*/
int x = 0; int x = 0;
//int tmp;
//tmp = (int *)img->buffer;
img->map.floor.r = 128;
img->map.floor.g = 128;
img->map.floor.b = 128;
img->map.sky.r = 0;
img->map.sky.g = 191;
img->map.sky.b = 255;
while (x < 512 * 960 * 4) while (x < 512 * 960 * 4)
{ {
if (x > 512 * 960 * 2) if (x > 512 * 960 * 2)
{ {
img->buffer[x + 0] = img->map.floor.b;
img->buffer[x + 1] = img->map.floor.g;
img->buffer[x + 2] =img->map.floor.r;
img->buffer[x + 3] = 0;
//tmp = create_trgb(128, 128, 128, 0);
img->buffer[x + 0] = 128; img->buffer[x + 0] = 128;
img->buffer[x + 1] = 128; img->buffer[x + 1] = 128;
img->buffer[x + 2] = 128; img->buffer[x + 2] = 128;
img->buffer[x + 3] = 128; img->buffer[x + 3] = 0;
} }
else else
{ {
img->buffer[x + 0] = 255; img->buffer[x + 0] = img->map.sky.b;
img->buffer[x + 1] = img->map.sky.g;
img->buffer[x + 2] =img->map.sky.r;
img->buffer[x + 3] = 0;
//tmp = create_trgb(255, 191, 0, 0);
/*img->buffer[x + 0] = 255;
img->buffer[x + 1] = 191; img->buffer[x + 1] = 191;
img->buffer[x + 2] = 0; img->buffer[x + 2] = 0;
img->buffer[x + 3] = 0; img->buffer[x + 3] = 0;*/
} }
x += 4; x += 4;
} }
//img->buffer = (char *)tmp;
/*while (x < 960) /*while (x < 960)
{ {
y = 0; y = 0;
@ -156,7 +184,7 @@ void set_back(t_data *img)
int key_press(int code, t_data *img) int key_press(int code, t_data *img)
{ {
printf("touche "); //printf("touche ");
if (code == 65307) if (code == 65307)
quit_game(img); quit_game(img);
else else