Advertisement
Privvet1

Pong Attempt

Mar 11th, 2022
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import simplegui
  2. import random
  3.  
  4. xForce = random.randint(-10, 10)
  5. yForce = random.randint(-10, 10)
  6. print(xForce, yForce)
  7.  
  8. py1 = 300
  9. py2 = 300
  10.  
  11. size = 40
  12.  
  13. bounce = True
  14.  
  15. colors = ["Red", "Yellow", "Blue", "Green", "Orange", "Purple", "Black"]
  16. color = random.choice(colors)
  17.  
  18. cx = 300
  19. cy = 300
  20. xSpeed = xForce
  21. ySpeed = yForce
  22.  
  23. def draw_handler(canvas):
  24.     global bounce
  25.     global color
  26.     global cx
  27.     global cy
  28.     global xSpeed
  29.     global ySpeed
  30.    
  31.    
  32.    
  33.     cx += xSpeed
  34.     cy += ySpeed
  35.    
  36.    
  37.    
  38.     canvas.draw_circle((cx, cy), 20, 5, color)
  39.     canvas.draw_line((50, py1 + size), (50, py1 - size), 10, "Black")
  40.     canvas.draw_line((550, py2 + size), (550, py2 - size), 10, "Black")
  41.  
  42.  
  43. frame = simplegui.create_frame('Testing', 600, 600)
  44. frame.set_canvas_background("White")
  45. frame.set_draw_handler(draw_handler)
  46. frame.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement