I have a little program that sets up a catapult to hit a target and avoid an obstacle, for my target and obstacle I have two different if statements that update the score (which is a global int), they set up a hit box for the each one and IF the projectile goes through it they should alter the score accordingly, however the if statements never activate for whatever reason. My current line of thinking is that its something to do with the global int score, but I have no real evidence for that, I'm not getting any errors which is even more confusing. Below I'll print the function that contains the if statements and the global int.
Code:
//global variables
int total_targets_down;
//draw projectile (coin)
int projectile(int user_input,float user_input_3,float user_input_4, int x_target_pos, int y_target_pos, int total_targets_down)
{
//set inital pos of coin
float pos_x=user_input-60;
float pos_y=280-10;
//PI to a value
int pie = 3.142;
//move to inital
GFX_MoveTo(pos_x, pos_y);
//set variables
int inital_y=pos_y;
int inital_x=pos_x;
float time=1;
int gravity=9.81;
double horiz = user_input_3*cos(user_input_4 *pie/180);
double vertical = user_input_3*sin(user_input_4 *pie/180);
//caculate trajectory
while(pos_y<399)
{
time=(pos_x-inital_x)/horiz;
pos_y=(inital_y)-(vertical*time)+(gravity*time*time)/2;
GFX_DrawLineTo(pos_x,pos_y,3);
pos_x+=1;
}
//make hit box for target, then update score if it is hit
if (pos_x>x_target_pos && pos_x<x_target_pos+120 && pos_y>y_target_pos-10 && pos_y<y_target_pos+80)
{
total_targets_down+=1;
printf("Wallet: %d\n", total_targets_down);
GFX_DrawCircle(30,30,20,4);
}
//make hit box for target, then update score if it is hit
if (pos_x> 180 && pos_x<260 && pos_y>280 && pos_y<360)
{
total_targets_down-=1;
printf("Wallet: %d\n", total_targets_down);
}
GFX_UpdateDisplay();
return 0;
}