// name: Carlos Sosa // section: O // e-mail id: carlosso@andrew.cmu.edu // class Homework9 // A video game based on Homework 8 // User must click the moving figures. // Each figure is worth 1 to 4 points based on the color of the figure. // Player has 1 minute to score as many points as possible. // Global variables or fields go here final int MAX = 15; Figure [ ] figArr;// calls the Figure array int hitCount; int missCount; boolean index; // Methods go here. void setup( ) { size ( 400, 400); smooth ( ); hitCount=0; missCount=0; //News the array figArr= new Figure [MAX]; frameRate(10); for (int i = 0; i < figArr.length; i++) { figArr[i]= new Figure(random(width),random(height),random(25,.15*width),(int)random(1,5)); } } void draw( ) { background( 140, 234, 156 ); for (int i = 0; i < MAX; i++) { figArr[i].drawFigure( );// draws the figure figArr[i].move( );// moves the figure } displayScores( ); if (frameCount%100 == 0) { frameRate(frameRate+5); } if (frameCount >= 500) { noLoop(); background( 140, 234, 156 ); text("Final Score: " + (hitCount-missCount), .38*width, height/2); } } void displayScores( ) { text("Time", .45*width, height/15); text(500-frameCount,.46*width, height/8); text("Hits", width/15, height/15); text(hitCount,.085*width, height/8); text("Misses", width/30, .8*height); text(missCount, .085*width, .86*height); } void mousePressed() { index=false; int score=0; for(int i = 0; i < MAX; i++) { if (figArr[i].mouseOnFigure() == true) { index = true; score = figArr[i].getValue(); break; } } if (index == true) { hitCount += score; } else missCount++; }