Sign in to follow this  

Advice on Pong for Beginner

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

If you intended to correct an error in the post then please contact us.

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.

 

Do you have any advice?

 

Btw, how do I post some codes?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this