Robin T writes (excerpted):
I am currently at chapter 14, i already made my first game called "Bounce". When the game is over, i want the user to push a button or a mouse click to restart the game. But i don't know how to do this.
Someone else asked a similar question a few years ago, so here's my post from back then, with some ideas about adding a restart button: "Restarting the game". In terms of creating a function to restart the game, you might want to use the canvas coords
function to move the ball and paddle back to their starting position, and then set the values of all the other variables to the same as they started as well (for example, setting the hit_bottom
variable to False
; if you've added a score, setting the score back to zero; and so on). coords
takes 5 parameters: the id of the object to move, the x and y position and the width and height of the object. So moving both objects back to their starting position might look something like this:
self.canvas.coords(self.paddle.id, 200, 300, 300, 310)
self.canvas.coords(self.ball.id, 245, 100, 260, 115)
Hopefully that helps.