We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello there, I have a problem for my Pong game : I have the draw() loop which contains short methods call. Two paddle objects and a ball object. I can't recuperate the position (x;y) of my ball object to tell it to bounce on the paddle or mark a point . The two paddle are actually coded the same way My question is :
How to objects can communicate between them to get the coordinates : ( incX and incY which determinate the position of the ball in the window.) The idea is to put
The code is right down :
````'''`void draw(){ //Extras pour la ligne du milieu et la couleur de fond; background(0); strokeWeight(2); stroke(255); line(0, 200, 400, 200); // ballePong(); raquette_bas(); raquette_haut(); }
void raquette_haut(){ //Raquette du balle_haut pushMatrix(); translate(r2x, 0); rect(170,10,60,13); fill(#F5310F); popMatrix(); if(a == true && r2x>=-168){r2x -= 2;} else if(r == true && r2x<=168){r2x += 2; } else {r2x +=0;} }
void raquette_bas(){ pushMatrix(); translate(r1x, 0); noStroke(); rect(170, 375, 60, 13); fill(#1BDBD9); popMatrix(); if(left==true && r1x>=-168){r1x -= 2;} else if(right==true && r1x<=168){r1x += 2;} else {r1x +=0;} }
void ballePong(){ pushMatrix(); translate(incX, incY); ellipse(200,200,10,10); popMatrix();
//bounce right if(incX >= 195){Direction=PI-Direction;} //bouce left if(incX <= -195){Direction=PI-Direction;}
//bounce down if(incY >= 195){Direction=-Direction;} //bounce up if(incY <= -195){Direction=-Direction;} }````'''```
Its a part of my source code. I want ballePong() to know r1x and r2x which are the abcisses of my paddles...
Thanks again
Answers
by the way i dont remember the manner to put in IDE-like code
Edit your post
Select entire code with mouse
Empty line before and after the code
Then hit ctrl-o