88#include <stdlib.h>
99#include <math.h>
1010#include <SDL2/SDL.h>
11- #include <SDL2/SDL2_gfxPrimitives.h>
1211
1312
1413static int is_rotating (char enemy_type )
@@ -50,7 +49,7 @@ void set_enemy_attributes(struct list *new, SDL_Rect *pos,
5049
5150 new -> rotating = is_rotating (enemy_type );
5251 new -> curr_texture = 0 ;
53- init_position (window -> w , pos -> y , window ,
52+ init_position (DEFAULT_W , pos -> y ,
5453 new -> rotating ? new -> texture .textures [0 ]-> texture : new -> texture .texture -> texture ,
5554 & new -> pos_dst );
5655}
@@ -87,7 +86,12 @@ void create_enemies(struct window *window)
8786 break ;
8887 }
8988
90- SDL_Rect pos = { .x = 0 , .y = window -> paths -> data [window -> paths -> index ].line .enemy_path .pos_y - h / 2 , .w = 0 , .h = 0 };
89+ SDL_Rect pos = { .x = 0 ,
90+ .y = window -> paths -> data [window -> paths -> index ].line .enemy_path .pos_y
91+ - h / 2 ,
92+ .w = 0 ,
93+ .h = 0
94+ };
9195
9296 char type = window -> paths -> data [window -> paths -> index ].line .enemy_path .enemy_type ;
9397
@@ -182,14 +186,26 @@ void render_enemies(struct window *window)
182186 .h = h
183187 };
184188
189+ resize_pos_for_resolution (window , & pos );
190+
185191 SDL_RenderCopy (window -> renderer ,
186192 temp -> texture .textures [temp -> curr_texture ]-> texture ,
187193 NULL , & pos );
188194 }
189195 else
196+ {
197+ SDL_Rect pos = { .x = temp -> pos_dst .x ,
198+ .y = temp -> pos_dst .y ,
199+ .w = temp -> pos_dst .w ,
200+ .h = temp -> pos_dst .h
201+ };
202+
203+ resize_pos_for_resolution (window , & pos );
204+
190205 SDL_RenderCopy (window -> renderer ,
191206 temp -> texture .texture -> texture ,
192- NULL , & temp -> pos_dst );
207+ NULL , & pos );
208+ }
193209
194210 // Go to next enemy
195211 temp = temp -> next ;
@@ -202,19 +218,29 @@ void render_enemies(struct window *window)
202218
203219void render_enemy_health (struct window * window , struct list * enemy )
204220{
205- boxRGBA (window -> renderer ,
206- enemy -> pos_dst .x + enemy -> pos_dst .w / 2 - 50 ,
207- enemy -> pos_dst .y - 25 ,
208- enemy -> pos_dst .x + enemy -> pos_dst .w / 2 - 50 + (100 * enemy -> health ) / enemy -> max_health ,
209- enemy -> pos_dst .y - 20 ,
210- 0 , 255 , 0 , 192 );
211-
212- boxRGBA (window -> renderer ,
213- enemy -> pos_dst .x + enemy -> pos_dst .w / 2 - 50 + (100 * enemy -> health ) / enemy -> max_health ,
214- enemy -> pos_dst .y - 25 ,
215- enemy -> pos_dst .x + enemy -> pos_dst .w / 2 + 50 ,
216- enemy -> pos_dst .y - 20 ,
217- 255 , 0 , 0 , 192 );
221+ SDL_Rect pos = { .x = enemy -> pos_dst .x + enemy -> pos_dst .w / 2 - 50 ,
222+ .y = enemy -> pos_dst .y - 25 ,
223+ .w = (100 * enemy -> health ) / enemy -> max_health ,
224+ .h = 5
225+ };
226+
227+ int old_w = pos .w ;
228+
229+ resize_pos_for_resolution (window , & pos );
230+
231+ SDL_SetRenderDrawColor (window -> renderer , 0 , 255 , 0 , 192 ); // green
232+ SDL_RenderFillRect (window -> renderer , & pos );
233+
234+
235+ pos .x = enemy -> pos_dst .x + enemy -> pos_dst .w / 2 - 50 + (100 * enemy -> health ) / enemy -> max_health ;
236+ pos .y = enemy -> pos_dst .y - 25 ; // Mandatory because of the resize_pos_for_resolution
237+ pos .w = 100 - old_w ;
238+ pos .h = 5 ; // Mandatory because of the resize_pos_for_resolution
239+
240+ resize_pos_for_resolution (window , & pos );
241+
242+ SDL_SetRenderDrawColor (window -> renderer , 255 , 0 , 0 , 192 ); // red
243+ SDL_RenderFillRect (window -> renderer , & pos );
218244}
219245
220246
@@ -269,7 +295,7 @@ void move_enemy_shots(struct window *window)
269295 // Prevent out of bounds by deleting the shot if not on screen
270296 if (temp -> pos_dst .x + temp -> pos_dst .w <= 0
271297 || temp -> pos_dst .y + temp -> pos_dst .h <= 0
272- || temp -> pos_dst .y >= window -> h )
298+ || temp -> pos_dst .y >= DEFAULT_H )
273299 {
274300 struct list * to_delete = temp ;
275301 prev -> next = temp -> next ;
@@ -293,8 +319,16 @@ void render_enemy_shots(struct window *window)
293319
294320 while (temp )
295321 {
322+ SDL_Rect pos = { .x = temp -> pos_dst .x ,
323+ .y = temp -> pos_dst .y ,
324+ .w = temp -> pos_dst .w ,
325+ .h = temp -> pos_dst .h
326+ };
327+
328+ resize_pos_for_resolution (window , & pos );
329+
296330 // Display shot
297- SDL_RenderCopy (window -> renderer , window -> img -> enemy_shot -> texture , NULL , & temp -> pos_dst );
331+ SDL_RenderCopy (window -> renderer , window -> img -> enemy_shot -> texture , NULL , & pos );
298332
299333 // Go to next shot
300334 temp = temp -> next ;
0 commit comments