Advice on Pong for Beginner

Started by
3 comments, last by DevilMoo 8 years, 2 months ago

Hi, I am trying to build the Pong game for 1 player using Python after reading an article here.

I found that it is difficult to make a balance on the ball speed and the speed of the object controlled by player.

In my game, players can't win the game because the Com always hit the ball.

Do you have any advice?

Btw, how do I post some codes?

Advertisement

"Com" ?

I guess that means computer?

If so, you can make it fail more often by slowing down the speed of the bat, or adding a random offset to it, bigger than 1/2 the size of the bat (assuming it now aims for the center?).

Once you added it's amatter of tuning those parameters :)

You post code by copy/paste it in here, then select it all, and hit "code" tag, the "<>" symbol on the bar.

Make the AI paddle follow the balls Y position except only allow updating of the AI paddle AFTER the ball has crossed over the center median into the AI's territory. This adds more realism along with also making it much easier to beat.

Example:


if(ball.x >= screenWidth / 2)
{
    if(ai.y < ball.y)
    {
        ai.y += ai.speed;
    }
    else
    {
        ai.y -= ai.speed;
    }
}

Also, I would try to incorporate changing of the balls trajectory based on where it impacts on the paddle so that the player can try to out smart the AI rather than a fixed set of patterns that the ball will follow. E.g. if the ball hits close to the center of the paddle, it should bounce off at close to a +/- a few 0 degree angle, but closer to each extreme of the paddle, it should bounce off at a more harsh angle.

Have you tried keeping the paddle speed fixed, but increasing the velocity of the ball over time?

Good, I will try this after the game is smooth.

I would like to send the game to my friends but they do not install python. Can they still play it?

This topic is closed to new replies.

Advertisement