• Create Account

### #ActualMilcho

Posted 25 January 2013 - 10:33 AM

EDIT: Actually your first problem is that by setting yVel to 0 first, and then doing yVel -= 30, you will always be setting it to -30, and never to anything below that. You should set your yVel to 0 when the key up event is received, instead of in your main loop.
Note that if you hold down a key, you may constantly receive events for that key. So your keyhandling should be:
case SDLK_UP:
if (!jumping)
{
jumping = true;
myDot.yVel = 0;
}
break;
However, even if you remove setting it to 0 first you'll have another problem:

Your yVel will never be exactly -100. It will go -30, -60, -90, -120...etc.
if (myDot.yVel <= -100)
On a different note, is yVel supposed to be velocity or position? Because it kind of seems like you're treating it like position, and not velocity, which is fine, but the naming seems off.

### #3Milcho

Posted 25 January 2013 - 10:31 AM

EDIT: Actually your first problem is that by setting yVel to 0 first, and then doing yVel -= 30, you will always be setting it to -30, and never to anything below that. You should set your yVel to 0 when the key up event is received, instead of in your main loop
However, even if you remove setting it to 0 first you'll have another problem:

Your yVel will never be exactly -100. It will go -30, -60, -90, -120...etc.
if (myDot.yVel <= -100)

On a different note, is yVel supposed to be velocity or position? Because it kind of seems like you're treating it like position, and not velocity, which is fine, but the naming seems off.

### #2Milcho

Posted 25 January 2013 - 10:29 AM

EDIT: Actually your first problem is that by setting yVel to 0 first, and then doing yVel -= 30, you will always be setting it to -30, and never to anything below that. However, even if you remove setting it to 0 first you'll have another problem:

Your yVel will never be exactly -100. It will go -30, -60, -90, -120...etc.

if (myDot.yVel <= -100)

On a different note, is yVel supposed to be velocity or position? Because it kind of seems like you're treating it like position, and not velocity, which is fine, but the naming seems off.

### #1Milcho

Posted 25 January 2013 - 10:27 AM

Your yVel will never be exactly -100. It will go -30, -60, -90, -120...etc.

if (myDot.yVel <= -100)