better background in 3D

This commit is contained in:
kinou-p 2022-05-05 03:07:10 +02:00
parent 6b370aa76d
commit 83d429796c
4 changed files with 39 additions and 6 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/04 18:46:58 by apommier ### ########.fr */ /* Updated: 2022/05/05 02:58:26 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,6 +52,7 @@ typedef struct s_data {
player player; player player;
} t_data; } t_data;
int get_color(char one, char two, char three);
int reset_angle(int angle); int reset_angle(int angle);
float deg_to_rad(int angle); float deg_to_rad(int angle);
void draw_ray(t_data *img); void draw_ray(t_data *img);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/04 18:08:14 by apommier #+# #+# */ /* Created: 2022/05/04 18:08:14 by apommier #+# #+# */
/* Updated: 2022/05/05 02:51:15 by apommier ### ########.fr */ /* Updated: 2022/05/05 02:59:14 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,6 +29,19 @@ void print_ray2(t_data *img, float vx, float vy, float dist)
} }
} }
int get_color(char one, char two, char three)
{
int color = 0;
color = color << 8;
color += one;
color = color << 8;
color += two;
color = color << 8;
color += three;
return (color);
}
int get_red() int get_red()
{ {
int red = 0; int red = 0;

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/05 02:52:35 by apommier ### ########.fr */ /* Updated: 2022/05/05 02:55:40 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -206,7 +206,7 @@ int main(int argc, char **argv)
img.player.vy = sin(deg_to_rad(img.player.angle)); img.player.vy = sin(deg_to_rad(img.player.angle));
print_map(img.map, &img); print_map(img.map, &img);
print_player(img.player, &img); print_player(img.player, &img);
print_ray(&img); //print_ray(&img);
mlx_hook(img.mlx_win, 2, 1L << 0, &key_press, &img); mlx_hook(img.mlx_win, 2, 1L << 0, &key_press, &img);
mlx_hook(img.mlx_win, 17, 0L, &quit_game, &img); mlx_hook(img.mlx_win, 17, 0L, &quit_game, &img);
mlx_loop(img.mlx); mlx_loop(img.mlx);

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/05 02:53:07 by apommier ### ########.fr */ /* Updated: 2022/05/05 03:05:12 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -98,6 +98,24 @@ int is_good(t_data *img, int type)
return (1); return (1);
} }
void print_back(t_data *img)
{
int x = 530;
int y = 160;
while (x < 1024)
{
y = 0;
while (y < 320)
{
mlx_pixel_put(img->mlx, img->mlx_win, x , y, get_color(128, 128, 128));
//mlx_pixel_put(img->mlx, img->mlx_win, x , y - 160, get_color(0, 255, 255));
y++;
}
x++;
}
}
int key_press(int code, t_data *img) int key_press(int code, t_data *img)
{ {
if (code == 65307) if (code == 65307)
@ -107,9 +125,10 @@ int key_press(int code, t_data *img)
if (is_good(img, code)) if (is_good(img, code))
{ {
//printf("code = %d\n", code); //printf("code = %d\n", code);
mlx_clear_window(img->mlx, img->mlx_win); //mlx_clear_window(img->mlx, img->mlx_win);
print_map(img->map, img); print_map(img->map, img);
print_player(img->player, img); print_player(img->player, img);
print_back(img);
draw_ray(img); draw_ray(img);
print_ray(img); print_ray(img);
} }