Public Group

# Advice on Pong for Beginner

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

## Recommended Posts

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.

Btw, how do I post some codes?

##### Share on other sites

"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.

##### Share on other sites

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.

Edited by BagelBytes

##### Share on other sites

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?

Edited by DevilMoo

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013306
×