////  Q1.java -- CST 112 Quiz #1
////  Franklin Abreu

////  +++ 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=3;
// +++ 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=2;
  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(145,200,255);
  // +++ Add your code below, to draw the scene:  grass, etc.
  
  fill( 0,255, 0);
  rect( 0,horizon, width,height*3/4);   // grass 
  // +++ Modify the above code as necessary.

  fill(255);
  rect( width/2,20, 120,90 ); // flag
  fill(255,0,0);
  rect( width/2,20,35,90);
  fill(0,0,255);
 
  // +++ Replace the above with your code to draw a tri-color flag!
  
  fill(255,0,0);
  ellipse( targetX,targetY, 200,200 ); 
  fill(255);
  ellipse( targetX,targetY, 150,150);
  fill(255, 0, 0);
  ellipse( targetX,targetY, 90,90);
  fill(255);
  ellipse( targetX, targetY,45,45);

  
}


////////  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.
 
  
  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( "Franklin Abreu", 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 == 't') 

  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) { reset();
    // +++ Add your code here, to handle mouse clicks above horizon.
  }
  


}


/******
breu	
Q1			
1.2	114		55
runs;sized?	10	OK	10
flag	10	2-colors	8
bullseye	10	OK	10
dart-move,stop	10	no stop!	5
score	10	NO SCORE	2
clicks:dart,flag	10	NO CLICKS	2
keys:	10	NO KEYS	2
readability	10	(no comments)	7
extras		.	
tree	5	.	---
bird	5	.	---
rabbit(s)	5	.	---
******/

