what you really want to look into is velocity, and don't just increatment the values. What do I mean?
//the velocity. use any number, but I will use 2 herefloat yVel=2.0f;//switch statement for the keypresses, or w/e you want use. Maybe keystatesswitch(event.key.keysym.sym){ case SDLK_w: yVel-=sourceRect.h/speed; break; case SDLK_s: yVel+=sourceRect.h/speed; break;}
where sourceRect is the rect that holds the dimensions of the paddle.
What this is, is this in words: you just take the sourceRect height value, and divide it by the speed (pixels to move each frame) and subtract it from the yVel. Do just the opposite for the s (down) key.
now for collision. Collision is pretty easy for pong
if(destRect.x+destRect.w==WINDOW_HEIGHT){ //oops...we need to take the last move back now!! destRect.x-=yVel;}
it's really that simple. Here's a SDL tutorial explaining it more, if you need more help.
LazyFoo's motion tutorial.I hope that helps dude. If need more help, then don't be afraid to post back here.
Chad.
EDIT: Beaten, but will keep it here, just to clairify more.
Changed xVel to yVel.
EDIT 2: If you don't believe me, or want to know why the paddle moves, then lets do math.
EDIT 3: lol...last edit...hopefully. Just back here if you need help with the ball. It's basically just the same, except one little tiny bitty difference, but the logic is the same...so you might get it.
yVel=2.0, speed=10 (for right now it is), image size=32x32 (any size will work in SDL...I am just acting like we are moving a tile
so...first: 32/10=3.2
next: 2.0-3.2=-1.2
so, you can see that we are indeed moving it up, due to the cordinate system.