Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def setup():
- size(400,400)
- background(0)
- frameRate(10)
- #variables pour la balle A
- xA=200
- dxA=5
- yA=200
- dyA=10
- #variables pour la balle B
- xB=100
- dxB=-5
- yB=100
- dyB=-12
- def distance(xA,xB,yA,yB):
- d=sqrt((xB-xA)**2+(yB-yA)**2)
- return d
- def draw():
- print(distance(xA,xB,yA,yB))
- #detection de la collision
- if distance(xA,xB,yA,yB)<50:
- print("COLLISION DETECTEE !!!!!!!!!!!!!")
- #mettre ici les instructions pour le rebond des 2 balles
- global xA,dxA,yA,dyA
- global xB,dxB,yB,dyB
- background(0)
- #dessin de la balle A (bleue)
- fill(0,0,255)
- ellipse(xA,yA,50,50)
- xA=xA+dxA
- yA=yA+dyA
- if xA>375 or xA<25:
- dxA=-dxA
- if yA>375 or yA<25:
- dyA=-dyA
- #dessin de la balle B (rouge)
- fill(255,0,0)
- ellipse(xB,yB,50,50)
- xB=xB+dxB
- yB=yB+dyB
- if xB>375 or xB<25:
- dxB=-dxB
- if yB>375 or yB<25:
- dyB=-dyB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement