I have an
if/else if statement that doesn't work only until I change it
to an
if/else statement. The problem is on line 31 where h should
increment 1 and it should because the previous if statement makes it so the
conditional will open up line 30. Here is the main issue. I need h to increment
so when I press space again a second fireball will fire off. And the weird part
is the second bullet will fire off BUT only after the first bullet crosses
the screen the FIRST time. After that, the 2nd bullet shoots??? When I tested
the program I found that h stays equal to 0 until the first bullet crosses the
screen. Can anybody see why. Thanks for any explanation. Again, this code does
work fine when I just make line 28 an else statement. I just need to understand
what is going on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
if(keystates[SDLK_SPACE])///If space is pressed
{
if((i==0&&h==0) || (i==0 && h==101))
i++;///increments i to 1 to record static jump with precise y-axis value
if(i==1 && h!=102)
{
staticJump=jump;
i=2;
h=100;
}
//having i = to 2 in this conditional might pose a problem if I make this program a sidescroller
if(h==101 && i==2)
{
h=102;
staticJump2=jump;
}
if(i==2)
fireballShot[0]+=10;
if(h==102)
fireballShot[1]+=10;
}
/**HERE"S THE CONFUSION! When I simply put this as an else statement, the first statement in this function [h++] registers**/
else if(i==2 || h==102)///program works like a charm if i simply make this an else statement
{
if(h==100)
h++;
if(i==2)
fireballShot[0]+=10;
if(h==102)
fireballShot[1]+=10;
///if fireball reaches the end of the screen, bring it back to the ball
if(fireballShot[0]>SCREEN_WIDTH /*&& fireballShot[1]>SCREEN_WIDTH*/)
{
i=0;
fireballShot[0]=ballPositionXAxis;
}
//^^^combine these two when I figure out initial second bullet problem [less code sake]
if(fireballShot[1]>SCREEN_WIDTH)
{
fireballShot[1]=ballPositionXAxis;
h=0;
}
}
|