//// Q0.java -- CST 112 Quiz #1 //// William Wagner //////// GLOBAL DECLARATIONS //////// String help= "click below horizon to set the dart\n" + "click flag (or 'd' key) to throw.\n" + "r resets dart & target, q to quit."; float horizon; float flagX, flagY; // Coordinates of flag float targetX, targetY; // Coordinates of the bullseye. float dartX, dartY, dartDX, dartDY; // Coordinates & velocity for dart. float score = abs(dartY-targetY); int value=0; //////// SETUP //////// void setup() { size(800,600); flagX=width/2; flagY=20; reset(); } void reset() { horizon= height / 4; targetX= width-120; targetY= random( horizon, height-100 ); dartDX=dartDY=0; dartX= 100; dartY= random( horizon, height-100 ); //+++REMOVE+++// Modify any of this code as needed! //+++REMOVE+++// //+++REMOVE+++// Add more declarations here, as needed. //+++REMOVE+++// } //////// NEXT FRAME //////// void draw() { scene(); action(); messages(); } //////// Draw the scene //////// void scene() { //+++REMOVE+++// Modify this code to draw the scene: grass, etc. //+++REMOVE+++// background( 93, 199, 255 ); // Background should be sky-blue! fill( 11,180,0 ); // Grass should be green rect( 0,horizon, width,height*3/4 ); // Flag // fill(255); rect(flagX,flagY, 120,90); fill(255,0,0); rect(flagX,flagY,40,90); fill(0,255,0); rect(flagX+40,flagY,40,90); fill(0,0,250); rect(flagX+80,flagY,40,90); // Target // fill(255); ellipse(targetX,targetY, 200,200); fill(255,0,0); ellipse(targetX,targetY, 150,150); fill(255); ellipse(targetX,targetY, 100,100); fill (255,0,0); ellipse(targetX,targetY, 50,50); } //////// ACTION: //////// * Move the dart (until it stops), update score, etc. //////// * Draw everything on the screen void drawdart() { dartY = mouseY; fill(0); triangle(dartX-40,dartY-20,dartX-20,dartY,dartX-40,dartY+20); strokeWeight(4); line(dartX-10,dartY,dartX+75,dartY); strokeWeight(1); fill(200,200,0); ellipse(dartX,dartY,80,20); fill(0); ellipse(dartX,dartY,60,20); fill(200,200,0); ellipse(dartX,dartY,30,20); fill(0); } void throwdart() { void action() { // Move the dart dartX = dartX + 2; // STOP the dart when reaches target. if (dartX >= targetX) { dartX=0; //+++REMOVE+++// Add your code here, to update score, etc. //+++REMOVE+++// } } //////// MESSAGES: title, author, score, etc. //////// void messages() { fill(0); textSize(24); text( "CST 112 Quiz #1", 10, 20 ); text( "SCORE:", width*3/4,20 ); textSize(12); text( help, 20,50 ); text( "William Wagner", 10, height-10 ); //+++REMOVE+++// Add your code, to display score on the screen. //+++REMOVE+++// } //////// EVENT HANDLERS: keys & mouse //////// void keyPressed() { if (key == 'q') { exit(); } if (key == 'r') { reset(); } if (key == 'd') { action(); } //+++REMOVE+++// Add your code here, to handle the 'd' key! //+++REMOVE+++// } //+++REMOVE+++// Add your code here to handle the 't' key! //+++REMOVE+++// void mousePressed() { if (mouseX>= flagX && mouseX<=flagX+120 && mouseY >=flagY && mouseY<=flagY+90 && mousePressed == true); {drawdart(); } } //+++REMOVE+++// Add your code to handle clicks below the horizon! //+++REMOVE+++//