Pong v. 1.0 – Pygame example

Spread the love

Pong game has been updated to v. 1.0 with the players to be controlled via keyboard and mouse.

Go here to see the previous post with this code from skratch.

The code is here:

The changes

The changes are in the fact that now the player one is controlled by the mouse

Mouse coordinates

We get the coordinates of the mouse here:

This is in the while loop.

Then we send the coordinates to the sprite1 function that draws the bar on the screen. We just need the y coordinate, as the bar need to go up and down.

So, in sprite1 function, now, we just have to pass y and x1 is a global value that stays fixed.

Set the mouse invisible

To hide the mouse, before the while loop, we put this line of code

The video of the mouse controlled bar code

In this video I am trying to add the movement of the mouse to the game, having some issues to make the ball to restart when it went out of the right part of the screen. At the end the only problem is to make the ball bouce in a more interesting way, otherwise the ball is just bouncing in the same clockwise path.

Arkanoid ???

In the following code (with a video of the output) I made some changes to the code to transform pong into arkanoid. There is still the clockwise path that need to be fixed, in the next post.

 

Pygame's Platform Game

Other Pygame's posts