// Kweku Cush //Cush //Instaniate Fruits// Cush[] mix; int many=3; Cush apple, orange, melon; int speed=30; float x1,x2,y1,y2; int score=0; String bounce; boolean pause=false; //toggle switch void setup(){ // size of the output screen size(500, 700); //creates the fruits apple= new Cush(); orange= new Cush(); melon= new Cush(); initialize(); frameRate( speed ); } void initialize() { mix = new Cush[many]; for (int k=0; k 430) { Dx= -Dx; x= x + Dx; bounce=""; } if (y < 60) { Dy= -Dy; y= y + Dy; bounce=""; } if (y > 590) { Dy= -Dy; y= y + Dy; bounce=""; } //// Check for collisions. check( apple, orange ); check( apple, melon ); check( orange, melon ); if (hit( apple, orange)) { apple.randomize(); score -= 10; bounce="apple"; } if (hit( apple, melon)) { melon.randomize(); score -= 10; bounce="melon"; } if (hit( orange, melon)) { orange.randomize(); score -= 10; bounce="orange"; } } boolean hit( Cush k, Cush c ) { //// Return true if p hits q return dist( k.x,k.y, c.x,c.y) < 20 ; } void check( Cush k, Cush c) { //// Check for collisions, then moves and indicates fruit if (dist( k.x,k.y, c.x,c.y) < 20) { score -= 10; k.show(); c.show(); fill(0); text( "HHHIIITTT !", k.x, k.y-50 ); bounce= "(" +int(k.x)+ "," +int(k.y)+ " ) HIT (" +int(c.x)+ "," +int(c.y)+ " )"; } } void show() { //// The specifications for the fruits. noStroke(); fill(101, 222, 4); ellipse(melon.x, melon.y, 60, 60); line(melon.x-30,melon.y,melon.x-30,200); fill(222, 37, 4); ellipse(apple.x, apple.y, 40, 40); line(apple.x-30,apple.y,apple.x-30,200); fill(222, 124, 4); ellipse(orange.x, orange.y, 20, 20); line(orange.x-30,orange.y,orange.x-10,200); } void randomize() { //// Set random values for x, y, Dx, Dy. x= random(65,430); y= random(60,590); Dx= 1 + random(3); Dy= 1 + random(3); } void speed() { Dx *= 1.1; Dy += 1.1; } void slow() { Dx *= .9; Dy += .9; } } //// void keyPressed() { // //Quits the game if (key=='Q') { exit(); if (key == 'P') { pause= ! pause; fill(20,132,222); text( "P A U S E D", 200, 200 ); text( "(press 'Captial P' to continue)", 200, 300 ); } else { show(); action(); scene(); initialize(); } } //restarts game if (key=='R') { initialize(); } if (key=='S') { speed++; } if (key=='s') { if (speed>0) speed--; } // if (key=='+') { many++; initialize(); } if (key=='-') { many--; many= many<1 ? 1 : many; initialize(); } if (key=='0') { many=0; initialize(); } if (key=='1') { many=0; initialize(); } }