
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
 *
 * ball
 *
 */
class ball2
{



	final int LEFT=0, RIGHT = 1, UP = 2, DOWN = 3;
	final int LEFT_WALL = 10,  TOP_WALL = 10;
	int x_pos,  y_pos, size;
	int dir_x, dir_y;
	int xinc = 30;
	Graphics g;
	Color ballcolor;
	Color bgcolor;
	Random r = new Random();
	boolean randomColors = false; 
	boolean overlay = false;
	int colors[] = new int[3];


	backandforth bnf;



	void setBackandforth(backandforth bnf)
	{
		this.bnf = bnf;
	}


	void setGraphics(Graphics gr)
	{
		g = gr;
	}
	 


	void move() 
	{
		switch (dir_x)
		{
		case LEFT:
			  {
				  x_pos -= xinc;
				  if (x_pos < (LEFT_WALL - 40))
				  {
					  x_pos = LEFT_WALL;
					  dir_x = RIGHT;
				  }
			  }
			  break;
		case RIGHT:
			{
				//paddle-ball intersection goes here
				x_pos += xinc;
				//System.out.println("xpos = " + x_pos);
				if (x_pos > (bnf.getSize().width - 40 ))
				  {
					//System.out.println("changing directions!");
					  x_pos = (bnf.getSize().width + 40);
					  dir_x = LEFT;
				
				  }

			}
			break;
		}

		
	}



	 ball2 (int x, int y, int mysize, int xinc, Color bgcolor, Color ballcolor, boolean randomcolors, boolean overlay)
	 {
		 x_pos = x;
		 y_pos = y;
		 dir_x = LEFT;
		 dir_y = UP;
		 size = mysize;
		 this.xinc = xinc;
		this.ballcolor = ballcolor;
		this.bgcolor = bgcolor;
		this.randomColors = randomcolors;
		this.overlay = overlay;


		System.out.println("ballcolor = " + ballcolor);
		System.out.println("bgcolor = " + bgcolor);		
		System.out.println("randomcolors = " + randomcolors); 
		System.out.println("overlay = " + overlay); 
	 }

	 void set_size(int x)
	 {
		 size = x;
	 }

	 void draw ()
	 {
		//System.err.println("moving");

		if (randomColors)
		{
		//don't overlay; just leave it up

		//overlay background
		if (overlay)
		{
		 g.setColor(bgcolor);
		 g.fillOval( x_pos, y_pos, size, size);
		}
		 move();
		//set up array of random colors, between 0 and 255
		for (int i = 0; i < 3; i++)
		{
			colors[i] = r.nextInt() % 256;
			if (colors[i] < 0)
			{
				colors[i] = -(colors[i]);
			}
			//System.err.println("color[" + i + "] is " + colors[i]);
		}

	  	 g.setColor(new Color(colors[0], colors[1], colors[2]));
		 g.fillOval( x_pos, y_pos, size, size);
		}
		else
		{


		 //overlay with background here
		 g.setColor(bgcolor);
		 g.fillOval( x_pos, y_pos, size, size);
		 move();
	  	 g.setColor(ballcolor);
		 g.fillOval( x_pos, y_pos, size, size);
		}



	 }

	 void move (int x, int y)
	 {
		 
		 x_pos = x;
		 y_pos = y;

		 
	 }
}

