Modify a text file: $/objects.pde
$/objects.pde
//// CST 112 practice: array of Button objects //// 7417:bam String title= "CST 112 practice: array of Button objects."; String news= "(...)"; String notes= "'=' key for statistics; +/-/1 to speedup/slowdown/restart"; String author= "Prof.BAM"; String[] names= { "Sleepy", "Sneezy", "Bashful", "Grumpy", "Dopey", "Doc", "Jumpy", "Dumpy", "Hither", "Yon" }; float top, bottom=400; float speedup=1; int numbuttons=6; Button[] buttons= new Button[numbuttons]; int left=0, shoot=1, right=2, go=3, reset=4, quit=5; int numvarmits=10; Varmit[] varmits= new Varmit[numvarmits]; int maxtargets=10, numtargets=10; Target[] targets= new Target[maxtargets]; /* Button left= new Button( "LEFT", 100, 430 ); Button shoot= new Button( "SHOOT", 200, 430 ); Button right= new Button( "RIGHT", 300, 430 ); Button go= new Button( "GO", 500, 430, 255,100,0 ); */ void setup() { size(640, 480); top=height/6; bottom=height*5/6; // buttons[0]= new Button( "LEFT", 100, 430 ); buttons[1]= new Button( "SHOOT", 200, 430 ); buttons[2]= new Button( "RIGHT", 300, 430 ); buttons[3]= new Button( "GO", 500, 430, 100,255,100 ); buttons[4]= new Button( "RESET", 20, 50, 255,100,0 ); buttons[5]= new Button( "QUIT", width-90, 50, 200,250,250 ); reset(); key= '='; // Targets. float xt=100, yt=25; for (int j=0; j
x+w) return false; if (yy < y || yy > y+h) return false; return true; } } class Varmit { float x=100, y=200, dx=2, dy=1; float w=50, h=25; float r,g,b; int legs=6; String name=""; //// CONSTRUCTOR(S) //// Varmit( String s ) { name= s; // x= random( 50, width-50 ); y= random( 100, height-100 ); w= random( 30, 90 ); h= random( 15, 40 ); legs= int( random(2,20) ); dx= random( 0.5, 3 ); dy= random( 0.5, 2 ); // r= random(100,250); g= random(50,150); b= random(0,100); } void move() { float margin= 10 + 10*speedup; if (x>width-margin || x
height-100-margin || y<100+margin) dy = -dy; y += dy*speedup; } void show() { fill( r,g,b ); ellipse( x, y, w, h ); // Head float headX= +20; if (dx<0) headX= -20; ellipse( x+headX, y-15, w/2, h/2 ); fill (255); ellipse( x+1.5*headX, y-20, 8, 8 ); fill (0,0,255); ellipse( x+1.7*headX, y-20, 4, 4 ); float xleg=5+x-w/2, legspace=w/legs; float walk= 3; if ((frameCount/30) % 2 == 0) { walk= -3; } // for (int j=0; j