In order to code the game Pong, in my main.py I have a value called game_is_on set to True,
As long as it's set, I have a refresh of the screen. When the ball touches one of the sides, I display some "Game over" text, turn game_is_on to False and alert the players to reset the game by pressing enter.
When they do, I want to set game_is_on back to True, but somehow can't reach it
#Before that I have a whole setup of my elements, when all is done I do
game_is_on = True
def game_reset():
game_is_on = True
print("we try to reset")
ball.restart()
score_B.restart()
field.screen.update()
while game_is_on:
while game_is_on:
field.screen.update()
ball.move()
if ball.ycor() < -390 or ball.ycor() > 390:
ball.hitwall()
if ball.distance(paddle_A) <= 20 or ball.distance(paddle_B) <= 20:
ball.hitpaddle()
if ball.xcor() < - 600 or ball.xcor() > 600:
if ball.xcor() < - 600:
score_B.increase()
else:
score_A.increase()
score_B.gameover()
game_is_on = False
field.screen.onkey(game_reset, "Return")
How can I set the game_is_on back to true in my game_reset() ?