//objects fruit[] salad; //score float s = 0; //amount of balls int many = 7; void setup(){ initialize(); size(400,600); } void draw(){ if (keyPressed){ if (key == 'p'){ textSize(30); fill(0); table(); fill(0); text("PAUSE",width/2-50,25); } }else{ scene(); action(); } } void action(){ for (int i=0; i< many; i++) { salad[i].move(); salad[i].show(); } //draws fruit ///collisions. for (int j=0; j25;i=i-75){ line(25,i,width-25,i); } //xy location textSize(15); fill(0); text(""+salad[0].x,170,90); text(""+salad[0].y,170,110); text(""+salad[1].x,170,150); text(""+salad[1].y,170,170); text(""+salad[2].x,170,210); text(""+salad[2].y,170,230); text(""+salad[3].x,170,270); text(""+salad[3].y,170,290); text(""+salad[4].x,170,330); text(""+salad[4].y,170,350); text(""+salad[5].x,170,410); text(""+salad[5].y,170,430); text(""+salad[6].x,170,470); text(""+salad[6].y,170,490); ///text("ball "+j,salad[j].x,salad[j].y-25); ///text(j+5+"points!",salad[j].x,salad[j].y-50); //vertical line for(int j=25; j width-50-w/2){ dx *= -1; // s -= 1; } if (x < 50+w/2){ dx *= -1; // s -= 1; } if (y > height-50-w/2){ dy *= -1; // s -= 1; } if (y < 50+w/2){ dy *= -1; // s -= 1; } } void randomize() { //// Set random values for x, y, dx, dy. x= random(50+w/2,width-50-w/2); y= random(50+w/2,height-50-w/2); } void show(){ //draws fruit noStroke(); fill(fruitcolor); ellipse(x, y, w, w); } } ///booleans /// boolean mousehit( float x, float y, float w) { //// Return true if mouse within ellipse boolean result=true; float top= y - w/2, bottom=y+w/2, left=x-w/2, right=x+w/2; if (mouseX < left ) result= false; if (mouseX > right ) result= false; if (mouseY < top ) result= false; if (mouseY > bottom ) result= false; return result; } boolean fruithit( fruit a, fruit b ) { //check collision return dist(a.x, a.y, b.x, b.y) < a.w/2 + b.w/2; }