Loading...
Logo
Processing Forum
Hello, I'm new to processing but and I really don't understand why this isn't working. Any help will be much appreciated. Thanks

/*
*To do list*
1. Get paddle to work
*/

float ellipseRadius;

//ball start position
float ellipseX;
float ellipseY;

//ball speed
float ballSpeedx;
float ballSpeedy;


void setup(){
size(1280,720);
frameRate(30);

ellipseRadius = 50; //ball size

//ball start position
ellipseX = 50;
ellipseY = 50;

//ball speed
ballSpeedx = 10;
ballSpeedy = 10;
}

void draw(){
  background(0,123,167);
  ellipseMode(CENTER);
  fill(255,127,0);
  ellipse(ellipseX,ellipseY,ellipseRadius, ellipseRadius);
  
  ellipseX = ellipseX + ballSpeedx; //moves ball across x axis
  ellipseY = ellipseY + ballSpeedy; // moves ball down y axis
  
  if(ellipseX + ellipseRadius/2 > (width-47) && (mouseY - 13) && (mouseY + 13) || ellipseX - ellipseRadius/2 < 0){
    ballSpeedx = -ballSpeedx;
  }
  
  if(ellipseY + ellipseRadius/2 > height || ellipseY - ellipseRadius/2 < 0){
    ballSpeedy = -ballSpeedy;
  }
  
  fill(255,0,0);
  rectMode(CENTER);
  rect(width-30, mouseY, 26, 100);
}

Replies(4)

Operators && and || only accept boolean data-type as its operands.
Neither (mouseY - 13) nor (mouseY + 13) generate boolean values. Rather, int ones.
Not sure if I'm doing it right, but it's still not working.

Copy code
  1. /*
  2. *To do list*
  3. 1. Get paddle to work
  4. */

  5. boolean paddle = false;
  6. float ellipseRadius;

  7. //ball start position
  8. float ellipseX;
  9. float ellipseY;

  10. //ball speed
  11. float ballSpeed;
  12. float ballSpeedx;
  13. float ballSpeedy;


  14. void setup(){
  15. size(1280,720);
  16. frameRate(30);

  17. ellipseRadius = 50; //ball size

  18. //ball start position
  19. ellipseX = 50;
  20. ellipseY = 50;

  21. //ball speed
  22. ballSpeed = 50;
  23. ballSpeedx = ballSpeed;
  24. ballSpeedy = ballSpeed;
  25. }

  26. void draw(){
  27.   background(0,123,167);
  28.   ellipseMode(CENTER);
  29.   fill(255,127,0);
  30.   ellipse(ellipseX,ellipseY,ellipseRadius, ellipseRadius);
  31.   
  32.   ellipseX = ellipseX + ballSpeedx; //moves ball across x axis
  33.   ellipseY = ellipseY + ballSpeedy; // moves ball down y axis
  34.   
  35.   if(ellipseX + ellipseRadius/2 > (width-47) && (mouseY - 13) && (mouseY + 13)|| ellipseX - ellipseRadius/2 < 0){
  36.     paddle = true;
  37.   } else{
  38.     paddle = false;
  39.   }
  40.   
  41.   if(paddle){
  42.     ballSpeedx = -ballSpeedx;
  43.   }
  44.   
  45.   if(ellipseY + ellipseRadius/2 > height || ellipseY - ellipseRadius/2 < 0){
  46.     ballSpeedy = -ballSpeedy;
  47.   }
  48.   
  49.   fill(255,0,0);
  50.   rectMode(CENTER);
  51.   rect(width-30, mouseY, 26, 100);
  52. }
As said, you have to do a comparison on each term of the expression. You compare the position of the ball to the mouse coordinates, the bounds, etc. You have to repeat the variable names on each expression needing them.