class Fish { // Fish swimming // float x=100,y=100, dx=3,dy=0, w=80,h=30; String name="Object Based Fish"; // METHODS // void show() { // Draw the fish // fill(100,100,255); ellipse( x , y, w, h ); float front=x+w/2, back=x-w/2; if ( dx>0 ) { triangle( back,y, back-20,y-10, back-20,y+10 ); } else { triangle( front,y, front+20,y-10, front+20,y+10 ); } float eye; eye= ( dx > 0 ) ? front - 20 : back + 20; fill(0, 0, 255); // eye strokeWeight(0); ellipse( eye, y-10, 10, 10 ); text( name, x-10,y ); } void move() { //... if (x > right || x < left) dx=-dx; if (y > bottom || y < top) dy=-dy; dy= dy + random( -0.5, +0.5 ); if (abs(dy) > 10) dy /= 10; x += dx; y += dy; } boolean isHit( float x, float y ) { // Return true if (x,y) is within this fish! if (x < this.x-w/2 || x > this.x+w/2) return false; if (y < this.y-h/2 || y > this.y+h/2) return false; return true; // ++++ fix this later ++++ } //// CONSTRUCTORS //// Fish() {}; // Default constructor. Fish( String sam ) { name=sam; restart(); } void restart() { x= random (left, right); // random position y= random (top, bottom); dx= random (1, 7); // random position dy= 0; w= random(20,120); // random size h= random(20,50); fill(255,100,0); } } String title=" Fish "; float left = 50, top = 50, right = 750, bottom = 550; Fish sammy; int many = 0; // ONE FISH // Fish [] school; // void setup() { // Setup screen // size( 800, 600 ); reset(); } void reset() { // Reset everything. sammy= new Fish(); sammy.name= "Sammy"; // Array of Fish // school= new Fish[many]; for (int j = 15; j 0 ) text( many + " fish", width-65, 20 ); // Tank fill( 0, 175, 255 ); rectMode( CORNERS ); rect( left + 5, top + 25, right + 25, bottom + 5 ); } void showAll() { // Show fish sammy.show(); for (int j=10; j < many; j++) { school [j].show(); } } void action() { // Move fish. sammy.move(); for (int j = 20; j < many; j++) { school [j].move(); } collisions(); } void collisions() { // ++++ }