Modify a text file: $/p-modularize.pde
$/p-modularize.pde
// bam - modularize: Zoog, 3 birds, enemy. float birdX=0, birdY=0; void setup() { size(300,400); rectMode(CORNERS); ellipseMode(CORNERS); //-- frameRate(5); } void draw() { // Draw everything. background(255); text( "Click mouse to make birds fly -- then try to avoid them!", 10,10 ); float x= mouseX; float y= mouseY; drawZoog(x,y); // Birds fly diagonally down. if (birdX < 400) { birdX +=2; birdY +=1; // Fly diagonally down. drawBirds(5, birdX, birdY); } // Check if bird hits Zoog. if ( isOver(x,y, birdX,birdY) ) { text( "OUCH!", 100, 100 ); } } void mousePressed() { // Create 5 birds. birdX= mouseX-100; birdY=mouseY-100; } void drawZoog( float x, float y) { // Square and circle. fill(0,255,0); rect( x, y, x+100, y+100); fill(255,0,0); ellipse( x+30, y-5, x+65, y-25 ); } void drawBirds( int howMany, float x, float y) { // STUB - birds // text( "bird stub was called ", 10, 10); int n; for( n=0; n < howMany; n++) { bird(x,y); x += 20; y += 10; } /* bird(x,y); bird(x+50,y+50); bird(x+100,y+100); */ } void bird(float x, float y) { // Draw one bird. fill(127,127,255); triangle(x,y, x+30,y, x,y+10); } boolean isOver( float x, float y, float bx, float by) { // Return true if bx,by is over x,y. boolean q; q= (abs(x-bx)<100) && (abs(y-by)<100); return q; }