//// Q0.java -- CST 112 Quiz #1 //// +++ Rahul Mathur //////// GLOBAL DECLARATIONS //////// String help= "To set the dart click below horizon" + ",click flag to throw the dart" + "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. int score=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 ); } //////// NEXT FRAME //////// void draw() { scene(); action(); messages(); } //////// Draw the scene //////// void scene() { background( 0, 0, 255 ); // Background should be sky-blue! fill( 0,255,0 ); // Grass should be green rect( 0,horizon, width,height*3/4 ); // Flag // fill(255,0,255); rect(flagX,flagY, 40,100); fill(0); rect(flagX+40,flagY, 40,100); fill(255,0,255); rect(flagX+80,flagY, 40,100); fill(255); text("Flag", flagX,flagY); // Target // fill(255,0,0); ellipse(targetX,targetY, 200,00); fill(255,0,0); text("Bullseye", targetX,targetY); fill(255,0,0); ellipse(targetX,targetY, 200,200); fill(255); ellipse(targetX,targetY, 150,150); fill(255,0,0); ellipse(targetX,targetY, 100,100); fill(255); ellipse(targetX,targetY, 50,50); } //////// ACTION: //////// * Move the dart (until it stops), update score, etc. //////// * Draw everything on the screen void action() { // Move the dart dartX = dartX + dartDX; // STOP the dart when reaches target. if (dartX >= targetX) { dartX=0; } // Draw the dart, etc. fill(5,10,255); ellipse( dartX,dartY, -80,20 ); fill(0); text( "DART", dartX, dartY ); } //////// MESSAGES: title, author, score, etc. //////// void messages() { fill(120); textSize(20); text( "CST 112 Quiz #1", 10, 20 ); text( "SCORE : 50", width*3/4,20 ); textSize(12); text( help, 20,50 ); text( "+++ Rahul Mathur +++", 10, height-10 ); } //////// EVENT HANDLERS: keys & mouse //////// void keyPressed() { if (key == 'q') { exit(); } if (key == 'r') { reset(); } if (key == 'd') { } } void mousePressed() { }