Cub3D
Loading...
Searching...
No Matches
render.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* render.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/08/26 01:57:48 by kamitsui #+# #+# */
9/* Updated: 2024/12/21 09:33:40 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15static void update_player(t_game *game)
16{
17 static t_moving_player func[6] = {
18 move_forward, move_backward,
19 strafe_left, strafe_right,
20 rotate_left, rotate_right};
21 int i;
22 int bit;
23
24 i = 0;
25 while (i < 6)
26 {
27 bit = 0x01 << i;
28 if (is_hit_flag(game->frame.flag, bit) == true)
29 func[i](&game->map, &game->player);
30 i++;
31 }
32 game->frame.flag = 0;
33}
34 //debug_moved_player(game);
35// debug_is_hit_flag(game, bit);// call this if is_hit_flag() == true
36
44static void draw_3d_view(t_frame *frame)
45{
46 int x;
47 static t_draw_3d_process func[5] = {
48 init_ray, perform_dda,
49 set_wall_slice, set_texture_x_coordinate,
50 draw_vertical_line};
51 int i;
52
53 x = 0;
54 while (x < IMG_3D_WIDTH)
55 {
56 i = 0;
57 while (i < 5)
58 {
59 func[i](frame, x);
60 i++;
61 }
62 x++;
63 }
64}
65
69static void draw_2d_map(t_game *game)
70{
71 draw_2d_wall(&game->map, &game->img_2d);
72 draw_2d_player(&game->img_2d, &game->player);
73}
74
82void render_frame(t_game *game)
83{
84 update_player(game);
85 draw_3d_view(&game->frame);
86 if (DISABLE_2D_MAP == true)
87 draw_2d_map(game);
88 mlx_put_image_to_window(game->mlx, game->win, game->img_3d.img, 0, 0);
89 if (DISABLE_2D_MAP == true)
90 mlx_put_image_to_window(
91 game->mlx, game->win, game->img_2d.img, IMG_3D_WIDTH, 0);
92}
93 //debug_frame(game, "render_frame()");
single still image for render_frame
Definition type_cub3d.h:247
main game
Definition type_cub3d.h:264