//// Q1.java -- CST 112 Quiz #1 //// +++ Change this comment to show YOUR NAME +++ //// +++ modify any of this code as needed! //// Please remove all "+++" instructions, before submitting this code! //////// GLOBAL DECLARATIONS //////// float horizon; float flagX=width/2,flagY=20; float targetX, targetY; // Coordinates of the bullseye. float dartX, dartY, dartDX, dartDY; // Coordinates & velocity for dart. int score=0; // +++ Add more declarations here, if needed. //////// SETUP //////// void setup() { size(800, 600); reset(); } void reset() { horizon= height / 4; targetX= width-120; targetY= random( horizon, height-100 ); dartDX=dartDY=0; dartX= 100; dartY= random( horizon, height-100 ); // +++ modify this code as needed! } //////// NEXT FRAME //////// void draw() { scene(); action(); messages(); } //////// Draw the scene //////// void scene() { background( 255, 255, 0 ); // +++ change color to sky-blue! // +++ Add your code below, to draw the scene: grass, etc. fill( 255,0,255 ); rect( 0,horizon, width,height*3/4 ); // grass // +++ Modify the above code as necessary. fill(255); rect( width/2,20, 120,90 ); // flag // +++ Replace the above with your code to draw a tri-color flag! fill(255,0,0); ellipse( targetX,targetY, 200,200 ); // flag // +++ Replace the above with your code to draw a bullseye! } //////// ACTION: //////// * Move the dart (until it stops), update score, etc. //////// * Draw everything on the screen void action() { // +++ Add your code below, to move the objects and draw them. // Move the dart dartX = dartX + dartDX; // Check if dart has reached target. if (dartX >= targetX) { dartX=0; // STOP the dart // +++ Add your code here, to update the score, etc. } // Draw the dart, target, etc. // +++ Add your code here to draw the dart, target, etc. fill( 0, 200, 0 ); triangle( dartX-20,dartY, dartX-40,dartY-20, dartX-40,dartY+20 ); ellipse( dartX,dartY, 80,20 ); fill(0); triangle( dartX+35,dartY-3, dartX+35,dartY+3, dartX+60,dartY ); } //////// 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( "+++ Replace this string with YOUR NAME +++", 10, height-10 ); // +++ Add your code, to display score on the screen. } //////// EVENT HANDLERS: keys & mouse //////// void keyPressed() { if (key == 'q') { exit(); } if (key == 'r') { reset(); } if (key == 'd') { // +++ add your code here, to handle this key! } // +++ Add your code below, to handle other keys. } void mousePressed() { // +++ Add your code to handle mouse clicks if (mouseY= horizon) { // +++ Add your code here, to handle mouse click below horizon. } }