@@ -50,48 +50,58 @@ void draw_select_gun(t_game *game, int position)
5050 }
5151}
5252
53- static void set_animation_position (t_texture * frame , t_vector * pos )
53+ static void process_animation_pixels (t_game * game , t_texture * frame ,
54+ t_vector pos )
5455{
55- pos -> x = (WINDOW_WIDTH - frame -> width ) >> 1 ;
56- pos -> y = (WINDOW_HEIGHT - frame -> height ) >> 1 ;
57- }
58-
59- void draw_animation (t_game * game , t_animation * anim )
60- {
61- t_texture * current_frame ;
62- t_vector pos ;
63- t_vector_i pixel ;
64- unsigned int color ;
56+ t_vector_i pixel ;
57+ int color ;
6558
66- if (!anim -> active || anim -> frame_count == 0 )
67- return ;
68- current_frame = & anim -> frames [anim -> current_frame ];
69- if (!current_frame -> img )
70- return ;
71- set_animation_position (current_frame , & pos );
7259 pixel .y = -1 ;
73- while (++ pixel .y < current_frame -> height )
60+ while (++ pixel .y < frame -> height )
7461 {
7562 pixel .x = -1 ;
76- while (++ pixel .x < current_frame -> width )
63+ while (++ pixel .x < frame -> width )
7764 {
7865 if (pos .x + pixel .x < 0 || pos .x + pixel .x >= WINDOW_WIDTH || pos .y
7966 + pixel .y < 0 || pos .y + pixel .y >= WINDOW_HEIGHT )
8067 continue ;
81- color = get_texture_pixel (current_frame , pixel .x , pixel .y );
68+ color = get_texture_pixel (frame , pixel .x , pixel .y );
8269 if ((color & 0xFFC0CB ) != 0 )
8370 draw_pixel (game , pos .x + pixel .x , pos .y + pixel .y , color );
8471 }
8572 }
8673}
8774
75+ void draw_animation (t_game * game , t_animation * anim )
76+ {
77+ t_texture * current_frame ;
78+ t_vector pos ;
79+
80+ if (!anim )
81+ return ;
82+ if (!anim -> active || anim -> frame_count == 0 )
83+ return ;
84+ current_frame = & anim -> frames [anim -> current_frame ];
85+ if (!current_frame -> img )
86+ return ;
87+ pos .x = (WINDOW_WIDTH - current_frame -> width ) >> 1 ;
88+ pos .y = (WINDOW_HEIGHT - current_frame -> height ) >> 1 ;
89+ process_animation_pixels (game , current_frame , pos );
90+ }
91+
8892void draw_menu (t_game * game )
8993{
94+ if (!game || !game -> menu )
95+ return ;
9096 update_menu_animations (game );
91- draw_animation (game , & game -> menu -> bg );
92- draw_animation (game , & game -> menu -> cube );
93- draw_animation (game , & game -> menu -> start_btn .anim );
94- draw_animation (game , & game -> menu -> exit_btn .anim );
97+ if (game -> menu -> bg .active )
98+ draw_animation (game , & game -> menu -> bg );
99+ if (game -> menu -> cube .active )
100+ draw_animation (game , & game -> menu -> cube );
101+ if (game -> menu -> start_btn .anim .active )
102+ draw_animation (game , & game -> menu -> start_btn .anim );
103+ if (game -> menu -> exit_btn .anim .active )
104+ draw_animation (game , & game -> menu -> exit_btn .anim );
95105 if (game -> menu -> selected_option == 0 )
96106 draw_select_gun (game , 1 );
97107 else
0 commit comments