Modify a text file: $/z2.pde
$/z2.pde
//// CST 112 Project #2 / Marcos Quijano //// String author= "Marcos Quijano"; String title= "Rover Class"; float horizon; Dog rover; Hero Mark; Star sol; house home; void setup() { size(600, 400); fill( 150, 150, 150 ); horizon= height / 2.75; rover= new dog(); mark= new hero(); } class Star { // MEMBER DATA. // float x=0, y=50, dx=1, dy=0, // Position and speed; float w=30, h=30; // Width & Height of ellipse. color c = color(255,255,0); // Yellow. (Changes at night.) // METHODS // void show () { if (day) c = color(255,255,0); // Yellow sun; else c = color(200, 180,180); // Pale moon; ellipse ( x,y, w,h ); } void move () { if (x > width) { sunset(); // Night & Day; x= x + dx; y = y + dy; } void sunset () { day = 1 day; // Switch nite/day x = 0; // Reset to left } void draw() { background( 20 , 60, 170 ); // Sky /// Draw grass fill( 50, 160, 50); rect(0, horizon, width, height+horizon); home.show(); action(); } void action() { mark.show(); mark.move(); rover.show(); rover.move(); } class House { float x=100, y=100; float wide=100, high=50; void show() { /// draw: house fill( 255, 0, 0 ); rect( x,y, wide,high ); rect( x+30, y-50, 15,50); triangle( x,y, x+w,100, x+w/2,60 ); fill( 0, 0, 0 ); rect( 110, 110, 30, 40 ); } class Dog { // DATA MEMBERS // float x=200, y=170, xx=3, yy=2; // Position & speed float wide=60, high=30; // Default dimensions //////// METHODS //////// void show() { ///Draw: Rover fill( 120, 120, 120 ); rect( x, y, 50, 30 ); rect( x+40, y-10, 30, 20 ); rect( x+30, y-10, 20, 10 ); fill( 200, 300, 300 ); ellipse( x+60, y, 10, 10 ); fill( 0, 0, 0 ); ellipse ( x+60, y, 2, 2 ); } void move() { x = x + xx; y = y + yy; if (x > width) xx = -xx; // Bounce. if (x < 0) xx = -xx; if (y > height) yy = -yy; if (y < horizon/2) yy= -yy; } }// class Dog // class Hero { float x=380, y=105, xx=3,yy=2; // Position & speed float wide=60, high=30; // Default dimensions //////// METHODS //////// void show() { ///Draw: Hero fill( 300, 300, 200 ); rect( x, y, 20, 5 ); rect( x+40, y-10, 20, 5 ); rect( x+30, y-10, 5, 30 ); rect( x+30, y-10, 5, 30 ); fill( 0, 255, 0 ); rect( x+40, y-30, 5, 30 ); fill( x+60, y, 10, 10 ); ellipse( 415, 90, 40, 40); fill( x+60, y, 10, 10 ); ellipse( 410, 90, 10, 10 ); ellipse( 420, 90, 10, 10 ); fill( x+60, y, 10, 10 ); ellipse( 410, 90, 2, 2 ); ellipse( 420, 90, 2, 2 ); ellipse( 414, 100, 5, 6 ); } void move() { x = x + xx; y = y + yy; if (x > width) xx = -xx ; // Bounce. if (x < 0) xx = -xx; if (y > height) yy = -yy; if (y < horizon/2) yy = -yy; { // class Hero // }