Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. def setup():
  2.     size(400,400)
  3.     background(0)
  4.     frameRate(10)
  5. #variables pour la balle A
  6. xA=200
  7. dxA=5
  8. yA=200
  9. dyA=10
  10.  
  11. #variables pour la balle B
  12. xB=100
  13. dxB=-5
  14. yB=100
  15. dyB=-12
  16.  
  17. def distance(xA,xB,yA,yB):
  18.     d=sqrt((xB-xA)**2+(yB-yA)**2)
  19.     return d
  20.  
  21. def draw():
  22.     print(distance(xA,xB,yA,yB))
  23.    
  24.     #detection de la collision
  25.     if distance(xA,xB,yA,yB)<50:
  26.         print("COLLISION DETECTEE !!!!!!!!!!!!!")
  27.         #mettre ici les instructions pour le rebond des 2 balles
  28.    
  29.     global xA,dxA,yA,dyA
  30.     global xB,dxB,yB,dyB
  31.     background(0)
  32.    
  33.     #dessin de la balle A (bleue)
  34.     fill(0,0,255)
  35.     ellipse(xA,yA,50,50)
  36.     xA=xA+dxA
  37.     yA=yA+dyA
  38.     if xA>375 or xA<25:
  39.         dxA=-dxA
  40.     if yA>375 or yA<25:
  41.         dyA=-dyA
  42.        
  43.     #dessin de la balle B (rouge)
  44.     fill(255,0,0)
  45.     ellipse(xB,yB,50,50)
  46.     xB=xB+dxB
  47.     yB=yB+dyB
  48.     if xB>375 or xB<25:
  49.         dxB=-dxB
  50.     if yB>375 or yB<25:
  51.         dyB=-dyB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement