package edu.compsci;

import cs1.android.*;

// Fling the bird so that it flies on top of the pig.

public class AngryBirdObjectsApp extends AndroidApp
{
	// for 320x480 screen in landscape mode
	final int WIDTH = 480;
	final int HEIGHT = 320;

	// distance considered a hit
	final double HIT_DIST = 40.0;


	public void run() 
	{	
		// position pig and bird at opposite corners
		double birdX = 60, birdY = 60;
		double pigX = 420, pigY = 260;

		// draw the scene
		Shape field = new Image(240,  169, "background.png");
		Shape pig = new Image(pigX, pigY, "pig.png");
		Shape bird = new Image(birdX, birdY, "bird.png");

		field.draw();
		pig.draw();
		bird.draw();

		// get the fling direction
		Fling fling = canvas.waitForFling();
		double dx =  fling.getDx();
		double dy =  fling.getDy();

		// use the speed to update position as long as bird in view and away frmo pig
		double speedX = 3, speedY = 6;
		while (Shape.distance(bird, pig) > HIT_DIST &&  
				field.contains(bird.getCenter())) {
			bird.move(speedX*dx, speedY*dy);			
			canvas.sleep(.01);
		}	
	}
}
