Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

ArrayList<circleObject> objectList = new ArrayList<circleObject>();
void setup()
{
  size(600, 800);
  objectList.add(new circleObject(mouseX, mouseY, 20));
  objectList.add(new circleObject(width/2, height/2, 40));
}
void draw()
{
  background(255);
  objectList.get(0).update(mouseX, mouseY);
  for(int i = 0; i<objectList.size(); i++) {
    objectList.get(i).draw(); 
  }
  
   objectList.get(0).checkCollision(objectList.get(1)._position, objectList.get(1)._radius);
}
class circleObject {
  PVector _position = new PVector();
  int _radius;
  int colour = 250;
  public circleObject(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;
    }
  }
}