class Fish { // Fishes swim float x=200,y=200, dx=5, dy=.30, w=80,h=30; int r= 100,g=8,b=90; // Color String name=""; // METHODS // void show() { // Draw the fishes. fill(r,g,b); 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 ); // Tail fill(155); // eye strokeWeight(2); ellipse( front-15, y-10, 10, 10 ); }else { triangle( front,y, front+20,y-10, front+20,y+10 ); // Tail fill(155); // eye strokeWeight(2); ellipse(back+15, y-10, 10, 10 ); } } void move() { //move the fishes if (x>right) dx= -dx; if (xtop) dy= -dy; if (y x+w/2) return false; if (y < y-h/2 || y > y+h/2) return false; return true; // Hit detected. } }//END class Fish // "Button" class class Button { } // Button int count= 0; float ddx= 0; // GLOBALS: String title="Fish project"; String news="r to reset; e to exit"; float left=50, top=50, right=550, bottom=350; Button b1; // Fish charlie; // Declare the object // Fish sarah; // Declare another object // // void setup() { // Setup screen; instantiate object(s). size( 600, 400 ); reset(); } void reset() { // Reset everything. // charlie= new Fish( "Charlie" ); // charlie.name= "Charlie"; // Instatiate it. // sarah= new Fish( "Sarah" ); // sarah.name= "Sarah"; // Instatiate it. // sarah.r= 250; sarah.g= 200; sarah.y= 150; // b1= new Button(); } // void draw() { // Next frame scene(); // background, tank, etc. showAll(); // Draw the fish, buttons, etc. action(); // Move fish, check collisions, etc. } void showAll() { // Show fish, buttons, etc. charlie.show(); sarah.show(); // b1.show(); } void action() { // Move fish. charlie.move(); sarah.move(); } void scene() { // Tank background( 55, 255, 55 ); } // EVENT HANDLERS void keyPressed() { //// Handle keys. if (key == 'e') exit(); if (key == 'r') reset(); }