PROJECT #2
The big, bad monster chases the brave, little hero,
who chases after the gold, while the sun moves across the sky.

Changes from Project #1:

  • Project #2 is based on project #1, and includes all of its features.
  • Add a few trees on the horizon
  • Add a house above the horizon (in front of trees)

  • Hero does NOT follow the mouse.
  • Click on the mouse to place a lump of GOLD anywhere on the grass.
  • Hero chases gold at a certain rate; monster chases hero at a slower rate.

  • When hero gets gold, add 50 points and transport him into the house.
  • If monster catches hero, he loses 100 points and transports to house.
  • Monster cannot go above the horizon (cannot catch hero within house).
  • Player may click to create new gold at any time (to escape monster!)

Make up names for your characters (hero and monster) and use use all of the following Library functions (methods) in your program :

		rect( ... )
		ellipse( ... )
		line( ... )
		triangle( ... )

		text( ... ), fill( ... ), stroke( ... )
The monster chases the hero, who chases after the gold. When the mouse is clicked, deduct 50 points, move the gold to a random position, and reset everything to starting positions: hero in the house and monster at a random height on one side of the window (randomly left or right), and the gold at a random position near the center.

Declare global variables for the position coordinates (X,Y) of each object. Variable names should start with a small letter (NOT a Capital) for the first word, but you may Capitalize any additional words. If the names are "Igor" and "Vladimir" then global declarations might look something like this:

		//// GLOBALS ////
		float goldX, goldY;
		float igorX, igorY;
		float vladX, vladY; 
and the Java code to move the monster might look something like this:
		// Monster chases hero //
		igorX=  igorX + (vladX-igorX) / 150;
		igorY +=  (vladY-igorY) / 150;
		if ( dist( vladX,vladY, igorX,igorY ) )   {
			// Monster catches hero!
			scor -= 100;
			reset();		// Move to opposite sides.
		} 
NOTE: Please don't call them Igor and Vlad! Make up your own names!

In the setup() method, reset everything to starting positions:

		void setup() {
			size( ..., ... );
			reeset();
		}

Your code for the draw() method should not actually draw anything.
Instead, have it call other methods to do all the work.

		void draw() {
			// Next frame. //
			scene();
			monster();
			hero();
			gold();
		} 
Write your own Java code for each of these methods, and also for mousePressed() keyPressed() .
The scene is a grassy field with a row of trees, under a light blue sky with the sun moving slowly from left to right a few times per minute. Display title and score at the top; your name in the lower-left corner.

For project #2, use functions with arguments to draw parts of the creatures on the screen, and add some animation (such as legs that "walk" or arms that "wave" or wings that "flap" or eyes that blink, etc.)
For example, code to draw the hero might look something like this:

	void drawVlad( float x, float y, float w, float h ) {
		// Draw hero centered at (x,y) with body width w and height h //
		rectMode( CENTER );
		fill( ... );
		rect( x,y, w,h );
		...					// Stripes.
	  	text( "Vlad", x-w/3, y-h/4 );		// Name on shirt.
		fill( ... );

		// Head //
		float headHeight= 20;
		head( headHeight, x, y-h-headHeight/2 );

		// Legs (starting at hips). //
		fill( ... );
		leg( 40, x-w/2, y+h/2 );		// legs start at hips.
		leg( 40, x+w/2, y+h/2 );

		// Arms //
		float armLength=h/3;
		arm( armLength,  x-w/2, y-h/2 );	// arms at shoulders
		arm( -armLength,  x+w/2, y-h/2 );
	}
	void head( float hh, float xh, floatyh ) {
		// Draw head and eyes //
		ellipse( xh, yh, hh, hh*3/4 );
		eye( xh-hh/6, yh-hh/4 );		// left eye
		eye( xh+hh/6, yh-hh/4 );		// right eye
	}
	void eye( float a, float b) {
		. . .
	}
	. . .

Use the same head(), eye(), leg(), and arm() functions for both the hero and the monster. Draw horizontal stripes, evenly spaced, across the the bodies of the hero and monster. Use the same head(), eye(), leg(), and arm() functions for both the hero and the monster.



Drop a bomb when the 'b' key is pressed. If bomb hits monster, move him to side of the screen at a random height.