// Anthony E. Capiral // CST 112 Intro to Programming // Final "Dog Race" //// REALISTICALLY, ONE HOUR TO EFFECTIVELY CODE THIS IS NOT ENOUGH \\\\ // highly improbably for any student to be able to complete this code (final) \\ //// please refer to my work throughout the class, //// the TAKEHOME Midterm, and projects 5, 6, and 7 \\\\ // how many dogs in the race int howManyDogs = 6; // declare an array called Dogs, of dogs objects of class Dog Dog[] aec = new Dog[howManyDogs]; // init random dog colors of brown color colorOne = color(100 + random(150), 50 + random(50), random(50)); color colorTwo = color(100 + random(150), 50 + random(50), random(50)); color colorThree = color(100 + random(150), 50 + random(50), random(50)); color colorFour = color(100 + random(150), 50 + random(50), random(50)); color colorFive = color(100 + random(150), 50 + random(50), random(50)); color colorSix = color(100 + random(150), 50 + random(50), random(50)); // default game over boolean boolean gameOver = false; // informational text String title = "CST 112 Final Exam"; String projectName = "Dog Racer"; String author = "Anthony E. Capiral"; String date = "© 12.19.2012"; void setup() { smooth(); size(800, 650); setupDogs(); } void createBg() { fill(255); rectMode(CORNERS); rect(0, 0, width, height); } // set up the Dog objects using class constructors void setupDogs() { aec[0] = new Dog(100, "Spike", colorOne); aec[1] = new Dog(150, "Fido", colorTwo); aec[2] = new Dog(200, "Scruffy", colorThree); aec[3] = new Dog(250, "Snoopy", colorFour); aec[4] = new Dog(300, "Kujo", colorFive); aec[5] = new Dog(350, "Muffin", colorSix); resetDogs(); } // reset: place all dogs at x=50, with random sizes and shades of brown void resetDogs() { for (int i = 0; i < howManyDogs; i++) { aec[i].dogPosX = 50; // all dogs goto to x=50 // random body width of the dog float dWidth = random(50, 80); aec[i].dogWidth = dWidth; // random width of the head of the dog aec[i].dogHeight = dWidth/2 + random(10); // random shade of brown colored dog aec[i].dogColor = color(100 + random(150), 50 + random(50), random(50)); } // boolean, game is not over but has been reset gameOver = false; } // create the background, draw the dog objects on the screen void draw() { createBg(); for (int d = 0; d < howManyDogs; d++) { aec[d].show(); } } // key press handlers for moving the dogs and reseting void keyPressed() { // move dogs randomly foward with space key if (key == ' ') { for (int m = 0; m < howManyDogs; m++) { aec[m].move(); } } // reset dogs with 'r' if (key == 'r') { resetDogs(); } } // define the Dog class public class Dog { // local dog variables float dogWidth; // width of dog float dogHeight; // height of dog float dogPosX = 50; // the dogs x coordinate default, 50 float dogPosY; // the y coord of the dog float dogDX; // speed at which dog moves along the x coord String dogName; // name of the dog boolean aboutFace = false; // when facing to the right this is false, when left, true color dogColor; // color of the dog // dog constructors Dog (float ySet, String nameSet, color cSet) { dogPosY = ySet; dogName = nameSet; dogColor = cSet; } // method to draw the dog, using basic shapes void show() { noStroke(); rectMode(CORNERS); fill(dogColor); rect(dogPosX, dogPosY, dogWidth, dogHeight); } // method to move the dog void move() { dogDX = random(0, 10); dogPosX = dogPosX + dogDX; } // boolean, test to see if mouse is on dog /* boolean hit(float mx, float my) { mx = mouseX; my = mouseY; if ( (abs(dogPosX - mx) < 20) && (abs(dogPosY - my) < 20) ) { return true; } } */ } // end Dog class definition