1. I am trying to make a pong paddle move by holding down a button. Rigtht now, it doesnt move at all. Here are the functions that are suppose to move the paddle and draw it.
2. I am trying to make the ball move by itself a little bit each frame, but its not working. The code for moving the ball is at the bottom.
That would only work if you started another thread which went ahead and looked at the next event. Since this isn't multi-threaded, when it detects that the user pressed the up (or down) key, it will enter an infinite loop.
The render function should show the paddle in its current position.
Also this: if( User.yPos > 0 && User.yPos < 480 ) would freeze the paddle if its position is <= 0 or >= 480. What you should do is not let the paddle go down if its new position would bring it below 480 (assuming y == 0 is top) and not let the paddle go up if its new position would bring it above 0.
Comment out your event handler except for the quit event. Does the paddle then show up? If not, it's either a problem with User.yPos not being initialized or a problem with the userPaddle surface. If the paddle does show up, then all I can think of (without seeing the rest of the code) is that the paddle moves so quick it goes beyond the screen before you have a chance to see it. If that's it, then you should make the paddle move slower (try 1, or 0.01 instead of 5). If you haven't already, you should also implement the proper collision detection for the boundary in your event handler:
shacktar wrote:
What you should do is not let the paddle go down if its new position would bring it below 480 (assuming y == 0 is top) and not let the paddle go up if its new position would bring it above 0.
You said you key down event looks just like mine so I assume you haven't implemented it yet. It's trivial code, so I didn't show it.
Comment out your event handler except for the quit event. Does the paddle then show up?
The paddle does not show up
If not, it's either a problem with User.yPos not being initialized or a problem with the userPaddle surface.
User.yPos is initialized as "User.yPos = 190.f;" in Game's constructor. The surface is fine too. How do i know? It was working before and i havent messed with the surface at all. Plus, i checked everything about the surface :p.
If you haven't already, you should also implement the proper collision detection for the boundary in your event handler: