scene_loader.c
void DrawSingleHealthBar(Tank* tank, Canvas* game_canvas){
	
	// Starting position for drawing
	int start_x = tank->x - HEALTH_BAR_X_OFFSET;
	int start_y = tank->y - HEALTH_BAR_Y_OFFSET;
	
	// Health and border color
	RGB inner_color = {.R = HEALTH_BAR_INNER_COLOR_R, .G = HEALTH_BAR_INNER_COLOR_G, .B = HEALTH_BAR_INNER_COLOR_B}; 
	RGB border_color = {.R = HEALTH_BAR_BORDER_COLOR_R, .G = HEALTH_BAR_BORDER_COLOR_G, .B = HEALTH_BAR_BORDER_COLOR_B}; 
	
	// How much health does the tank have ? How high should the inner part be
	double health_height = (((((double)tank->health)/TANK_HEALTH))*HEALTH_BAR_HEIGHT);

	for(int y = 0; y < HEALTH_BAR_HEIGHT; y++){
		for(int x = 0; x < HEALTH_BAR_WIDTH; x++){
			// Try to color only if we are withing boundraries
			if((start_x+x >= 0) && (start_x+x < DISPLAY_WIDTH) && (start_y+y >= 0) && (start_y+y < DISPLAY_HEIGHT)){
				if((y < HEALTH_BAR_BORDER) || (y > (HEALTH_BAR_HEIGHT-HEALTH_BAR_BORDER-1))){
					// Color border UP and DOWN
					ColorCanvasPixel(start_x+x, start_y+y, &border_color, game_canvas);
				}else{
					if((x < HEALTH_BAR_BORDER) || (x > (HEALTH_BAR_WIDTH-HEALTH_BAR_BORDER-1))){
						// Color border LEFT and RIGHT
						ColorCanvasPixel(start_x+x, start_y+y, &border_color, game_canvas);
					}else{
						// Color inner part if we satisfy requierement
						if(y >= (HEALTH_BAR_HEIGHT-health_height)){
							// Color innter part
							ColorCanvasPixel(start_x+x, start_y+y, &inner_color, game_canvas);
						}
					}
				}
			}
		}
	}
	
	return;
}
/*  This function takes tank as an argument and draws healthbar over it in game_canvas  */
This function takes tank as an argument and draws healthbar over it in game_canvas
This function takes tank as an argument and draws healthbar over it in game_canvas
void DrawSingleHealthBar(Tank* tank, Canvas* game_canvas){
	int start_x = tank->x - HEALTH_BAR_X_OFFSET;
	int start_y = tank->y - HEALTH_BAR_Y_OFFSET;
	RGB inner_color = {.R = HEALTH_BAR_INNER_COLOR_R, .G = HEALTH_BAR_INNER_COLOR_G, .B = HEALTH_BAR_INNER_COLOR_B}; 
	RGB border_color = {.R = HEALTH_BAR_BORDER_COLOR_R, .G = HEALTH_BAR_BORDER_COLOR_G, .B = HEALTH_BAR_BORDER_COLOR_B}; 
	double health_height = (((((double)tank->health)/TANK_HEALTH))*HEALTH_BAR_HEIGHT);
	for(int y = 0; y < HEALTH_BAR_HEIGHT; y++){
		for(int x = 0; x < HEALTH_BAR_WIDTH; x++){
			if((start_x+x >= 0) && (start_x+x < DISPLAY_WIDTH) && (start_y+y >= 0) && (start_y+y < DISPLAY_HEIGHT)){
				if((y < HEALTH_BAR_BORDER) || (y > (HEALTH_BAR_HEIGHT-HEALTH_BAR_BORDER-1))){
					ColorCanvasPixel(start_x+x, start_y+y, &border_color, game_canvas);
				}else{
					if((x < HEALTH_BAR_BORDER) || (x > (HEALTH_BAR_WIDTH-HEALTH_BAR_BORDER-1))){
						ColorCanvasPixel(start_x+x, start_y+y, &border_color, game_canvas);
					}else{
						if(y >= (HEALTH_BAR_HEIGHT-health_height)){
							ColorCanvasPixel(start_x+x, start_y+y, &inner_color, game_canvas);
						}
					}
				}
			}
		}
	}
	return;
}
void DrawSingleHealthBar ( Tank * tank , Canvas * game_canvas ) { int start_x = tank -> x - HEALTH_BAR_X_OFFSET ; int start_y = tank -> y - HEALTH_BAR_Y_OFFSET ; RGB inner_color = { . R = HEALTH_BAR_INNER_COLOR_R , . G = HEALTH_BAR_INNER_COLOR_G , . B = HEALTH_BAR_INNER_COLOR_B } ; RGB border_color = { . R = HEALTH_BAR_BORDER_COLOR_R , . G = HEALTH_BAR_BORDER_COLOR_G , . B = HEALTH_BAR_BORDER_COLOR_B } ; double health_height = ( ( ( ( ( double ) tank -> health ) / TANK_HEALTH ) ) * HEALTH_BAR_HEIGHT ) ; for ( int y = 0 ; y < HEALTH_BAR_HEIGHT ; y ++ ) { for ( int x = 0 ; x < HEALTH_BAR_WIDTH ; x ++ ) { if ( ( start_x + x >= 0 ) && ( start_x + x < DISPLAY_WIDTH ) && ( start_y + y >= 0 ) && ( start_y + y < DISPLAY_HEIGHT ) ) { if ( ( y < HEALTH_BAR_BORDER ) || ( y > ( HEALTH_BAR_HEIGHT - HEALTH_BAR_BORDER - 1 ) ) ) { ColorCanvasPixel ( start_x + x , start_y + y , & border_color , game_canvas ) ; } else { if ( ( x < HEALTH_BAR_BORDER ) || ( x > ( HEALTH_BAR_WIDTH - HEALTH_BAR_BORDER - 1 ) ) ) { ColorCanvasPixel ( start_x + x , start_y + y , & border_color , game_canvas ) ; } else { if ( y >= ( HEALTH_BAR_HEIGHT - health_height ) ) { ColorCanvasPixel ( start_x + x , start_y + y , & inner_color , game_canvas ) ; } } } } } } return ; }
This function takes tank as an argument and draws healthbar over it in game_canvas
This function takes tank as an argument and draws healthbar over it in game_canvas
// Starting position for drawing // Health and border color // How much health does the tank have ? How high should the inner part be // Try to color only if we are withing boundraries // Color border UP and DOWN // Color border LEFT and RIGHT // Color inner part if we satisfy requierement // Color innter part