scene_loader.c
void ProjectileDoDamage(SceneData* scene_data){
	
	// Load projectile
	Projectile* projectile = &(scene_data[SCENE_GAME_MAP].projectile);
	
	// Distance up to which players and terrain is damaged
	int explosion_radius = PROJECTILE_ATTRIBUTES[projectile->type][PROJECTILE_EXPLOSION_RADIUS];
	
	// Damage the projectile will make to players around (distance < explosion_radius)
	int projectile_damage = PROJECTILE_ATTRIBUTES[projectile->type][PROJECTILE_DAMAGE];
	
	/* Iterate through all the tanks and if the tank is alive
	   subtract their health with 'projectile_damage'*/
	int p1_tanks_total = scene_data[SCENE_GAME_MAP].player_1_tanks;
	int p2_tanks_total = scene_data[SCENE_GAME_MAP].player_2_tanks;

	for(int t = 0; t < p1_tanks_total; t++){
		Tank* temp_tank = &(scene_data[SCENE_GAME_MAP].player_1_tanks_obj[t]);
		
		if(temp_tank->is_alive == true){ // Is the tank alive?
			printf("temp_tank->distance_from_projectile <= explosion_radius :::  %f  <=   %d\n", temp_tank->distance_from_projectile, explosion_radius);
			if((temp_tank->distance_from_projectile) <= explosion_radius){
				// Subtract health
				printf("Subtracting health!  old health: %d  ", temp_tank->health);
				
				// Do damage linearly
				double percentage_to_deal = (explosion_radius-temp_tank->distance_from_projectile)/(explosion_radius);
				int dmg = percentage_to_deal*projectile_damage;
				
				temp_tank->health -= dmg;
				printf("new health: %d\n", temp_tank->health);
				
				// Kill the tank if the new health is <= 0
				if(temp_tank->health <= 0){
					temp_tank->is_alive = false;
				}
			}
		}
	}
	for(int t = 0; t < p2_tanks_total; t++){
		Tank* temp_tank = &(scene_data[SCENE_GAME_MAP].player_2_tanks_obj[t]);
		
		if(temp_tank->is_alive == true){ // Is the tank alive?
			printf("temp_tank->distance_from_projectile <= explosion_radius :::  %f  <=   %d\n", temp_tank->distance_from_projectile, explosion_radius);
			if((temp_tank->distance_from_projectile) <= explosion_radius){
				// Subtract health
				printf("Subtracting health!  old health: %d  ", temp_tank->health);
				
				// Do damage linearly
				double percentage_to_deal = (explosion_radius-temp_tank->distance_from_projectile)/(explosion_radius);
				int dmg = percentage_to_deal*projectile_damage;
				
				temp_tank->health -= dmg;
				printf("new health: %d\n", temp_tank->health);
				
				// Kill the tank if the new health is <= 0
				if(temp_tank->health <= 0){
					temp_tank->is_alive = false;
				}
				
			}
		}
	}
	
	// ADD TERRAIN DAMAGE
	
	/* Iterate through the whole map array and get the distance from projectile to
	   the top of the map in each point  */
	   
	// Load projectile and get the x and y coordinates
	int aim_path_index = projectile->projectile_path_pairs_index;
	Parabola* projectile_parabola = projectile->parabola;
	
	int projectile_x = projectile_parabola->parabolic_path[aim_path_index*2];
	int projectile_y = projectile_parabola->parabolic_path[aim_path_index*2 + 1];
	
	printf("PROJECTILE x: %d  y:  %d\n", projectile_x, projectile_y);
	//////////////////////////////////////////////////	
	
	for(int x = 0; x < DISPLAY_WIDTH; x++){
		// Get y position of terraint
		int y = DISPLAY_HEIGHT-scene_data[SCENE_GAME_MAP].game_map_array[x];
		
		printf("TERRAIN x: %d  y:  %d\n", x, y);
		
		// Get the distance from parabola to terrain point
		int distance = (int)GetDistance(projectile_x, projectile_y, x, y);
		printf("GOT DISTANCE: %d\n", distance);
		/* If the distance is withing the explosion radius or the explosion occured
		   under the terrain -> remove chunks of terrain.  */
		if(distance < explosion_radius){
			// The closer to the center, remove more chunks of terrain
			int to_remove = abs((int)((explosion_radius - distance)*TERRAIN_REMOVER_MULTIPLIER));
			printf("REMOVE: %d px\n", to_remove);
			if((scene_data[SCENE_GAME_MAP].game_map_array[x] + to_remove)  >= (DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER)){
				scene_data[SCENE_GAME_MAP].game_map_array[x] = DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER;
			}else{
				scene_data[SCENE_GAME_MAP].game_map_array[x] += to_remove;
			}
		}else if((projectile_y < (y-explosion_radius)) && (abs(projectile_x - x) <= explosion_radius)){
			int to_remove = abs((int)((explosion_radius - projectile_x)*TERRAIN_REMOVER_MULTIPLIER));
			printf("REMOVE: %d px\n", to_remove);
			if((scene_data[SCENE_GAME_MAP].game_map_array[x] + to_remove)  >= (DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER)){
				scene_data[SCENE_GAME_MAP].game_map_array[x] = DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER;
			}else{
				scene_data[SCENE_GAME_MAP].game_map_array[x] += to_remove;
			}
		}
		
	}
	
	
	
	return;
}
/*  This function dealth damage to its surroundings, player tanks and terrain  */
This function dealth damage to its surroundings, player tanks and terrain
This function dealth damage to its surroundings player tanks and terrain
void ProjectileDoDamage(SceneData* scene_data){
	Projectile* projectile = &(scene_data[SCENE_GAME_MAP].projectile);
	int explosion_radius = PROJECTILE_ATTRIBUTES[projectile->type][PROJECTILE_EXPLOSION_RADIUS];
	int projectile_damage = PROJECTILE_ATTRIBUTES[projectile->type][PROJECTILE_DAMAGE];
	int p1_tanks_total = scene_data[SCENE_GAME_MAP].player_1_tanks;
	int p2_tanks_total = scene_data[SCENE_GAME_MAP].player_2_tanks;
	for(int t = 0; t < p1_tanks_total; t++){
		Tank* temp_tank = &(scene_data[SCENE_GAME_MAP].player_1_tanks_obj[t]);
		if(temp_tank->is_alive == true){ 
			printf("temp_tank->distance_from_projectile <= explosion_radius :::  %f  <=   %d\n", temp_tank->distance_from_projectile, explosion_radius);
			if((temp_tank->distance_from_projectile) <= explosion_radius){
				printf("Subtracting health!  old health: %d  ", temp_tank->health);
				double percentage_to_deal = (explosion_radius-temp_tank->distance_from_projectile)/(explosion_radius);
				int dmg = percentage_to_deal*projectile_damage;
				temp_tank->health -= dmg;
				printf("new health: %d\n", temp_tank->health);
				if(temp_tank->health <= 0){
					temp_tank->is_alive = false;
				}
			}
		}
	}
	for(int t = 0; t < p2_tanks_total; t++){
		Tank* temp_tank = &(scene_data[SCENE_GAME_MAP].player_2_tanks_obj[t]);
		if(temp_tank->is_alive == true){ 
			printf("temp_tank->distance_from_projectile <= explosion_radius :::  %f  <=   %d\n", temp_tank->distance_from_projectile, explosion_radius);
			if((temp_tank->distance_from_projectile) <= explosion_radius){
				printf("Subtracting health!  old health: %d  ", temp_tank->health);
				double percentage_to_deal = (explosion_radius-temp_tank->distance_from_projectile)/(explosion_radius);
				int dmg = percentage_to_deal*projectile_damage;
				temp_tank->health -= dmg;
				printf("new health: %d\n", temp_tank->health);
				if(temp_tank->health <= 0){
					temp_tank->is_alive = false;
				}
			}
		}
	}
	 and get the x and y coordinates
	int aim_path_index = projectile->projectile_path_pairs_index;
	Parabola* projectile_parabola = projectile->parabola;
	int projectile_x = projectile_parabola->parabolic_path[aim_path_index*2];
	int projectile_y = projectile_parabola->parabolic_path[aim_path_index*2 + 1];
	printf("PROJECTILE x: %d  y:  %d\n", projectile_x, projectile_y);
	for(int x = 0; x < DISPLAY_WIDTH; x++){
		int y = DISPLAY_HEIGHT-scene_data[SCENE_GAME_MAP].game_map_array[x];
		printf("TERRAIN x: %d  y:  %d\n", x, y);
		int distance = (int)GetDistance(projectile_x, projectile_y, x, y);
		printf("GOT DISTANCE: %d\n", distance);
		if(distance < explosion_radius){
			int to_remove = abs((int)((explosion_radius - distance)*TERRAIN_REMOVER_MULTIPLIER));
			printf("REMOVE: %d px\n", to_remove);
			if((scene_data[SCENE_GAME_MAP].game_map_array[x] + to_remove)  >= (DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER)){
				scene_data[SCENE_GAME_MAP].game_map_array[x] = DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER;
			}else{
				scene_data[SCENE_GAME_MAP].game_map_array[x] += to_remove;
			}
		}else if((projectile_y < (y-explosion_radius)) && (abs(projectile_x - x) <= explosion_radius)){
			int to_remove = abs((int)((explosion_radius - projectile_x)*TERRAIN_REMOVER_MULTIPLIER));
			printf("REMOVE: %d px\n", to_remove);
			if((scene_data[SCENE_GAME_MAP].game_map_array[x] + to_remove)  >= (DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER)){
				scene_data[SCENE_GAME_MAP].game_map_array[x] = DISPLAY_HEIGHT-TERRAIN_BOTTOM_BORDER;
			}else{
				scene_data[SCENE_GAME_MAP].game_map_array[x] += to_remove;
			}
		}
	}
	return;
}
void ProjectileDoDamage ( SceneData * scene_data ) { Projectile * projectile = & ( scene_data [ SCENE_GAME_MAP ] . projectile ) ; int explosion_radius = PROJECTILE_ATTRIBUTES [ projectile -> type ] [ PROJECTILE_EXPLOSION_RADIUS ] ; int projectile_damage = PROJECTILE_ATTRIBUTES [ projectile -> type ] [ PROJECTILE_DAMAGE ] ; int p1_tanks_total = scene_data [ SCENE_GAME_MAP ] . player_1_tanks ; int p2_tanks_total = scene_data [ SCENE_GAME_MAP ] . player_2_tanks ; for ( int t = 0 ; t < p1_tanks_total ; t ++ ) { Tank * temp_tank = & ( scene_data [ SCENE_GAME_MAP ] . player_1_tanks_obj [ t ] ) ; if ( temp_tank -> is_alive == true ) { printf ( " \n " , temp_tank -> distance_from_projectile , explosion_radius ) ; if ( ( temp_tank -> distance_from_projectile ) <= explosion_radius ) { printf ( " " , temp_tank -> health ) ; double percentage_to_deal = ( explosion_radius - temp_tank -> distance_from_projectile ) / ( explosion_radius ) ; int dmg = percentage_to_deal * projectile_damage ; temp_tank -> health -= dmg ; printf ( " \n " , temp_tank -> health ) ; if ( temp_tank -> health <= 0 ) { temp_tank -> is_alive = false ; } } } } for ( int t = 0 ; t < p2_tanks_total ; t ++ ) { Tank * temp_tank = & ( scene_data [ SCENE_GAME_MAP ] . player_2_tanks_obj [ t ] ) ; if ( temp_tank -> is_alive == true ) { printf ( " \n " , temp_tank -> distance_from_projectile , explosion_radius ) ; if ( ( temp_tank -> distance_from_projectile ) <= explosion_radius ) { printf ( " " , temp_tank -> health ) ; double percentage_to_deal = ( explosion_radius - temp_tank -> distance_from_projectile ) / ( explosion_radius ) ; int dmg = percentage_to_deal * projectile_damage ; temp_tank -> health -= dmg ; printf ( " \n " , temp_tank -> health ) ; if ( temp_tank -> health <= 0 ) { temp_tank -> is_alive = false ; } } } } int aim_path_index = projectile -> projectile_path_pairs_index ; Parabola * projectile_parabola = projectile -> parabola ; int projectile_x = projectile_parabola -> parabolic_path [ aim_path_index * 2 ] ; int projectile_y = projectile_parabola -> parabolic_path [ aim_path_index * 2 + 1 ] ; printf ( " \n " , projectile_x , projectile_y ) ; for ( int x = 0 ; x < DISPLAY_WIDTH ; x ++ ) { int y = DISPLAY_HEIGHT - scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] ; printf ( " \n " , x , y ) ; int distance = ( int ) GetDistance ( projectile_x , projectile_y , x , y ) ; printf ( " \n " , distance ) ; if ( distance < explosion_radius ) { int to_remove = abs ( ( int ) ( ( explosion_radius - distance ) * TERRAIN_REMOVER_MULTIPLIER ) ) ; printf ( " \n " , to_remove ) ; if ( ( scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] + to_remove ) >= ( DISPLAY_HEIGHT - TERRAIN_BOTTOM_BORDER ) ) { scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] = DISPLAY_HEIGHT - TERRAIN_BOTTOM_BORDER ; } else { scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] += to_remove ; } } else if ( ( projectile_y < ( y - explosion_radius ) ) && ( abs ( projectile_x - x ) <= explosion_radius ) ) { int to_remove = abs ( ( int ) ( ( explosion_radius - projectile_x ) * TERRAIN_REMOVER_MULTIPLIER ) ) ; printf ( " \n " , to_remove ) ; if ( ( scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] + to_remove ) >= ( DISPLAY_HEIGHT - TERRAIN_BOTTOM_BORDER ) ) { scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] = DISPLAY_HEIGHT - TERRAIN_BOTTOM_BORDER ; } else { scene_data [ SCENE_GAME_MAP ] . game_map_array [ x ] += to_remove ; } } } return ; }
This function dealth damage to its surroundings, player tanks and terrain
This function dealth damage to its surroundings player tanks and terrain
// Load projectile // Distance up to which players and terrain is damaged // Damage the projectile will make to players around (distance < explosion_radius) /* Iterate through all the tanks and if the tank is alive
	   subtract their health with 'projectile_damage'*/ // Is the tank alive? // Subtract health // Do damage linearly // Kill the tank if the new health is <= 0 // Is the tank alive? // Subtract health // Do damage linearly // Kill the tank if the new health is <= 0 // ADD TERRAIN DAMAGE /* Iterate through the whole map array and get the distance from projectile to
	   the top of the map in each point  */ // Load projectile and get the x and y coordinates //////////////////////////////////////////////////	 // Get y position of terraint // Get the distance from parabola to terrain point /* If the distance is withing the explosion radius or the explosion occured
		   under the terrain -> remove chunks of terrain.  */ // The closer to the center, remove more chunks of terrain