class food{ int initialTime; PVector myPos; int mySize; int myLiveSpan; //gridStart, gridSpacing, gridColumns, gridRows food(int _s, int _l){ initialTime = millis(); mySize = _s; myLiveSpan = _l; myPos = new PVector(gridStart+gridSpacing*int(random(gridColumns)), gridStart+gridSpacing*int(random(gridRows))); } void update(){ checkIfImAlive(); drawMe(); } void checkIfImAlive(){ if(millis()-initialTime > myLiveSpan){ //kill myself: foodArray.remove(this); } } void drawMe(){ rect(myPos.x,myPos.y,mySize,mySize); } PVector getPosition(){ return myPos; } }