Click to enlarge screenshot.  | 
Write new object-based code 
to satisfy the requirements in 
	Project #1 
& exam 
	q1 ,
plus some additional requirements (below).
In your folder, submit your code by April 1,
in a .pde file whose name begins with p2.
NOTE:  
Do not copy your p1 code.
Instead, use it as a guide to write new object-based code, 
using class definitons for:
Each class should include declarations for necessary properties
as well as a show() method 
to display itself on the screen (with animation if required),
plus other methods, as needed.
	
// You may use different names for these classes, if you wish.
		
 // (I changed my class name from "Sun" to "Star", to avoid confusion.)
Objects that move 
will need either a move( ) method OR a chase( x2, y2 ) method.
MODIFICATIONS:
	
		Animate at least one of the moving objects (Hero, Dog, or Monster).
		
	
	More features will be added here.
	
	
	
	BUTTONS 
	--
	 
	 
	Add the following buttons to Project #2.
	
	
| 
		 similar to the one in h1b_buttons.pde  | |
| HOME | move the hero to the house. | 
|---|---|
| RESET | reset all objects. | 
| DAY | switch to daytime. | 
| NITE | switch to nighttime. | 
			Suggestion:   
			
	test these 
	in keyPressed(),
	before connecting them to buttons.  | |
ARRAYS & LOOPS (see Chapter 9):  
Project #2 will also require an array for the 3 trees,
and a for loop to display them.
NOTE: 
Rows of flowers & rocks 
(from q1)
are not required;
code for these may be removed.
OPTIONAL -- Here are some ideas for extra credit:
 //// CST 112 Project #2 / Your Name //// String title= "Project #2"; String author= "Your Name"; Hero yoshio; Dog noodles; Monster vlad; Star sol; House home; int ntrees=3; Tree[] trees = new Tree[ntrees]; boolean day=true; float horizon;// . . . (more declarations) . . .  | 
Your Object-Oriented Project #2 may include code similar to the following.
 
void setup() {
    size( 800, 600 );
    horizon=  height / 4;
	
    // Instatiation of objects. //
    yoshio = new Hero();
    noodles = new Dog();
    vlad = new Monster();
    sol = new Star();
    for (int n=0; n<ntrees; n=n+1) {
          trees[n] = new Tree();
    }
    home = new House();
    // . . . (more setup) . . .
    reset();
}
void reset() {
    yoshio.reset();
    monster.reset();
    for (int n=0; n<ntrees; n=n+1) {
          trees[n].reset();
    }
}
void draw() {
    scene();
    action();
    messages();
}
// . . . 
 
 | void scene() {
    if (day) background( SKY );
    else background( NITE );
    sol.show();
    grass();
    ladder();
    for (int n=0; n<ntrees; n=n+1) {
          trees[n].show();
    }
    home.show();
    // . . . 
} 
 | 
 
    yoshio.move();
    noodles.chase( yoshio.x, yoshio.y );
    if ( ! day ) vlad.chase( noodles.x, noodles.y );
    // . . . more action code . . . 
 | 
 
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 nite.)
    // METHODS //
    void show() {
	if (day) c = color(255,255,0);	// Yellow sun.
	else c = color(200,180,180);	// Pale moon.
	fill(c);
	ellipse( x,y, w,h );
    }
    void move() {
	if (x > width) { sunset(); }	// Night & Day.
	x = x + dx;
	y = y + dy;
    }
    void sunset() {
	day = ! day;			// Switch nite/day
	x = 0;				// Reset to left
    }
} 
 | 
 
class Monster {
    // MEMBER DATA. //
    float x=0, y=50, xx=1, yy=0;	// Position & speed.
    // . . .
    void chase( float x2, float y2 ) {
	if ( day ) { return; }		// No day chasing.
	// Slowly chase (x2,y2)
	xx =  (x2-x) / 120;
	yy =  (y2-y) / 120;
	move();
    }
    void move() {
	x = x + xx;
	y = y + yy;
    }
    // . . .
}
 |