//// PROJECT #4: Dog Race String author= "---joseph mendoza +++"; String title= " Dog ~Race"; //// +++ ADD YOUR OWN CODE TO MAKE BUTTONS WORK. //// +++ ADD YOUR OWN CODE TO show and move the objects. //// +++ Add buttons, dogs, and varmits: //// +++ 3rd button moves 3rd dog on 3rd track. //// +++ 4th button moves all dogs. //// +++ 2 varmits run back & forth between the tracks. //// +++ Make buttons, dog, and varmits different colors. //// +++ Add some animation to the dogs & varmits. Button b1, b2, b3; Dog d1, d2, d3; Varmit mickey, oswald; String name1= "Spike"; String name2= "Max"; String name3= "Nike"; float track1= 150, track2=250, track3=350; float start=100, finish=500, horizon=track1-50; float xNews=350, yNews=horizon+25; int winner=0; void setup() { size( 640, 480 ); init(); reset(); } void init() { //// Initialize the objects // b1 = new Button( "Spike", 10, 10 ); b2 = new Button( "Max", 10, 40 ); d1 = new Dog( "Spike", start, track1 ); d2 = new Dog( "Max", start, track2 ); } void reset() { d1.x= start; d2.x= start; } void draw() { scene(); showAll(); messages(); } void scene() { background( 200, 220, 255 ); // Blue sky fill( 200, 220, 200 ); // Green grass rect( 0, horizon, width, height-horizon ); // //// Draw the tracks; fill(0); text( "Track #1", start-60, track1 ); text( "Track #2", start-60, track2 ); text( "Track #3", start-60, track3 ); fill( 250, 200, 200 ); rect( start, track1, finish-start+100, 80 ); rect( start, track2, finish-start+100, 80 ); rect( start, track3, finish-start+100, 80 ); stroke( 255,0,0 ); strokeWeight( 8 ); line( finish+100,track1-10, finish+100,height-40 ); strokeWeight( 1 ); stroke(0); // // Show the buttons. // b1.show(); b2.show(); } void showAll() { d1.show(); d2.show(); } void messages() { textSize(30); text( title, width/3, 30 ); textSize(12); text( author, 10, height-5 ); // //// Check for WINNER. //// if (d1.x > finish) { winner=1; textSize(24); fill(d1.c); text( d1.name+ " won the race!", xNews, yNews ); } else if (d2.x > finish) { winner=2; textSize(24); fill(d2.c); text( d2.name+ " wins the race!", xNews, yNews ); } else { winner=0; fill(150); text( "(No winner, yet)", xNews, yNews ); } textSize(12); } //////// EVENTS /////// void keyPressed() { if (key == 'q') { exit(); } if (key == 'r') { reset(); } // // Space bar moves all dogs. // if (key == ' ') { moveAll(); } // // Cheat! // if (key == '1') { d1.x += random(99); } if (key == '2') { d2.x += random(99); } } void moveAll() { // +++ INSERT YOUR CODE to move ALL dogs. +++ } void mousePressed() { // +++ INSERT YOUR CODE to check ALL buttons // +++ and perform appropriate actions. } //////// OBJECTS /////// class Button { float x, y; float w=90, h=25; String name; color c=color(255); // // CONSTRUCTORS // Button() { }; Button( String name, float x, float y ) { this.name= name; this.x= x; this.y= y; } // METHODS // void show() { fill(c); rect( x, y, w, h ); // // +++ INSERT YOUR CODE to complete the button. +++ // } boolean clicked() { // +++ MODIFY OR INSERT YOUR CODE to return true if button was clicked. return hit( mouseX, mouseY ); } boolean hit( float xx, float yy) { // // +++ INSERT YOUR CODE to return true if button was hit. // return false; } }// class Button // class Dog { float x, y; String name; color c; // // CONSTRUCTORS // Dog() { }; Dog( String name, float x, float y ) { this.name= name; this.x= x; this.y= y; } // METHODS // void show() { fill(c); // // +++ INSERT YOUR CODE to draw (and animate) dog. +++ // text( name, x+10, y+20 ); } void move() { // Dog moves (a random amount) forward. // // +++ INSERT YOUR CODE to move this dog. +++ } }// class Dog // class Varmit { float x, y; color c=0; // METHODS // void show() { // +++ INSERT YOUR CODE to draw & animate the varmit. } void move() { // +++ INSERT YOUR CODE to move varmit (horizontally) } }// class Varmit //