////Object-Based Excercise: Fish Tank//// //instructions: construct a fish tank with various fish // that move from left to right, and up and down. // 1st step: make one fish that swims and bounces for now, // give it a name class Fish { // Fish gotta swim, birsds gotta fly ... float x=100,y=100, dx=5,dy=0, w=80,h=30; int r,g,b; // Color String name=""; // METHODS // void show() { // Draw the fish. fill(r,g,b); ellipse( x,y, w,h ); float front=x+w/2, back=x-w/2; triangle( back,y, back-20,y-10, back-20,y+10 ); // Tail fill(255); // eye strokeWeight(1); ellipse( front-15, y-10, 10, 10 ); } void move() { //... dy= dy + random( -1, +1 ); x += dx; y += dy; } boolean isHit( float x, float y ) { // Return true if (x,y) is within this fish! // +++++ STUB - we will code this later. +++++ return false; // ++++ fix this later ++++ } } float left=50, top=50, right=500, bottom=350; // Fish carlton; void setup() { size( 650, 400); reset(); } void reset() { // Reset everything. // // Instatiate it. // carlton= new Fish(); carlton.name= "Carlton"; // } void draw() { scene(); showAll(); action(); } void scene() { background ( 20, 20, 70); fill( 20, 80, 230 ); rectMode(CORNERS); rect(left, top, right, bottom); } void action() { // Move fish collisions(); } void collisions() { // ++++ } void showAll() { // Show fish, buttons, etc. // // }