Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
ArrayList<circleObject>ArrayList<Ball> objectListballList = new ArrayList<circleObject>ArrayList<Ball>();
void setup()
{
  size(600, 800);
  objectListballList.add(new circleObjectBall(mouseX, mouseY, 20));
  objectListballList.add(new circleObjectBall(width/2, height/2, 40));
}
void draw()
{
  background(255);
  objectListballList.get(0).update(mouseX, mouseY);
  for(int i = 0; i<objectListi<ballList.size(); i++) {
    objectListballList.get(i).draw(); 
  }
  
   objectListballList.get(0).checkCollision(objectListballList.get(1)._position, objectListballList.get(1)._radius);
}
class circleObjectBall {
  PVector _position = new PVector();
  int _radius;
  int colour = 250;
  public circleObjectBall(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 draw() {
    pushMatrix();
    fill(colour,0,0);
    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;
    }
  }
}

 

...