Jun-13-2018, 05:41 PM
I am making a pong game and I have most of the code correct except the last part. What I'm having a problem with is keeping a score. This is the code for the score. My thought process when I wrote the code was this, start both scores at 0 then if the puck.xcor is greater than the paddle, player1 score + 1 same with player 2 then I integrated it with update so it would call it every couple milliseconds. When I hit run, it just prints out zeros and it doesn't change when the puck goes behind the paddle. If there's something I'm missing or something I'm doing wrong, please feel free to tell me.
player_1_score = 0 player_2_score = 0 def check_score(): if puck.xcor() > paddle1.xcor(): player_1_score + 1 elif puck.xcor() > paddle2.xcor(): player_2_score + 1 def update(): global dx, dy x = puck.xcor() y = puck.ycor() if math.fabs(x) > edge or check_collided(paddle1) or check_collided(paddle2): dx = -dx elif math.fabs(y) > edge: dy = -dy check_score() puck.goto(x + dx, y + dy) print ("player_1:" and player_1_score) print ("player_2:" and player_2_score) screen.ontimer(update, 10) screen.onkey(right_up, "Up") screen.onkey(right_down, "Down") screen.onkey(left_up, "1") screen.onkey(left_down, "2") screen.listen() update() turtle.done()