//////// Exercise x2: modularize exercise x1, and add dog to chase hero. //////// Whoever Whoever (CST 112; today's date?) //////// Please change these to your name and today's date. String author= "Whoever Whatever"; String title= " ??? "; String help= " Click to relocate hero \n 'q' to quit; 'r' to reset. "; //// GLOBALS: coordinates, speed, etc. float horizon; float x, y; // Position. float dx, dy; // Speed. float dogX, dogY; float puppyX, puppyY; /// puppy //// SETUP: window size, initialization (start in middle of screen). void setup() { size( 640,480); horizon= height/4; x= width/2; y= height/2; dx= 3; dy= 2; } //// NEXT FRAME: scene, action, show. void draw() { scene(); hero(); dog(); messages(); puppy(); } //// SCENE: sky, sun, tree, house, etc. void scene() { /* INSERT YOUR CODE HERE! */ background( 200,255,255 ); fill(0); /* REPLACE THIS STUB! */ text( "scene", 100, 100 ); } void messages() { text( title, width/3, 20 ); text( help, width*2/3, 30 ); text( author, 10,height-20 ); } //// ACTION: move (x,y) coordinates of hero & dog; show them. void hero() { /* INSERT YOUR CODE HERE! */ fill(200,100,180); triangle(x,y,x,y-20,x+50,y); /* REPLACE THIS STUB! */ text( "[[[[ Zoog. ]]]]", 200, 200 ); fill(0,100,150); rect( x,y, 50,80); x = x + dx/2; y = y + dy/2; } void dog() { dogX= dogX - (dogX-x+100)/30; dogY= dogY - (dogY-y-40)/40; text( dogX, 10, 10 ); text( dogY, 10, 20 ); // fill( 140,90,0 ); rect(dogX,dogY, 60,30,0,10,0,12); ellipse(dogX,dogY,10,20); /////Ear fill(105,100,0); ellipse(dogX+60,dogY,10,10); /// Dog nose fill(0); ellipse(dogX+10, dogY+10,10,10); /// dog eye noStroke(); fill(200,255,255); ///// mouth color triangle(dogX+30,dogY+15,dogX+60,dogY+15,dogX+60,dogY+30); //// Dogs mouth /* INSERT YOUR CODE HERE! */ /* REPLACE THIS STUB! */ text( "woof, woof!d!!", 150, 150 ); } void puppy(){ puppyX= dogX - (dogX-x)/30; puppyY= dogY - (dogY-y)/40; fill(0); rect(puppyX/2,puppyY/2,40,20); //puppy } //////// HANDLERS: mouse clicks, keys void mousePressed() { x= mouseX; // Set (x,y) to mouse y= mouseY; // dx= random( -6, +6 ); // random speed. dy= random( -4, +4 ); } void keyPressed() { if (key == 'q') { exit(); // press 'q' qjkey to QUIT. } /* INSERT YOUR CODE HERE! */ }