Hey guys help me on collision detection
in
Programming Questions
•
3 months ago
hey guys in this code i want to make a bouncing ball but the ball is not bouncing...........so tell me whats wrong with it
- float xPos = width/2;
- float yPos = height/2;
- int xDirection = 1;
- int yDirection = 1;
- float xSpeed = 2.2;
- float ySpeed = 1.8;
- int ballRed = 60;
- float pRect;
- void setup(){
- size(600,300);
- smooth();
- frameRate(60);
- //noCursor();
- }
- void draw(){
- noStroke();
- fill(#64F7E2);
- rect(0,0,width/2,height);
- fill(#4DB2A3);
- rect(width/2,0,width/2,height);
- fill(#4DB2A3);
- pRect = getPRect();
- rect(20,pRect,10,40);
- ellipseMode(RADIUS);
- updateBall();
- fill(0);
- ellipse(xPos,yPos,ballRed,ballRed);
- }
- float getPRect(){
- if(mouseY<=height-38){
- return mouseY;
- }
- else
- return height-38;
- }
- void updateBall(){
- xPos += xSpeed*xDirection;
- yPos += ySpeed*yDirection;
- if(xPos>width-ballRed || xPos<ballRed){
- xDirection *= -1;
- }
- if(yPos>height-ballRed || yPos<ballRed){
- yDirection *= -1;
- }
- }
1