scene_loader.c
void CalculateParabolicPath(SceneData* scene_data, int max_positions, 
							int start_x, int start_y, 
							double angle, double gravity, double wind_speed, double velocity, 
							bool wind,
							bool should_malloc,
							bool private_path
							){
	/* We will calculate this parabola in conventional cartesian coordinate system
	   we will have to map those coordinates to our display grid with different values.  */
	int valid_size = max_positions; //  <= max_positions. Size depends on duration of flight 
	
	Parabola* parabola;
	if(should_malloc){
		// Malloc our Parabola datatype
		parabola = malloc(sizeof(Parabola));
		if(parabola == NULL){
			printf("ERROR: Could not malloc 'Parabola' in CalculateParabolicPath!\n");
			exit(EXIT_FAILURE);
		}
		
		// Malloc our array in which we will store our pixels
		parabola->parabolic_path = malloc(max_positions*2*sizeof(short int)); // Each pixel has 2 coordinates
		
		
		if(parabola->parabolic_path == NULL){
			printf("ERROR: Could not malloc 'parabolic_path' in CalculateParabolicPath!\n");
			exit(EXIT_FAILURE);
	}
	}else{
		if(private_path){
			parabola = scene_data[SCENE_GAME_MAP].aim_path_private;
		}else{
			parabola = scene_data[SCENE_GAME_MAP].aim_path_public;
			// If we have public parabola, player doesnt see effect of the wind 
			wind = false;
		}
	}
	
	
	////////// START CALCULATION ///////////
	double converter = PI / 180; // Convert degrees to radians

	double v_x = velocity*cos(angle*converter); // horizontal velocity, along x-axis
	double v_y = velocity*sin(angle*converter); // vertical velocity, along y-axis
	
	for(int i = 0; i < max_positions; i++){
		short int new_x, new_y; // Variables for new positions
		double time_delta = (double)i*ARRAY_PATH_TIME_CHANGE;
		
		// Calculate new x coordinate  // s = start_x + v*t + wind_v*t   // wind has negative speed when it moves to the left 
		if(wind){ // WIND == ON
			new_x = (short int)(start_x + (v_x*time_delta) + (wind_speed*time_delta));
		}else{ // WIND == OFF
			new_x = (short int)(start_x + (v_x*time_delta));
			printf("new_x: %d\n", new_x);
			printf("v_x*time_delta: %f\n", v_x*time_delta);
			printf("v_x: %f\n", v_x);
			printf("time_delta: %f\n", time_delta);
		}
		
		// Calculate new y coordinate // s =  start_y + v0*t + (1/2)*g*t^2 
		new_y = (short int)(start_y + (v_y*time_delta) + (0.5)*gravity*time_delta*time_delta);

		// Check bounds, break if needed
		if((new_y <= 0) || (new_x <= 0) || (new_x >= DISPLAY_WIDTH)){
			valid_size = i-1; // Our size of valid pixels will be smaller,
			break;
		}else{
			parabola->parabolic_path[(i*2)] = new_x;
			parabola->parabolic_path[(i*2)+1] = new_y;
		}
	}
	////////////////////////////////////////
	
	// Write final valid size to parabola
	parabola->number_of_pairs = valid_size;
	
	if(should_malloc){
		if(private_path){
			scene_data[SCENE_GAME_MAP].aim_path_private = parabola;
		}else{
			scene_data[SCENE_GAME_MAP].aim_path_public = parabola;
		}
	}
	return;
}
/*  This function calculates parabola.
	For each time delta of size 'ARRAY_PATH_TIME_CHANGE' seconds, it will calculate positions x,y.
	We will specify the number of positions (time stamps) we want, which then also corresponds to the flight
	time. If the path gets ouf of left,right, bottom bounds it will end. -> upper boundrary not included
	I wanted to make this function more generic so it could be possibly used for other things.
	-Option 'should_malloc' will allocate our new path to array public or private according to arguments.
	-Option 'private_path' decides which path is calculated public or private one
	 */
This function calculates parabola.
For each time delta of size 'ARRAY_PATH_TIME_CHANGE' seconds, it will calculate positions x,y.
We will specify the number of positions (time stamps) we want, which then also corresponds to the flight
time. If the path gets ouf of left,right, bottom bounds it will end. -> upper boundrary not included
I wanted to make this function more generic so it could be possibly used for other things.
Option 'should_malloc' will allocate our new path to array public or private according to arguments.
Option 'private_path' decides which path is calculated public or private one
This function calculates parabola . For each time delta of size ' ARRAY_PATH_TIME_CHANGE ' seconds it will calculate positions x y . We will specify the number of positions ( time stamps ) we want which then also corresponds to the flight time . If the path gets ouf of left right bottom bounds it will end . - > upper boundrary not included I wanted to make this function more generic so it could be possibly used for other things . Option ' should_malloc ' will allocate our new path to array public or private according to arguments . Option ' private_path ' decides which path is calculated public or private one
void CalculateParabolicPath(SceneData* scene_data, int max_positions, 
							int start_x, int start_y, 
							double angle, double gravity, double wind_speed, double velocity, 
							bool wind,
							bool should_malloc,
							bool private_path
							){
	int valid_size = max_positions; 
	Parabola* parabola;
	if(should_malloc){
		parabola = malloc(sizeof(Parabola));
		if(parabola == NULL){
			printf("ERROR: Could not malloc 'Parabola' in CalculateParabolicPath!\n");
			exit(EXIT_FAILURE);
		}
		parabola->parabolic_path = malloc(max_positions*2*sizeof(short int)); 
		if(parabola->parabolic_path == NULL){
			printf("ERROR: Could not malloc 'parabolic_path' in CalculateParabolicPath!\n");
			exit(EXIT_FAILURE);
	}
	}else{
		if(private_path){
			parabola = scene_data[SCENE_GAME_MAP].aim_path_private;
		}else{
			parabola = scene_data[SCENE_GAME_MAP].aim_path_public;
			wind = false;
		}
	}
	double converter = PI / 180; 
	double v_x = velocity*cos(angle*converter); 
	double v_y = velocity*sin(angle*converter); 
	for(int i = 0; i < max_positions; i++){
		short int new_x, new_y; 
		double time_delta = (double)i*ARRAY_PATH_TIME_CHANGE;
		if(wind){ 
			new_x = (short int)(start_x + (v_x*time_delta) + (wind_speed*time_delta));
		}else{ 
			new_x = (short int)(start_x + (v_x*time_delta));
			printf("new_x: %d\n", new_x);
			printf("v_x*time_delta: %f\n", v_x*time_delta);
			printf("v_x: %f\n", v_x);
			printf("time_delta: %f\n", time_delta);
		}
		new_y = (short int)(start_y + (v_y*time_delta) + (0.5)*gravity*time_delta*time_delta);
		if((new_y <= 0) || (new_x <= 0) || (new_x >= DISPLAY_WIDTH)){
			valid_size = i-1; 
			break;
		}else{
			parabola->parabolic_path[(i*2)] = new_x;
			parabola->parabolic_path[(i*2)+1] = new_y;
		}
	}
	parabola->number_of_pairs = valid_size;
	if(should_malloc){
		if(private_path){
			scene_data[SCENE_GAME_MAP].aim_path_private = parabola;
		}else{
			scene_data[SCENE_GAME_MAP].aim_path_public = parabola;
		}
	}
	return;
}
void CalculateParabolicPath ( SceneData * scene_data , int max_positions , int start_x , int start_y , double angle , double gravity , double wind_speed , double velocity , bool wind , bool should_malloc , bool private_path ) { int valid_size = max_positions ; Parabola * parabola ; if ( should_malloc ) { parabola = malloc ( sizeof ( Parabola ) ) ; if ( parabola == NULL ) { printf ( " \n " ) ; exit ( EXIT_FAILURE ) ; } parabola -> parabolic_path = malloc ( max_positions * 2 * sizeof ( short int ) ) ; if ( parabola -> parabolic_path == NULL ) { printf ( " \n " ) ; exit ( EXIT_FAILURE ) ; } } else { if ( private_path ) { parabola = scene_data [ SCENE_GAME_MAP ] . aim_path_private ; } else { parabola = scene_data [ SCENE_GAME_MAP ] . aim_path_public ; wind = false ; } } double converter = PI / 180 ; double v_x = velocity * cos ( angle * converter ) ; double v_y = velocity * sin ( angle * converter ) ; for ( int i = 0 ; i < max_positions ; i ++ ) { short int new_x , new_y ; double time_delta = ( double ) i * ARRAY_PATH_TIME_CHANGE ; if ( wind ) { new_x = ( short int ) ( start_x + ( v_x * time_delta ) + ( wind_speed * time_delta ) ) ; } else { new_x = ( short int ) ( start_x + ( v_x * time_delta ) ) ; printf ( " \n " , new_x ) ; printf ( " \n " , v_x * time_delta ) ; printf ( " \n " , v_x ) ; printf ( " \n " , time_delta ) ; } new_y = ( short int ) ( start_y + ( v_y * time_delta ) + ( 0.5 ) * gravity * time_delta * time_delta ) ; if ( ( new_y <= 0 ) || ( new_x <= 0 ) || ( new_x >= DISPLAY_WIDTH ) ) { valid_size = i - 1 ; break ; } else { parabola -> parabolic_path [ ( i * 2 ) ] = new_x ; parabola -> parabolic_path [ ( i * 2 ) + 1 ] = new_y ; } } parabola -> number_of_pairs = valid_size ; if ( should_malloc ) { if ( private_path ) { scene_data [ SCENE_GAME_MAP ] . aim_path_private = parabola ; } else { scene_data [ SCENE_GAME_MAP ] . aim_path_public = parabola ; } } return ; }
This function calculates parabola.
This function calculates parabola .
/* We will calculate this parabola in conventional cartesian coordinate system
	   we will have to map those coordinates to our display grid with different values.  */ //  <= max_positions. Size depends on duration of flight  // Malloc our Parabola datatype // Malloc our array in which we will store our pixels // Each pixel has 2 coordinates // If we have public parabola, player doesnt see effect of the wind  ////////// START CALCULATION /////////// // Convert degrees to radians // horizontal velocity, along x-axis // vertical velocity, along y-axis // Variables for new positions // Calculate new x coordinate  // s = start_x + v*t + wind_v*t   // wind has negative speed when it moves to the left  // WIND == ON // WIND == OFF // Calculate new y coordinate // s =  start_y + v0*t + (1/2)*g*t^2  // Check bounds, break if needed // Our size of valid pixels will be smaller, //////////////////////////////////////// // Write final valid size to parabola