• Popular Now

• 13
• 18
• 19
• 27
• 10

Archived

This topic is now archived and is closed to further replies.

This topic is 5743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have been making a lot of progress lately with my Pong clone, but I have hit a brick wall. The game is certainly playable, completely with CD playback and a menu system. I am still adding more features, but they will be merely aesthetic and the actual game is annoying in its current state. Every so often, the paddle jumps down to the bottom of the screen. It appears to be entirely random. I originally thought it had something to do with a large increase from GetTickCount() between two frames, but I added a little protection (if(time/10 < 10), update the paddle''s position) and it still jumps down to the bottom. I guess the best way is to see it in action: Pong Since I now have no idea what is causing this problem, here is the input code for you to look at:

// User paddle movement

if (g_keys->keyDown [VK_UP] == TRUE)
//if (GetAsyncKeyState(VK_UP))

{
if(paddleA > (20 + (pLength/2)))
{
if((time/10) < 10)
{
}
if((paddleA - (pLength/2)) < 20)
paddleA = 20 + (pLength/2);
}
}
if (g_keys->keyDown [VK_DOWN] == TRUE)
//if (GetAsyncKeyState(VK_DOWN))

{
if((paddleA + (pLength/2)) < HEIGHT)
{
if((time/10) < 10)
{
}
if((paddleA + (pLength/2)) > HEIGHT)
paddleA = HEIGHT - (pLength/2);
}
}

If you need more code, just ask. Any help would be greatly appreciated.

Share on other sites
I skimmed trough the other thread, and didn''t see anyone pointing it out, but the paddle is going down the bottom almost everytime the ball hits the bottom. Without more of the code, and its context, it''s hard to tell whats up. Is the paddleA var only modified these four times you showed us (excluding initialization though), or is the position depending on any other vars?

Btw, shouldn''t it be:
if((paddleA + (pLength/2)) >= HEIGHT)                paddleA = HEIGHT - (pLength/2);

That is, greater or equal to HEIGHT, rather than just greater?

Share on other sites
It shouldn''t matter either way. If (paddleA + (pLength/2) = HEIGHT), then setting paddleA = HEIGHT - (pLength/2) would not change a thing. I only want to manually change the paddle''s position if it is below the screen, not touching the bottom.

And CWizard, you are my hero! You noticed that paddleA jumped down everytime the ball hit the bottom. Well, that was almost correct. I searched for ''paddleA'' in the code and realized that I was placing paddleA at the bottom of the screen everytime that paddleB (the computer paddle) went below the screen. You see, I just copied the paddleA movement code and changed all the paddleA''s into paddleB''s, and replaced the input if statement with a ball tracking if statement (if ballY > paddleB, etc). I guess I just forgot to change the one paddleA.

Thanks for catching that for me. If you wouldn''t have made that observation, I probably wouldn''t have looked at the computer paddle code, since it always looked like it was working fine.

Did you notice any other problems?

Share on other sites
Good to hear, hope that solves your paddle problem. I suspected that it was something similar, and nothing with the key logic, as it jumped even when you didn''t do anything, and the code you showed seemed to do its job.

As for other problems, I can''t see any obvious. Sometimes the ball get cought between the corner and paddle, but will soon get out in the free . Overall I would say it works good, when the paddle problem is history, and is entertaining; you never can get enough pong, can you ?

Keep the good work going.