0
votes

I'm writing a program using Processing but I keep getting Expecting TRIPLE_DOT, found ';'. What could be wrong?

class Collision {
  Ball ball = new Ball();
  Block block = new Block();
  int ball_xpos;
  int ball_rad;
  int ball_ypos;

  int block_width;
  int block_height;
  int block_control;

    Collision(ball.xpos, ball.rad, ball.ypos, block.width, block.height, block.control){
    //
  }


  void detect_() {
    //not done yet
  }
}

Ball class: class Ball { int rad = 30; // Width of the shape float xpos, ypos; // Starting position of shape

  float xspeed = 2.8;  // Speed of the shape
  float yspeed = 2.2;  // Speed of the shape

  int xdirection = 1;  // Left or Right
  int ydirection = 1;  // Top to Bottom

 Ball() {
     ellipseMode(RADIUS);
    // Set the starting position of the shape
    xpos = width/2;
    ypos = height/2;
  }


  void display() {
    ellipseMode(CENTER);
    ellipse(xpos, ypos, 410, 40);
  }

  void move() {
    // Update the position of the shape
    xpos = xpos + ( xspeed * xdirection );
    ypos = ypos + ( yspeed * ydirection );

    // Test to see if the shape exceeds the boundaries of the screen
    // If it does, reverse its direction by multiplying by -1
    if (xpos > width-rad || xpos < rad) {
      xdirection *= -1;
    }
    if (ypos > height-rad || ypos < rad) {
      ydirection *= -1;
    }

    // Draw the shape
    ellipse(xpos, ypos, rad, rad);
  }
}
1

1 Answers

2
votes

In the parameter names in your constructor, the dots (.) should be replaced with _. And you should give types to those parameters:

Collision(int ball_xpos, int ball_rad, ... so on){
    //
}

If you use ball.xpos, then compiler expects a var-args after the 1st dot(.) after ball.


But it seems like want to pass attributes of Ball class, to initialize the fields with the Ball class attribute. In that case, you should just pass a single parameter, that is a reference to Ball:

Collision(Ball ball) {
    this.ball = ball;
}

But I don't see why at all you are having those fields (ball_xpos, ball_ypos) in Collision class, given that you also have a Ball type field. You can remove them, and just set ball reference to the reference passed in the above constructor.

Same thing for Block type reference. You are simply having copy of the fields of Block and Ball in Collision class again. Not needed.