Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
ArrayList<Ball> ballList = new ArrayList<Ball>();
Ball mouseBall;
void setup()
{
  size(600, 800);
  ballList.add(new Ball(mouseXwidth/2, mouseYheight/2, 2040));
  mouseBall = ballList.add(new Ball(width/2mouseX, height/2mouseY, 4020));
}
void draw()
{
  background(255);
  ballListmouseBall.get(0).update(mouseX, mouseY);

  for (int i = 0; i<ballList.size(); i++) {
    ballList.get(i).drawdrawBall();
   }
  
   ballList.get(0). mouseBall.checkCollision(ballList.get(1i)._position, ballList.get(1i)._radius);
  }
    mouseBall.drawBall();
}
class Ball {
  PVector _position = new PVector();
  int _radius;
  int colour = 250;
  public Ball(int x, int y, int r) {
    _position.set(x, y, 0);
    _radius = r;
  }
  void update(int x, int y) {
    _position.set(x, y, 0);
  }

    void drawdrawBall() {
    pushMatrix();
    fill(colour, 0, 0);
    noStroke();
    translate(_position.x, _position.y);
    ellipse(0, 0, _radius*2, _radius*2);
    popMatrix();
  }
 

  void checkCollision(PVector position, int radius) {
    float distance = PVector.dist(_position, position);
    if (distance <= radius +_radius) {
       println("hit");
 
      colour = 60;
    } else {
      colour = 255;
    }
  }
}