Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # main game loop
- def move():
- global pong_dx, pong_dy, AIplayerspeed, seconds, score
- # move pong ball
- x, y = pong.position()
- x += pong_dx
- y += pong_dy
- pong.setposition(x, y)
- if isCollision(pong, player): # collision pong and player
- pong_dx *= -1
- # Update the score
- score += 10
- score_pen.undo()
- score_pen.write("Score: {}".format(score), align="left", font=FONT)
- elif isCollision(pong, AIplayer): # collision pong and AIplayer
- pong_dx *= -1
- elif y < -299.5 or y > 299.5: # check for bounce and redirect it
- pong_dy *= -1
- elif x > 300:
- pong_dx *= -1
- elif x < -300:
- print("Game Over")
- screen.bye()
- return
- # move AI paddle (might speed up pong movement)
- AIplayer.forward(AIplayerspeed)
- y = AIplayer.ycor()
- if y < -250 or y > 250:
- AIplayerspeed *= -1
- # display timer
- seconds += 0.05
- time_pen.undo()
- time_pen.write("Time: {}".format(int(seconds)), False, align="Left", font=FONT)
- screen.ontimer(move, 50)
- screen.update()
- screen.tracer(False)
- move()
- screen.mainloop()
Add Comment
Please, Sign In to add comment