import java.util.*; import java.awt.*; public class RectangleTarget extends BApplet { ArrayList drops ; Rectangle targetRect; void setup() { size(200,200); targetRect = new Rectangle(50,100,20,20); drops = new ArrayList(); } void mousePressed(){ Drop newDrop = new Drop(mouseX,mouseY); drops.add(newDrop); } void loop() { background(127); fill(50); //draw the rect regular rect(targetRect.x, targetRect.y, 10,10); for (int i = drops.size()-1; i > -1; i--){ //go backwards through the list in class you have to delete one, //normally you would say for (int i =0; i< drops.size(); i++) to go forward throught an array Drop thisDrop = (Drop) drops.get(i); //it has amnesia when it comes out so you have to cast it as something thisDrop.moveIt(); thisDrop.drawIt(); if (thisDrop.isHitting(targetRect)){ //if it intersects the target, draw the target differently fill(200); rect(targetRect.x, targetRect.y, 10,10); } if (thisDrop.isTooLow(height)){ drops.remove(i); println("remove"); } } } class Drop { Point dropPos = new Point(); //will hold both x and y Drop(int _x, int _y){ dropPos.x = _x; dropPos.y = _y; } void moveIt(){ dropPos.y = dropPos.y + 1; } boolean isTooLow(int _limit){ return (dropPos.y > _limit); } boolean isHitting(Rectangle _targetRect){ return (_targetRect.contains(dropPos)); //finally we don't have to have that terrible if statement } void drawIt(){ fill(20); ellipse( dropPos.x, dropPos.y,5,5); } } }